1 # Kamailio build system
3 # common Makefile rules, included by main Makefile & the modules
7 # Uses: NAME, ALLDEP, CC, CFLAGS, C_DEFS, DEFS, C_INCLUDES, INCLUDES, LIBS,
8 # MKDEP, auto_gen, auto_gen_others, auto_gen_keep,
9 # depends, objs, extra_objs, static_modules, static_modules_path,
11 # (all this must be defined previously!, see Makefile.defs & Makefile)
12 # Optional: SER_LIBS - list of ser libraries that will be automatically
13 # built if necessary. Format: path/shortname, where shortname is the
14 # name passed to -l (e.g. for libprint.so the shortname is print)
18 # check if the saved cfg corresponds with the current one
19 # (if not rebuild everything)
20 ifeq (,$(filter $(nodep_targets),$(MAKECMDGOALS)))
22 # if trying to build a lib automatically and the lib is already compiled,
23 # don't rebuild it if the only differences in DEFS or INCLUDES are covered
24 # by LIB_NOREBUILD_DEFS/LIB_NOREBUILD_INCLUDES
27 # don't rebuild if the differences are covered by NOREBUILD_DEFS or
29 ifneq ($(strip $(filter-out $(NOREBUILD_DEFS),\
30 $(C_DEFS) $(DEFS))),$(strip $(CFG_DEFS)))
31 #$(warning different defs: <$(strip $(C_DEFS) $(DEFS))> != )
32 #$(warning : <$(strip $(CFG_DEFS))>)
33 $(shell rm -f makecfg.lst)
35 ifneq ($(strip $(filter-out $(NOREBUILD_INCLUDES),\
36 $(C_INCLUDES) $(INCLUDES))),$(strip $(CFG_INCLUDES)))
37 $(shell rm -f makecfg.lst)
43 # returns current type: "" core/unknown, "M" module, "L" libray, "U" util
44 crt_type=$(if $(MOD_NAME),M,$(if $(LIB_NAME),L,$(if $(UTIL_NAME),U)))
46 cmd_CC=$(CC) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) -c $< -o $@
47 cmd_LD=$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) \
50 ifeq (,$(CC_MKDEP_OPTS))
51 # if CCC_MKDEP_OPTS is empty => CC cannot generate dependencies on the fly
52 cmd_MKDEP=$(MKDEP) $(filter -D% -I%,$(CFLAGS)) $(C_INCLUDES) $(INCLUDES) \
53 $(C_DEFS) $(DEFS) $< \
54 | sed -e 's/\#.*//' -e '/:[ ]*$$/d' -e '/^[ ]*$$/d' \
55 -e 's|.*:|$@: $$(wildcard |' -e 's/\([^\\]\)$$/\1)/'> $*.d
57 # deps can be generated on the fly by cmd_CC
58 cmd_CC+=$(CC_MKDEP_OPTS)
59 # no MKDEP command any more
63 # what will be displayed if quiet==silent
64 silent_cmd_CC=CC ($(CC)) [$(strip $(crt_type) $(NAME))] $@
65 silent_cmd_LD=LD ($(LD)) [$(strip $(crt_type) $(NAME))] $@
67 ifneq (,$(filter 0 no off verbose noisy, $(Q) $(QUIET)))
75 MAKE+= --no-print-directory
80 module_make= if [ -n "$(1)" -a -r "$(1)/Makefile" ]; then \
83 if $$(MAKE) -C $(1) $(2) || [ ${err_fail} != 1 ] ; then \
89 echo module not found: $(1) ; \
94 escall= $(subst $$,\$$,$(subst $(quote),\$(quote),$1))
95 exec_cmd= $(if $($(quiet)_cmd_$(1)),\
96 @echo "$(call escall,$($(quiet)_cmd_$(1)))" ;) $(cmd_$(1))
103 # use RPATH and SER_LIBS if needed (make install and the module depends
107 # abspath & realpath don't work on make <= 3.80
108 SER_LIBS_DIRS:=$(dir $(SER_LIBS))
109 ifneq (,$(filter install install% %install, $(MAKECMDGOALS)))
110 lib_compile_for_install=yes
111 expected_lib_ipath=$(lib_target)
113 lib_compile_for_install=$(compile_for_install)
114 # function: expected_lib_ipath ser_lib_dir
115 expected_lib_ipath=$(1)
118 ifneq (,$(filter install install% %install, $(MAKECMDGOALS)))
119 SER_RPATH_LST:=$(lib_target)
121 # realpath is not supported in make 3.80 or older
122 ifeq (,$(filter-out 3.80 3.80.%,$(MAKE_VERSION)))
123 fullpath=$(shell cd $(1); pwd)
125 fullpath=$(realpath $(1))
128 SER_RPATH_LST:=$(call fullpath,$(dir $(SER_LIBS)))
130 ifneq ($(strip $(SER_RPATH_LST)),)
131 SER_RPATH:=$(addprefix $(LD_RPATH),$(SER_RPATH_LST))
135 SER_IPATH_LST:=$(addsuffix /libiname.lst,$(SER_LIBS_DIRS))
136 #$(warning $(NAME) DARWIN, SER_LIBS=$(SER_LIBS), $(SER_LIBS_DIRS), ipath_lst=$(SER_IPATH_LST))
142 ifeq (,$(filter clean %clean clean% proper %proper proper%, $(MAKECMDGOALS)))
144 -include librpath.lst
145 ifneq ($(SER_RPATH_LST), $(LIB_RPATH_LST))
146 $(shell rm -f librpath.lst)
151 $(foreach l, $(SER_LIBS), $(dir $l)$(LIB_PREFIX)$(notdir $l)$(LIB_SUFFIX))
152 ALL_LIBS+=$(foreach l, $(SER_LIBS), -L$(dir $l) -l$(notdir $l))
154 $(NAME): librpath.lst $(SER_LIBS_DEPS)
156 $(SER_LIBS_DEPS): FORCE
157 @$(MAKE) -wC $(dir $@) compile_for_install=$(lib_compile_for_install) \
158 NOREBUILD_DEFS="$(NOREBUILD_DEFS) $(LIB_NOREBUILD_DEFS)" \
159 NOREBUILD_INCLUDES="$(NOREBUILD_INCLUDES) $(LIB_NOREBUILD_INCLUDES)"
164 ifneq ($(SER_IPATH_LST),)
166 $(NAME): $(SER_IPATH_LST)
168 $(SER_IPATH_LST): FORCE
170 "COMPILED_INAME:=$(call expected_lib_ipath,$(shell cd $(@D); pwd))" \
171 $(@) 1>/dev/null 2>/dev/null ; \
174 $(call oecho,"re-building $(@D)" ;) \
175 $(MAKE) -wC $(@D) compile_for_install=$(lib_compile_for_install) ; \
178 .PHONY: FORCE-BUILD-LIBS
180 @for r in $(SER_LIBS_DIRS) ; do \
181 $(call oecho,building lib $$r ;) \
182 $(MAKE) -wC $$r compile_for_install=$(lib_compile_for_install) ; \
190 $(NAME): $(objs) $(ALLDEP)
194 librpath.lst: $(ALLDEP)
195 @echo LIB_RPATH_LST:=$(SER_RPATH_LST) >librpath.lst
198 @echo "CFG_DEFS:=$(call escall,$(strip \
199 $(filter-out $(NOREBUILD_DEFS), $(C_DEFS) $(DEFS))))" >>$@
200 @echo "CFG_INCLUDES:=$(call escall,$(strip \
201 $(filter-out $(NOREBUILD_INCLUDES),\
202 $(C_INCLUDES) $(INCLUDES))))" >>$@
204 all: $(NAME) every-module
209 # clean only the current directory (no modules or utils)
210 # (it's usefull to have it separated from clean for speeding up make proper)
213 -@rm -f $(objs) $(NAME) $(objs:.o=.il) *.a librpath.lst 2>/dev/null
218 .PHONY: clean-modules
220 -@for r in $(cmodules) $(static_modules_path) "" ; do \
221 if [ -d "$$r" ]; then \
222 $(call oecho,"module $$r" ;) \
223 $(MAKE) -C "$$r" clean ; \
224 [ -r "$$r"/doc/Makefile ] && $(MAKE) -C "$$r"/doc clean ; \
228 # make proper for the local directory
232 .PHONY: maintainer-clean
233 proper distclean realclean maintainer-clean: local-clean
234 -@rm -f $(depends) $(auto_gen) $(auto_gen_others) $(auto_gen_keep) \
235 makecfg.lst 2>/dev/null
237 maintainer-clean: clean-tmp
239 .PHONY: proper-modules
240 .PHONY: distclean-modules
241 .PHONY: realclean-modules
242 .PHONY: maintainer-clean-modules
243 proper-modules realclean-modules distclean-modules maintainer-clean-modules: \
244 clean_target=$(patsubst %-modules,%,$@)
245 proper-modules realclean-modules distclean-modules maintainer-clean-modules:
246 -@for r in $(cmodules) "" ; do \
247 if [ -d "$$r" ]; then \
248 $(MAKE) -C "$$r" $(clean_target); \
249 [ -r "$$r"/doc/Makefile ] && $(MAKE) -C "$$r"/doc $(clean_target);\
255 -@rm -f TAGS tags *.dbg .*.swp
260 -@mkdir -p $(doxygen_dir)
261 -@echo "Create Doxygen documentation"
262 # disable call graphes, because of the DOT dependencies
263 (cat ./$(COREPATH)/doc/doxygen/ser.doxygen; \
264 echo "HAVE_DOT=no" ;\
265 echo "PROJECT_NAME=SIP-ROUTER" ;\
266 echo "PROJECT_NUMBER=$(NAME)-$(RELEASE)" )| doxygen -
267 -@echo "Doxygen documentation created"
269 .PHONY: clean_doxygen
271 -@rm -rf $(doxygen_dir)/{xml,man,rtf,latex,html}
272 -@rmdir --ignore-fail-on-non-empty -p $(doxygen_dir) || true
278 $(MKTAGS) --exclude="obsolete/*" --exclude="test/*" -R .
287 ifeq (,$(MAKECMDGOALS))
290 ifeq (,$(strip $(nodep_targets)))
291 include $(COREPATH)/Makefile.targets
293 ifneq (,$(filter-out $(nodep_targets),$(MAKECMDGOALS)))
296 endif # ifeq (,$(MAKECMDGOALS))