Generate source dependency informations on the fly
Commit Message
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.
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
batman-adv-userspace/Makefile | 10 ++++------
batman/Makefile | 9 ++++-----
battool/Makefile | 7 ++++---
vis-advanced/Makefile | 10 ++++------
4 files changed, 16 insertions(+), 20 deletions(-)
@@ -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:
@@ -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:
@@ -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:
@@ -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 *~