Browse code

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).

Andrei Pelinescu-Onciul authored on 10/03/2010 08:25:13
Showing 2 changed files
... ...
@@ -74,6 +74,9 @@
74 74
 #              from the host (andrei)
75 75
 #  2009-10-01  use -fsigned-char for gcc on ppc, ppc64, arm and arm6
76 76
 #              (on those archs char is unsigned by default) (andrei)
77
+#  2010-03-10  added CC_MKDEP_OPTS, which contains to the list of options
78
+#               needed to generate dependencies on-the-fly while compiling
79
+#               or is empty if the compiler doesn't support it (andrei)
77 80
 
78 81
 quiet?=$(if $(filter 1 yes on,$(Q)),silent,verbose)
79 82
 
... ...
@@ -351,7 +354,7 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
351 351
 #				 	 -e 's/^[^0-9].*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/')
352 352
 	# sed with POSIX.1 regex doesn't support |, + or ? 
353 353
         # (darwin, solaris ...) => this complicated expression
354
-	MKDEP=$(CC) -MM 
354
+	MKDEP=$(CC) -MM -MG
355 355
 	#transform gcc version into 2.9x or 3.0
356 356
 	CC_SHORTVER:=$(shell echo "$(CC_VER)" | cut -d" " -f 2| \
357 357
 				 sed -e 's/[^0-9]*-\(.*\)/\1/'| \
... ...
@@ -360,7 +363,11 @@ ifneq (,$(findstring gcc, $(CC_LONGVER)))
360 360
 					's/3\.[4-9]/3.4/' -e 's/4\.[0-1]\..*/4.x/' -e \
361 361
 					's/4\.[0-1]/4.x/' -e 's/4\.[2-9]\..*/4.2+/' -e \
362 362
 					's/4\.[2-9]$$/4.2+/')
363
-endif
363
+ifeq (,$(strip $(filter-out 3.0 3.4 4.x 4.2+,$(CC_SHORTVER))))
364
+	# dependencies can be generated on-the-fly while compiling *.c
365
+	CC_MKDEP_OPTS=-MMD -MP
366
+endif # 3.0 <= $(CC_SHORTVER) <= 4.x
367
+endif # gcc
364 368
 
365 369
 ifneq (, $(findstring Sun, $(CC_LONGVER)))
366 370
 	CC_NAME=suncc
... ...
@@ -1947,6 +1954,7 @@ export exported_vars
1947 1947
 saved_fixed_vars:=	MAIN_NAME  CFG_NAME SCR_NAME FLAVOUR INSTALL_FLAVOUR \
1948 1948
 		SRC_NAME RELEASE OS ARCH \
1949 1949
 		C_DEFS DEFS_RM PROFILE CC LD MKDEP MKTAGS LDFLAGS C_INCLUDES \
1950
+		CC_MKDEP_OPTS \
1950 1951
 		MOD_LDFLAGS LIB_LDFLAGS UTILS_LDFLAGS LIB_SONAME LD_RPATH \
1951 1952
 		LIB_SUFFIX LIB_PREFIX \
1952 1953
 		LIBS \
... ...
@@ -25,6 +25,11 @@
25 25
 #              used only for "temporary" defines/includes inside modules or
26 26
 #              libs, C_DEFS and C_INCLUDES are used for the common stuff)
27 27
 #              (andrei)
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)
28 33
 
29 34
 
30 35
 # 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 $@
59 59
 cmd_LD=$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(ALL_LIBS) $(SER_RPATH) \
60 60
 	-o $(NAME)
61 61
 
62
+ifeq (,$(CC_MKDEP_OPTS))
63
+# if CCC_MKDEP_OPTS is empty => CC cannot generate dependencies on the fly
64
+cmd_MKDEP=$(MKDEP) $(filter -D% -I%,$(CFLAGS)) $(C_INCLUDES) $(INCLUDES) \
65
+			$(C_DEFS) $(DEFS) $< \
66
+		|  sed	-e 's/\#.*//' -e '/:[ 	]*$$/d' -e '/^[ 	]*$$/d' \
67
+				-e 's|.*:|$@: $$(wildcard |' -e 's/\([^\\]\)$$/\1)/'> $*.d
68
+else
69
+# deps can be generated on the fly by cmd_CC
70
+cmd_CC+=$(CC_MKDEP_OPTS)
71
+# no MKDEP command any more
72
+cmd_MKDEP=
73
+endif # CC_MKDEP_OPTS
74
+
62 75
 # what will be displayed if quiet==silent
63 76
 silent_cmd_CC=CC ($(CC)) [$(strip $(crt_type) $(NAME))]		$@
64 77
 silent_cmd_LD=LD ($(LD)) [$(strip $(crt_type) $(NAME))]		$@
... ...
@@ -94,9 +112,7 @@ exec_cmd= $(if $($(quiet)_cmd_$(1)),\
94 94
 #implicit rules
95 95
 %.o:%.c  $(ALLDEP)
96 96
 	$(call exec_cmd,CC)
97
-	@$(MKDEP) $(CFLAGS) $(C_INCLUDES) $(INCLUDES) $(C_DEFS) $(DEFS) $< \
98
-	|  sed	-e 's/#.*//' -e '/:[ 	]*$$/d' -e '/^[ 	]*$$/d' \
99
-				-e 's#.*:#$@: $$(wildcard #g' -e 's/\([^\\]\)$$/\1)/'> $*.d
97
+	@$(call cmd_MKDEP)
100 98
 
101 99
 # use RPATH and SER_LIBS if needed (make install and the module depends
102 100
 # on some ser libs)