improve auto dependencies
Stefan Schuermans

Stefan Schuermans commited on 2017-09-23 12:32:50
Showing 2 changed files, with 5 additions and 10 deletions.

... ...
@@ -1,3 +1,2 @@
1 1
 Blinker
2 2
 config.mk
3
-deps
... ...
@@ -6,7 +6,7 @@ CPP := g++
6 6
 CONFIG :=
7 7
 DEFINE :=
8 8
 INCLUDE := -Icommon -Ilinux
9
-CFLAGS := -Wall -Wextra -Werror -O2 -g2
9
+CFLAGS := -Wall -Wextra -Werror -O2
10 10
 LDFLAGS :=
11 11
 LIBS := -lBlinkenLib
12 12
 
... ...
@@ -20,12 +20,12 @@ OBJS := $(addsuffix .o,$(SRCS_BASE))
20 20
 .SUFFIXES:
21 21
 .SECONDARY:
22 22
 
23
-all: $(TARGET)
23
+all: $(DEPS) $(TARGET)
24 24
 
25 25
 ifneq ($(MAKECMDGOALS),clean)
26 26
   ifneq ($(MAKECMDGOALS),distclean)
27 27
     include config.mk
28
-    include deps
28
+    -include $(DEPS)
29 29
   endif
30 30
 endif
31 31
 
... ...
@@ -37,12 +37,8 @@ config.mk: $(CFGS_MK)
37 37
 %.cfg.mk: %.cfg.sh
38 38
 	sh $< >$@
39 39
 
40
-deps: $(DEPS)
41
-	cat /dev/null $^ >$@
42
-
43 40
 %.d: %.cpp Makefile config.mk
44
-	$(CPP) $(DEFINE) $(INCLUDE) $(CFLAGS) -M -o $@ $<
45
-	sed -i 1s!^!$(dir $<)! $@
41
+	$(CPP) $(DEFINE) $(INCLUDE) $(CFLAGS) -MM -MF $@ -MT $(@:.d=.o) $<
46 42
 
47 43
 %.o: %.cpp Makefile
48 44
 	$(CPP) $(DEFINE) $(INCLUDE) $(CFLAGS) -c -o $@ $<
... ...
@@ -51,7 +47,7 @@ $(TARGET): $(OBJS)
51 47
 	$(CPP) $(LDFLAGS) -o $@ $+ $(LIBS)
52 48
 
53 49
 clean:
54
-	rm -f deps $(DEPS) $(OBJS) $(TARGET)
50
+	rm -f $(DEPS) $(OBJS) $(TARGET)
55 51
 
56 52
 distclean: clean
57 53
 	rm -f config.mk $(CFGS_MK)
58 54