Skip to contentSkip to conversation

Generate source dependency informations on the fly

PATCH New Sven Eckelmann 1 participant 1 message Mar 2, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Generate source dependency informations on the fly

The current way to track dependencies in batman and related tools is to look for changes in the .c file and if it exist the .h file with the same name. This can lead to inconsistent compilations when changes are done in a header which is included in different .c files. The easiest workaround is to let the compiler generate the dependency information which is then included in the makefile to notice changes in directly and indirectly included files. The first run is made without these informations during the build of object files. No extra execve or gcc startup related overhead is generated in that way and future changes are still tracked by make.

---
 batman-adv-userspace/Makefile |   10 ++++------
 batman/Makefile               |    9 ++++-----
 battool/Makefile              |    7 ++++---
 vis-advanced/Makefile         |   10 ++++------
 4 files changed, 16 insertions(+), 20 deletions(-)
batman-adv-userspace/Makefile +4 -6
index 6e3c2dd..265799b 100644
@@ -60,11 +60,9 @@ all:
 $(BINARY_NAME):	$(SRC_O) $(SRC_H) Makefile
 	$(Q_LD)$(CC) -o $@ $(SRC_O) $(LDFLAGS)
 
-%.o: %.c %.h
-	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
-
-%.o: %.c
-	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
+.c.o:
+	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -MD -c $< -o $@
+-include $(SRC_C:.c=.d)
 
 sources:
 	mkdir -p $(FILE_NAME)
@@ -80,7 +78,7 @@ sources:
 	tar czvf $(FILE_NAME).tgz $(FILE_NAME)
 
 clean:
-	rm -f $(BINARY_NAME) *.o
+	rm -f $(BINARY_NAME) *.o *.d
 
 
 clean-long:
batman/Makefile +4 -5
index 565d75e..509217d 100644
@@ -78,11 +78,9 @@ all:
 $(BINARY_NAME):	$(SRC_O) $(SRC_H) Makefile
 	$(Q_LD)$(CC) -o $@ $(SRC_O) $(LDFLAGS)
 
-%.o: %.c %.h
-	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
-
-%.o: %.c
-	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
+.c.o:
+	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -MD -c $< -o $@
+-include $(SRC_C:.c=.d)
 
 sources:
 	mkdir -p $(FILE_NAME)
@@ -99,6 +97,7 @@ sources:
 
 clean:
 	rm -f $(BINARY_NAME) *.o posix/*.o linux/*.o bsd/*.o
+	rm -f `find . -name '*.d' -print`
 
 
 clean-long:
battool/Makefile +4 -3
index 10d310f..4c8d497 100644
@@ -73,8 +73,9 @@ all:		$(BINARY_NAME)
 $(BINARY_NAME):	$(SRC_O) $(SRC_H) Makefile
 	$(Q_LD)$(CC) -o $@ $(SRC_O) $(LDFLAGS)
 
-%.o: %.c
-	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
+.c.o:
+	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -MD -c $< -o $@
+-include $(SRC_C:.c=.d)
 
 sources:
 	mkdir -p $(FILE_NAME)
@@ -91,7 +92,7 @@ sources:
 	tar czvf $(FILE_NAME).tgz $(FILE_NAME)
 
 clean:
-	rm -f $(BINARY_NAME) *.o
+	rm -f $(BINARY_NAME) *.o *.d
 
 
 clean-long:
vis-advanced/Makefile +4 -6
index 548d85f..3eaf1eb 100644
@@ -42,11 +42,9 @@ vis-adv:	$(SRC_O) Makefile
 vis-adv-static:	$(SRC_O) Makefile
 		$(Q_LD)$(CC) $(CFLAGS) -o $@ $(SRC_O) $(LDFLAGS_STATIC)
 
-%.o: %.c %.h
-	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
-
-%.o: %.c
-	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@
+.c.o:
+	$(Q_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) -MD -c $< -o $@
+-include $(SRC_C:.c=.d)
 
 clean:
-		rm -f vis-adv vis-adv-static *.o *~
+		rm -f vis-adv vis-adv-static *.o *.d *~
Signature · 1 line
1.6.1.3