| 1 | ############################################################################## |
| 2 | # Copyright (c) 2000-2016 Ericsson Telecom AB |
| 3 | # All rights reserved. This program and the accompanying materials |
| 4 | # are made available under the terms of the Eclipse Public License v1.0 |
| 5 | # which accompanies this distribution, and is available at |
| 6 | # http://www.eclipse.org/legal/epl-v10.html |
| 7 | # |
| 8 | # Contributors: |
| 9 | # Balasko, Jeno |
| 10 | # Baranyi, Botond |
| 11 | # Forstner, Matyas |
| 12 | # Kovacs, Ferenc |
| 13 | # Pandi, Krisztian |
| 14 | # Raduly, Csaba |
| 15 | # Szabo, Janos Zoltan – initial implementation |
| 16 | # |
| 17 | ############################################################################## |
| 18 | # General stuff (to be included at the end of makefiles). The |
| 19 | # following variables are used: DEPFILES, SUBDIRS... |
| 20 | |
| 21 | tags: $(SOURCES) |
| 22 | ifdef SUBDIRS |
| 23 | @for i in $(SUBDIRS) ; do \ |
| 24 | (cd $$i && $(MAKE) tags) || exit 1; \ |
| 25 | done |
| 26 | endif |
| 27 | etags --members *.hh *.h *.c *.cc |
| 28 | |
| 29 | dep: |
| 30 | ifdef SUBDIRS |
| 31 | @for i in $(SUBDIRS) ; do \ |
| 32 | (cd $$i && $(MAKE) dep) || exit 1; \ |
| 33 | done |
| 34 | endif |
| 35 | ifdef DEPFILES |
| 36 | $(MAKE) $(DEPFILES) |
| 37 | endif |
| 38 | |
| 39 | clean: |
| 40 | ifdef SUBDIRS |
| 41 | @for i in $(SUBDIRS) ; do \ |
| 42 | (cd $$i && $(MAKE) clean) || exit 1; \ |
| 43 | done |
| 44 | endif |
| 45 | $(RM) $(TARGETS) $(OBJECTS) $(TOBECLEANED) |
| 46 | |
| 47 | distclean: |
| 48 | ifdef SUBDIRS |
| 49 | @for i in $(SUBDIRS) ; do \ |
| 50 | (cd $$i && $(MAKE) distclean) || exit 1; \ |
| 51 | done |
| 52 | endif |
| 53 | $(RM) $(TARGETS) $(OBJECTS) $(TOBECLEANED) \ |
| 54 | $(GENERATED_HEADERS) $(GENERATED_SOURCES) \ |
| 55 | $(GENERATED_OTHERS) \ |
| 56 | $(DEPFILES) TAGS *.gcno *.gcda |
| 57 | |
| 58 | # This target allows us to "make ../clean" |
| 59 | ../% $(foreach dir, $(SUBDIRS), $(dir)/%): |
| 60 | cd $(dir $@) && $(MAKE) $(notdir $@) |
| 61 | |
| 62 | # General rules to compile C(++) files. |
| 63 | # |
| 64 | # These macros implement "silent" rules during building. |
| 65 | # Define the V make variable or environment variable to a nonzero value to get |
| 66 | # the exact call to the compiler: e.g. make V=1 |
| 67 | # |
| 68 | # Define the VD variable to get the exact (verbose) action while |
| 69 | # generating dependencies. |
| 70 | # |
| 71 | NULL := |
| 72 | SPACE := ${NULL} ${NULL} |
| 73 | |
| 74 | DEF_V := 0 |
| 75 | DEF_VD:= 0 |
| 76 | |
| 77 | V_CC_0 = @echo " (CC) " $<;$(SPACE) |
| 78 | V_CXX_0 = @echo " (C++) " $<;$(SPACE) |
| 79 | V_DEP_0 = @echo " (dep) " $<;$(SPACE) |
| 80 | |
| 81 | V_CC_ = $(V_CC_$(DEF_V)) |
| 82 | V_CXX_ = $(V_CXX_$(DEF_V)) |
| 83 | V_DEP_ = $(V_DEP_$(DEF_VD)) |
| 84 | |
| 85 | V_CC = $(V_CC_$(V)) |
| 86 | V_CXX = $(V_CXX_$(V)) |
| 87 | V_DEP = $(V_DEP_$(VD)) |
| 88 | |
| 89 | %.o: %.c |
| 90 | $(V_CC)$(CC) -c $(CPPFLAGS) $(CCFLAGS) $< -o $@ |
| 91 | |
| 92 | # Special rule for building profmerge files |
| 93 | %.profmerge.o: %.cc |
| 94 | $(V_CXX)$(CXX) -c -DPROF_MERGE $(CPPFLAGS) $(CXXFLAGS) $< -o $@ |
| 95 | |
| 96 | %.o: %.cc |
| 97 | $(V_CXX)$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@ |
| 98 | |
| 99 | # Preprocess C/C++ files |
| 100 | %.i: %.c |
| 101 | $(CC) -E $(CPPFLAGS) $(CCFLAGS) \ |
| 102 | $< > $@ |
| 103 | |
| 104 | %.ii: %.cc |
| 105 | $(CXX) -E $(CPPFLAGS) $(CXXFLAGS) \ |
| 106 | $< > $@ |
| 107 | |
| 108 | # General rules to create the dependency file. |
| 109 | |
| 110 | %.d: %.c |
| 111 | $(V_DEP)set -e; $(CC) $(CCDEPFLAG) $(CPPFLAGS) $< \ |
| 112 | | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@; \ |
| 113 | [ -s $@ ] || rm -f $@ |
| 114 | |
| 115 | %.d: %.cc |
| 116 | $(V_DEP)set -e; $(CXX) $(CXXDEPFLAG) $(CPPFLAGS) $< \ |
| 117 | | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@; \ |
| 118 | [ -s $@ ] || rm -f $@ |
| 119 | |
| 120 | ifdef DEPFILES |
| 121 | ifndef MAKECMDGOALS |
| 122 | DEPFILES_NEEDED := yes |
| 123 | else |
| 124 | DEPFILES_NEEDED := $(filter-out clean distclean, $(MAKECMDGOALS)) |
| 125 | endif |
| 126 | ifdef DEPFILES_NEEDED |
| 127 | DEPFILES_INCLUDE := $(filter-out $(MAKECMDGOALS), $(DEPFILES)) |
| 128 | ifdef DEPFILES_INCLUDE |
| 129 | ifeq (,$(findstring n,$(MAKEFLAGS))) |
| 130 | # -n was *not* given to make |
| 131 | -include $(DEPFILES_INCLUDE) |
| 132 | endif |
| 133 | endif |
| 134 | endif |
| 135 | endif |
| 136 | |
| 137 | # Building PDFs from man pages (for MinGW) |
| 138 | %.pdf: %.1 |
| 139 | man2pdf ./$< $@ |
| 140 | # The "./" prefix is important, it tells man that the input is a filename, |
| 141 | # so it shouldn't search through MANPATH. |
| 142 | |
| 143 | # List of fake targets: |
| 144 | .PHONY: all install tags dep clean distclean |
| 145 | |
| 146 | # Disable all built-in suffix rules of make |
| 147 | .SUFFIXES: |
| 148 | |
| 149 | # Do not delete generated headers while building .d files |
| 150 | # (.PRECIOUS would also keep them if make is killed) |
| 151 | .SECONDARY: $(GENERATED_HEADERS) |
| 152 | |
| 153 | ifdef SRCDIR |
| 154 | |
| 155 | REQUIRED_MAKE_VERSION = 3.81 |
| 156 | # 3.80 is known not to work; 3.82 does work |
| 157 | REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION)) |
| 158 | EARLIER_MAKE_VERSION = $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))) |
| 159 | ifeq "$(REQUIRED_MAKE_VERSION)" "$(EARLIER_MAKE_VERSION)" |
| 160 | |
| 161 | # Declare a search path for every source. |
| 162 | # "vpath %.cc $(ABS_SRC)" would lump in generated .cc files, |
| 163 | # potentially picking up generated files laying around in the source dir |
| 164 | # instead of generating them in the build dir. |
| 165 | $(foreach src, $(STATIC_SOURCES) $(ORIGINATORS), $(eval vpath $(src) $(ABS_SRC))) |
| 166 | |
| 167 | else |
| 168 | |
| 169 | # alas, make 3.80 can't cope with the "foreach/eval vpath" above |
| 170 | #$(warning no OOBE with make $(MAKE_VERSION)) |
| 171 | |
| 172 | endif |
| 173 | |
| 174 | endif |