[sr-dev] git:master: make: on-the-fly dependency generation

Andrei Pelinescu-Onciul andrei at iptel.org
Wed Mar 10 10:53:57 CET 2010


Module: sip-router
Branch: master
Commit: 5a9014ee4977c6afbc4b0cf65a9fad6237c2e2a6
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5a9014ee4977c6afbc4b0cf65a9fad6237c2e2a6

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Wed Mar 10 09:25:13 2010 +0100

make: on-the-fly dependency generation

- support on-the-fly dependency file generation with gcc >=3.0
 (the dependency files are generated while compiling the object
 file, eliminating another gcc+sed invocation)

- support for using makedepend -f-  for generating dependencies
 E.g.: make cfg MKDEP="makedepend -f-". In general gcc should be
 preferred if available (use this if you don't have gcc and your
 compiler doesn't generate good deps).

---

 Makefile.defs  |   12 ++++++++++--
 Makefile.rules |   22 +++++++++++++++++++---
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/Makefile.defs b/Makefile.defs
index d334f24..a775bd9 100644
--- a/Makefile.defs
+++ b/Makefile.defs
@@ -74,6 +74,9 @@
 #              from the host (andrei)
 #  2009-10-01  use -fsigned-char for gcc on ppc, ppc64, arm and arm6
 #              (on those archs char is unsigned by default) (andrei)
+#  2010-03-10  added CC_MKDEP_OPTS, which contains to the list of options
+#               needed to generate dependencies on-the-fly while compiling
+#               or is empty if the compiler doesn't support it (andrei)
 
 quiet?=$(if $(filter 1 yes on,$(Q)),silent,verbose)
 
@@ -351,7 +354,7 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
 #				 	 -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
 	# sed with POSIX.1 regex doesn't support |, + or ? 
         # (darwin, solaris ...) => this complicated expression
-	MKDEP=$(CC) -MM 
+	MKDEP=$(CC) -MM -MG
 	#transform gcc version into 2.9x or 3.0
 	CC_SHORTVER:=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
 				 sed -e 's/[^0-9]*-\(.*\)/\1/'| \
@@ -360,7 +363,11 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
 					's/3\.[4-9]/3.4/' -e 's/4\.[0-1]\..*/4.x/' -e \
 					's/4\.[0-1]/4.x/' -e 's/4\.[2-9]\..*/4.2+/' -e \
 					's/4\.[2-9]$$/4.2+/')
-endif
+ifeq (,$(strip $(filter-out 3.0 3.4 4.x 4.2+,$(CC_SHORTVER))))
+	# dependencies can be generated on-the-fly while compiling *.c
+	CC_MKDEP_OPTS=-MMD -MP
+endif # 3.0 <= $(CC_SHORTVER) <= 4.x
+endif # gcc
 
 ifneq (, $(findstring Sun, $(CC_LONGVER)))
 	CC_NAME=suncc
@@ -1947,6 +1954,7 @@ export exported_vars
 saved_fixed_vars:=	MAIN_NAME  CFG_NAME SCR_NAME FLAVOUR INSTALL_FLAVOUR \
 		SRC_NAME RELEASE OS ARCH \
 		C_DEFS DEFS_RM PROFILE CC LD MKDEP MKTAGS LDFLAGS C_INCLUDES \
+		CC_MKDEP_OPTS \
 		MOD_LDFLAGS LIB_LDFLAGS UTILS_LDFLAGS LIB_SONAME LD_RPATH \
 		LIB_SUFFIX LIB_PREFIX \
 		LIBS \
diff --git a/Makefile.rules b/Makefile.rules
index 9fbf02b..f816f8b 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -25,6 +25,11 @@
 #              used only for "temporary" defines/includes inside modules or
 #              libs, C_DEFS and C_INCLUDES are used for the common stuff)
 #              (andrei)
+#  2010-03-09  generate dependencies when compiling .o instead of on
+#               include .d and fix build errors when a .h is moved
+#              support for using MKDEP="makedepend-f-"      (andrei)
+#  2010-03-10  support for on the-fly dependency generation (while compiling,
+#               see CC_MKDEP_OPTS)  (andrei)
 
 
 # check if the saved cfg corresponds with the current one
@@ -59,6 +64,19 @@ cmd_CC=$(CC) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) -c $< -o $@
 cmd_LD=$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) \
 	-o $(NAME)
 
+ifeq (,$(CC_MKDEP_OPTS))
+# if CCC_MKDEP_OPTS is empty => CC cannot generate dependencies on the fly
+cmd_MKDEP=$(MKDEP) $(filter -D% -I%,$(CFLAGS)) $(C_INCLUDES) $(INCLUDES) \
+			$(C_DEFS) $(DEFS) $< \
+		|  sed	-e 's/\#.*//' -e '/:[ 	]*$$/d' -e '/^[ 	]*$$/d' \
+				-e 's|.*:|$@: $$(wildcard |' -e 's/\([^\\]\)$$/\1)/'> $*.d
+else
+# deps can be generated on the fly by cmd_CC
+cmd_CC+=$(CC_MKDEP_OPTS)
+# no MKDEP command any more
+cmd_MKDEP=
+endif # CC_MKDEP_OPTS
+
 # what will be displayed if quiet==silent
 silent_cmd_CC=CC ($(CC)) [$(strip $(crt_type) $(NAME))]		$@
 silent_cmd_LD=LD ($(LD)) [$(strip $(crt_type) $(NAME))]		$@
@@ -94,9 +112,7 @@ exec_cmd= $(if $($(quiet)_cmd_$(1)),\
 #implicit rules
 %.o:%.c  $(ALLDEP)
 	$(call exec_cmd,CC)
-	@$(MKDEP) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) $< \
-	|  sed	-e 's/#.*//' -e '/:[ 	]*$$/d' -e '/^[ 	]*$$/d' \
-				-e 's#.*:#$@: $$(wildcard #g' -e 's/\([^\\]\)$$/\1)/'> $*.d
+	@$(call cmd_MKDEP)
 
 # use RPATH and SER_LIBS if needed (make install and the module depends
 # on some ser libs)




More information about the sr-dev mailing list