5 # common Makefile rules, included by main Makefile & the modules
9 # Uses: NAME, ALLDEP, CC, CFLAGS, C_DEFS, DEFS, C_INCLUDES, INCLUDES, LIBS,
10 # MKDEP, auto_gen, auto_gen_others, auto_gen_keep,
11 # depends, objs, extra_objs, static_modules, static_modules_path,
13 # (all this must be defined previously!, see Makefile.defs & Makefile)
14 # Optional: SER_LIBS - list of ser libraries that will be automatically
15 # built if necessary. Format: path/shortname, where shortname is the
16 # name passed to -l (e.g. for libprint.so the shortname is print)
20 # 2007-03-29 set rpath differently for make install
21 # automatically build listed SER_LIBS if needed (andrei)
22 # 2008-06-23 automatically rebuild if make time defines or includes
23 # changed (via makecfg.lst)
24 # 2009-03-10 support for C_DEFS and C_INCLUDES (DEFS and INCLUDES are now
25 # used only for "temporary" defines/includes inside modules or
26 # libs, C_DEFS and C_INCLUDES are used for the common stuff)
28 # 2010-03-09 generate dependencies when compiling .o instead of on
29 # include .d and fix build errors when a .h is moved
30 # support for using MKDEP="makedepend-f-" (andrei)
31 # 2010-03-10 support for on the-fly dependency generation (while compiling,
32 # see CC_MKDEP_OPTS) (andrei)
35 # check if the saved cfg corresponds with the current one
36 # (if not rebuild everything)
37 ifeq (,$(filter $(nodep_targets),$(MAKECMDGOALS)))
39 # if trying to build a lib automatically and the lib is already compiled,
40 # don't rebuild it if the only differences in DEFS or INCLUDES are covered
41 # by LIB_NOREBUILD_DEFS/LIB_NOREBUILD_INCLUDES
44 # don't rebuild if the differences are covered by NOREBUILD_DEFS or
46 ifneq ($(strip $(filter-out $(NOREBUILD_DEFS),\
47 $(C_DEFS) $(DEFS))),$(strip $(CFG_DEFS)))
48 #$(warning different defs: <$(strip $(C_DEFS) $(DEFS))> != )
49 #$(warning : <$(strip $(CFG_DEFS))>)
50 $(shell rm -f makecfg.lst)
52 ifneq ($(strip $(filter-out $(NOREBUILD_INCLUDES),\
53 $(C_INCLUDES) $(INCLUDES))),$(strip $(CFG_INCLUDES)))
54 $(shell rm -f makecfg.lst)
60 # returns current type: "" core/unknown, "M" module, "L" libray, "U" util
61 crt_type=$(if $(MOD_NAME),M,$(if $(LIB_NAME),L,$(if $(UTIL_NAME),U)))
63 cmd_CC=$(CC) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) -c $< -o $@
64 cmd_LD=$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) \
67 ifeq (,$(CC_MKDEP_OPTS))
68 # if CCC_MKDEP_OPTS is empty => CC cannot generate dependencies on the fly
69 cmd_MKDEP=$(MKDEP) $(filter -D% -I%,$(CFLAGS)) $(C_INCLUDES) $(INCLUDES) \
70 $(C_DEFS) $(DEFS) $< \
71 | sed -e 's/\#.*//' -e '/:[ ]*$$/d' -e '/^[ ]*$$/d' \
72 -e 's|.*:|$@: $$(wildcard |' -e 's/\([^\\]\)$$/\1)/'> $*.d
74 # deps can be generated on the fly by cmd_CC
75 cmd_CC+=$(CC_MKDEP_OPTS)
76 # no MKDEP command any more
80 # what will be displayed if quiet==silent
81 silent_cmd_CC=CC ($(CC)) [$(strip $(crt_type) $(NAME))] $@
82 silent_cmd_LD=LD ($(LD)) [$(strip $(crt_type) $(NAME))] $@
84 ifneq (,$(filter 1 yes on, $(Q) $(QUIET)))
87 MAKE+= --no-print-directory
97 module_make= if [ -n "$(1)" -a -r "$(1)/Makefile" ]; then \
100 if $$(MAKE) -C $(1) $(2) || [ ${err_fail} != 1 ] ; then \
108 escall= $(subst $$,\$$,$(subst $(quote),\$(quote),$1))
109 exec_cmd= $(if $($(quiet)_cmd_$(1)),\
110 @echo "$(call escall,$($(quiet)_cmd_$(1)))" ;) $(cmd_$(1))
117 # use RPATH and SER_LIBS if needed (make install and the module depends
121 # abspath & realpath don't work on make <= 3.80
122 SER_LIBS_DIRS:=$(dir $(SER_LIBS))
123 ifneq (,$(filter install install% %install, $(MAKECMDGOALS)))
124 lib_compile_for_install=yes
125 expected_lib_ipath=$(lib_target)
127 lib_compile_for_install=$(compile_for_install)
128 # function: expected_lib_ipath ser_lib_dir
129 expected_lib_ipath=$(1)
132 ifneq (,$(filter install install% %install, $(MAKECMDGOALS)))
133 SER_RPATH_LST:=$(lib_target)
135 # realpath is not supported in make 3.80 or older
136 ifeq (,$(filter-out 3.80 3.80.%,$(MAKE_VERSION)))
137 fullpath=$(shell cd $(1); pwd)
139 fullpath=$(realpath $(1))
142 SER_RPATH_LST:=$(call fullpath,$(dir $(SER_LIBS)))
144 ifneq ($(strip $(SER_RPATH_LST)),)
145 SER_RPATH:=$(addprefix $(LD_RPATH),$(SER_RPATH_LST))
149 SER_IPATH_LST:=$(addsuffix /libiname.lst,$(SER_LIBS_DIRS))
150 #$(warning $(NAME) DARWIN, SER_LIBS=$(SER_LIBS), $(SER_LIBS_DIRS), ipath_lst=$(SER_IPATH_LST))
156 ifeq (,$(filter clean %clean clean% proper %proper proper%, $(MAKECMDGOALS)))
158 -include librpath.lst
159 ifneq ($(SER_RPATH_LST), $(LIB_RPATH_LST))
160 $(shell rm -f librpath.lst)
165 $(foreach l, $(SER_LIBS), $(dir $l)$(LIB_PREFIX)$(notdir $l)$(LIB_SUFFIX))
166 ALL_LIBS+=$(foreach l, $(SER_LIBS), -L$(dir $l) -l$(notdir $l))
168 $(NAME): librpath.lst $(SER_LIBS_DEPS)
170 $(SER_LIBS_DEPS): FORCE
171 @$(MAKE) -wC $(dir $@) compile_for_install=$(lib_compile_for_install) \
172 NOREBUILD_DEFS="$(NOREBUILD_DEFS) $(LIB_NOREBUILD_DEFS)" \
173 NOREBUILD_INCLUDES="$(NOREBUILD_INCLUDES) $(LIB_NOREBUILD_INCLUDES)"
178 ifneq ($(SER_IPATH_LST),)
180 $(NAME): $(SER_IPATH_LST)
182 $(SER_IPATH_LST): FORCE
184 "COMPILED_INAME:=$(call expected_lib_ipath,$(shell cd $(@D); pwd))" \
185 $(@) 1>/dev/null 2>/dev/null ; \
188 $(call oecho,"re-building $(@D)" ;) \
189 $(MAKE) -wC $(@D) compile_for_install=$(lib_compile_for_install) ; \
192 .PHONY: FORCE-BUILD-LIBS
194 @for r in $(SER_LIBS_DIRS) ; do \
195 $(call oecho,building lib $$r ;) \
196 $(MAKE) -wC $$r compile_for_install=$(lib_compile_for_install) ; \
204 $(NAME): $(objs) $(ALLDEP)
208 librpath.lst: $(ALLDEP)
209 @echo LIB_RPATH_LST:=$(SER_RPATH_LST) >librpath.lst
212 @echo "CFG_DEFS:=$(call escall,$(strip \
213 $(filter-out $(NOREBUILD_DEFS), $(C_DEFS) $(DEFS))))" >>$@
214 @echo "CFG_INCLUDES:=$(call escall,$(strip \
215 $(filter-out $(NOREBUILD_INCLUDES),\
216 $(C_INCLUDES) $(INCLUDES))))" >>$@
218 all: $(NAME) every-module
223 # clean only the current directory (no modules or utils)
224 # (it's usefull to have it separated from clean for speeding up make proper)
227 -@rm -f $(objs) $(NAME) $(objs:.o=.il) librpath.lst 2>/dev/null
232 .PHONY: clean-modules
234 -@for r in $(cmodules) $(static_modules_path) "" ; do \
235 if [ -d "$$r" ]; then \
236 $(call oecho,"module $$r" ;) \
237 $(MAKE) -C "$$r" clean ; \
238 [ -r "$$r"/doc/Makefile ] && $(MAKE) -C "$$r"/doc clean ; \
242 # make proper for the local directory
246 .PHONY: maintainer-clean
247 proper distclean realclean maintainer-clean: local-clean
248 -@rm -f $(depends) $(auto_gen) $(auto_gen_others) $(auto_gen_keep) \
249 makecfg.lst 2>/dev/null
251 maintainer-clean: clean-tmp
253 .PHONY: proper-modules
254 .PHONY: distclean-modules
255 .PHONY: realclean-modules
256 .PHONY: maintainer-clean-modules
257 proper-modules realclean-modules distclean-modules maintainer-clean-modules: \
258 clean_target=$(patsubst %-modules,%,$@)
259 proper-modules realclean-modules distclean-modules maintainer-clean-modules:
260 -@for r in $(cmodules) "" ; do \
261 if [ -d "$$r" ]; then \
262 $(MAKE) -C "$$r" $(clean_target); \
263 [ -r "$$r"/doc/Makefile ] && $(MAKE) -C "$$r"/doc $(clean_target);\
269 -@rm -f TAGS tags *.dbg .*.swp
274 -@mkdir -p $(doxygen_dir)
275 -@echo "Create Doxygen documentation"
276 # disable call graphes, because of the DOT dependencies
277 (cat ./$(COREPATH)/doc/doxygen/ser.doxygen; \
278 echo "HAVE_DOT=no" ;\
279 echo "PROJECT_NAME=SIP-ROUTER" ;\
280 echo "PROJECT_NUMBER=$(NAME)-$(RELEASE)" )| doxygen -
281 -@echo "Doxygen documentation created"
283 .PHONY: clean_doxygen
285 -@rm -rf $(doxygen_dir)/{xml,man,rtf,latex,html}
286 -@rmdir --ignore-fail-on-non-empty -p $(doxygen_dir) || true
295 ifeq (,$(MAKECMDGOALS))
298 ifeq (,$(strip $(nodep_targets)))
299 include $(COREPATH)/Makefile.targets
301 ifneq (,$(filter-out $(nodep_targets),$(MAKECMDGOALS)))
304 endif # ifeq (,$(MAKECMDGOALS))