The ultimative dependency generation

Andreas Schwab (schwab@issan.informatik.uni-dortmund.de)
Fri, 6 Dec 96 11:58:30 +0100


Here's a patch to implement the ultimative dependency generation with
gcc -MD. It has a number of advantages over the conventional `make
depend' thing:

- it has *NO* overhead (why duplicating part of the work of cpp?)
- dependencies are always up-to-date
- dependencies are always correct
- no need for such kludges as `# /*nodep*/ include'
- no bogus touching of header files any more, which will fail when the
files are read-only (perhaps because they reside on a read-only medium).

I'm using this method for already a long time with great success. I've
never had the need to make clean since then (i'm always upgrading through
patches), yet everything is correctly updated automagically.

However there are also some drawbacks:

- the checking of mkdep for a missing or extra inclusion of
<linux/config.h> cannot be done by gcc. On the other hand, this is of
no use for a user who just wants to recompile the kernel. But it is
still usefull to provide a program similar to mkdep that only does this
checking and which can be run occasionally after bigger changes.
- There's currently no easy way to regenerate a *.d file if it gets lost
somehow. In this case only the implict dependency on the *.c or *.S file
is known to make. You'll have to explicitly delete the *.o file to
force recompilation and regeneration of the *.d file.

IMHO the advantages outweigh these drawbacks by far.

Andreas.

----------------------------------------------------------------------
--- Makefile.~1~ Wed Nov 27 17:48:35 1996
+++ Makefile Mon Dec 2 18:07:35 1996
@@ -48,14 +48,8 @@
#
ifeq (.config,$(wildcard .config))
include .config
-ifeq (.depend,$(wildcard .depend))
-include .depend
do-it-all: Version vmlinux
else
-CONFIGURATION = depend
-do-it-all: depend
-endif
-else
CONFIGURATION = config
do-it-all: config
endif
@@ -103,6 +97,9 @@
endif
endif

+# automagically generated dependencies
+CFLAGS += -MD
+
#
# if you want the ram-disk device, define this to be the
# size in blocks.
@@ -153,14 +150,14 @@
.S.s:
$(CC) -D__ASSEMBLY__ $(AFLAGS) -traditional -E -o $*.s $<
.S.o:
- $(CC) -D__ASSEMBLY__ $(AFLAGS) -traditional -c -o $*.o $<
+ $(CC) -D__ASSEMBLY__ $(AFLAGS) -traditional -MD -c -o $@ $<

else

.S.s:
$(CC) -D__ASSEMBLY__ -traditional -E -o $*.s $<
.S.o:
- $(CC) -D__ASSEMBLY__ -traditional -c -o $*.o $<
+ $(CC) -D__ASSEMBLY__ -traditional -MD -c -o $@ $<

endif

@@ -234,10 +231,16 @@
@mv -f .ver $@

init/version.o: init/version.c include/linux/compile.h
- $(CC) $(CFLAGS) -DUTS_MACHINE='"$(ARCH)"' -c -o init/version.o init/version.c
+ @rm -f ${@:.o=.d}
+ SUNPRO_DEPENDENCIES="${@:.o=.d} $@" \
+ $(CC) $(filter-out -MD,$(CFLAGS)) -DUTS_MACHINE='"$(ARCH)"' -c $< -o $@

init/main.o: init/main.c
- $(CC) $(CFLAGS) $(PROFILING) -c -o $*.o $<
+ @rm -f ${@:.o=.d}
+ SUNPRO_DEPENDENCIES="${@:.o=.d} $@" \
+ $(CC) $(filter-out -MD,$(CFLAGS)) $(PROFILING) -c $< -o $@
+
+-include init/*.d

fs: dummy
$(MAKE) linuxsubdirs SUBDIRS=fs
@@ -329,6 +312,7 @@
rm -f include/asm
rm -f .depend `find . -name .depend -print`
rm -f .hdepend scripts/mkdep
+ rm -f `find . -name '*.d' -print`
rm -f $(TOPDIR)/include/linux/modversions.h
rm -f $(TOPDIR)/include/linux/modules/*

--- Rules.make.~1~ Fri Sep 27 19:23:23 1996
+++ Rules.make Mon Dec 2 18:08:10 1996
@@ -196,3 +196,5 @@
ifeq ($(TOPDIR)/.hdepend,$(wildcard $(TOPDIR)/.hdepend))
include $(TOPDIR)/.hdepend
endif
+
+-include *.d
--- arch/alpha/kernel/Makefile.~1~ Wed Jun 5 19:23:26 1996
+++ arch/alpha/kernel/Makefile Thu Dec 5 11:40:16 1996
@@ -10,7 +10,7 @@
.S.s:
$(CPP) -D__ASSEMBLY__ -traditional $< -o $*.s
.S.o:
- $(CC) -D__ASSEMBLY__ -traditional -c $< -o $*.o
+ $(CC) -D__ASSEMBLY__ -traditional -MD -c $< -o $@

all: kernel.o head.o

--- arch/alpha/lib/Makefile.~1~ Tue Nov 19 19:52:18 1996
+++ arch/alpha/lib/Makefile Thu Dec 5 11:45:22 1996
@@ -12,19 +12,19 @@
$(AR) rcs lib.a $(OBJS)

memset.o: memset.S
- $(CC) -c -o memset.o memset.S
+ $(CC) -MD -c -o memset.o memset.S

__divqu.o: divide.S
- $(CC) -DDIV -c -o __divqu.o divide.S
+ $(CC) -MD -DDIV -c -o __divqu.o divide.S

__remqu.o: divide.S
- $(CC) -DREM -c -o __remqu.o divide.S
+ $(CC) -MD -DREM -c -o __remqu.o divide.S

__divlu.o: divide.S
- $(CC) -DDIV -DINTSIZE -c -o __divlu.o divide.S
+ $(CC) -MD -DDIV -DINTSIZE -c -o __divlu.o divide.S

__remlu.o: divide.S
- $(CC) -DREM -DINTSIZE -c -o __remlu.o divide.S
+ $(CC) -MD -DREM -DINTSIZE -c -o __remlu.o divide.S

dep:

--- arch/i386/kernel/Makefile.~1~ Fri Sep 27 19:23:24 1996
+++ arch/i386/kernel/Makefile Thu Dec 5 11:49:01 1996
@@ -12,10 +12,10 @@

ifdef SMP
.S.o:
- $(CC) -D__ASSEMBLY__ $(AFLAGS) -traditional -c $< -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ $(AFLAGS) -traditional -c $< -o $@
else
.S.o:
- $(CC) -D__ASSEMBLY__ -traditional -c $< -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ -traditional -c $< -o $@
endif

all: kernel.o head.o
@@ -29,12 +29,12 @@
O_OBJS += smp.o

head.o: head.S $(TOPDIR)/include/linux/tasks.h
- $(CC) -D__ASSEMBLY__ -D__SMP__ -traditional -c $*.S -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ -D__SMP__ -traditional -c $< -o $@

else

head.o: head.S $(TOPDIR)/include/linux/tasks.h
- $(CC) -D__ASSEMBLY__ -traditional -c $*.S -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ -traditional -c $< -o $@

endif

--- arch/i386/lib/Makefile.~1~ Fri Sep 27 19:23:26 1996
+++ arch/i386/lib/Makefile Thu Dec 5 11:50:17 1996
@@ -4,10 +4,10 @@

ifdef SMP
.S.o:
- $(CC) -D__ASSEMBLY__ $(AFLAGS) -traditional -c $< -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ $(AFLAGS) -traditional -c $< -o $@
else
.S.o:
- $(CC) -D__ASSEMBLY__ -traditional -c $< -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ -traditional -c $< -o $@
endif

L_TARGET = lib.a
--- arch/i386/math-emu/Makefile.~1~ Wed Aug 16 21:18:49 1995
+++ arch/i386/math-emu/Makefile Thu Dec 5 11:51:01 1996
@@ -10,7 +10,7 @@
CFLAGS := $(CFLAGS) $(PARANOID) $(DEBUG) -fno-builtin $(MATH_EMULATION)

.S.o:
- $(CC) -D__ASSEMBLY__ $(PARANOID) -c $<
+ $(CC) -MD -D__ASSEMBLY__ $(PARANOID) -c $<

L_OBJS =fpu_entry.o div_small.o errors.o \
fpu_arith.o fpu_aux.o fpu_etc.o fpu_trig.o \
--- arch/m68k/kernel/Makefile.~1~ Fri Aug 30 19:12:38 1996
+++ arch/m68k/kernel/Makefile Thu Oct 17 16:27:02 1996
@@ -8,7 +8,7 @@
# Note 2! The CFLAGS definitions are now in the main makefile...

.S.o:
- $(CC) -D__ASSEMBLY__ -traditional -c $< -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ -traditional -c $< -o $@

all: kernel.o head.o
O_TARGET := kernel.o
--- arch/sparc/kernel/Makefile.~1~ Tue Nov 19 19:52:53 1996
+++ arch/sparc/kernel/Makefile Thu Dec 5 11:56:17 1996
@@ -13,7 +13,7 @@
$(CPP) -D__ASSEMBLY__ $(AFLAGS) -ansi $< -o $*.s

.S.o:
- $(CC) -D__ASSEMBLY__ $(AFLAGS) -ansi -c $< -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ $(AFLAGS) -ansi -c $< -o $@


else
@@ -22,7 +22,7 @@
$(CPP) -D__ASSEMBLY__ -ansi $< -o $*.s

.S.o:
- $(CC) -D__ASSEMBLY__ -ansi -c $< -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ -ansi -c $< -o $@


endif
@@ -53,12 +53,12 @@
ifdef SMP

head.o: head.S
- $(CC) -D__ASSEMBLY__ $(AFLAGS) -ansi -c $*.S -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ $(AFLAGS) -ansi -c $< -o $@

else

head.o: head.S
- $(CC) -D__ASSEMBLY__ -ansi -c $*.S -o $*.o
+ $(CC) -MD -D__ASSEMBLY__ -ansi -c $< -o $@

endif

--- arch/sparc/lib/Makefile.~1~ Tue Nov 19 19:53:15 1996
+++ arch/sparc/lib/Makefile Thu Dec 5 11:57:55 1996
@@ -13,52 +13,52 @@
sync

checksum.o: checksum.S
- $(CC) -ansi -c -o checksum.o checksum.S
+ $(CC) -MD -ansi -c -o checksum.o checksum.S

memcpy.o: memcpy.S
- $(CC) -D__ASSEMBLY__ -ansi -c -o memcpy.o memcpy.S
+ $(CC) -MD -D__ASSEMBLY__ -ansi -c -o memcpy.o memcpy.S

memcmp.o: memcmp.S
- $(CC) -ansi -c -o memcmp.o memcmp.S
+ $(CC) -MD -ansi -c -o memcmp.o memcmp.S

memscan.o: memscan.S
- $(CC) -ansi -c -o memscan.o memscan.S
+ $(CC) -MD -ansi -c -o memscan.o memscan.S

strncmp.o: strncmp.S
- $(CC) -ansi -c -o strncmp.o strncmp.S
+ $(CC) -MD -ansi -c -o strncmp.o strncmp.S

strncpy_from_user.o: strncpy_from_user.S
- $(CC) -D__ASSEMBLY__ -ansi -c -o strncpy_from_user.o strncpy_from_user.S
+ $(CC) -MD -D__ASSEMBLY__ -ansi -c -o strncpy_from_user.o strncpy_from_user.S

blockops.o: blockops.S
- $(CC) -ansi -c -o blockops.o blockops.S
+ $(CC) -MD -ansi -c -o blockops.o blockops.S

memset.o: memset.S
- $(CC) -D__ASSEMBLY__ -ansi -c -o memset.o memset.S
+ $(CC) -MD -D__ASSEMBLY__ -ansi -c -o memset.o memset.S

strlen.o: strlen.S
- $(CC) -ansi -c -o strlen.o strlen.S
+ $(CC) -MD -ansi -c -o strlen.o strlen.S

mul.o: mul.S
- $(CC) -c -o mul.o mul.S
+ $(CC) -MD -c -o mul.o mul.S

rem.o: rem.S
- $(CC) -DST_DIV0=0x2 -c -o rem.o rem.S
+ $(CC) -MD -DST_DIV0=0x2 -c -o rem.o rem.S

sdiv.o: sdiv.S
- $(CC) -DST_DIV0=0x2 -c -o sdiv.o sdiv.S
+ $(CC) -MD -DST_DIV0=0x2 -c -o sdiv.o sdiv.S

udiv.o: udiv.S
- $(CC) -DST_DIV0=0x2 -c -o udiv.o udiv.S
+ $(CC) -MD -DST_DIV0=0x2 -c -o udiv.o udiv.S

umul.o: umul.S
- $(CC) -c -o umul.o umul.S
+ $(CC) -MD -c -o umul.o umul.S

urem.o: urem.S
- $(CC) -DST_DIV0=0x2 -c -o urem.o urem.S
+ $(CC) -MD -DST_DIV0=0x2 -c -o urem.o urem.S

ashrdi3.o: ashrdi3.S
- $(CC) -c -o ashrdi3.o ashrdi3.S
+ $(CC) -MD -c -o ashrdi3.o ashrdi3.S

dep:

--- drivers/char/Makefile.~1~ Wed Nov 27 17:49:15 1996
+++ drivers/char/Makefile Wed Nov 27 18:12:15 1996
@@ -353,7 +353,7 @@

fastdep: uni_hash.tbl

-consolemap.o:
+consolemap.o: uni_hash.tbl

conmakehash: conmakehash.c
$(HOSTCC) -o conmakehash conmakehash.c