aboutsummaryrefslogtreecommitdiffhomepage
path: root/Makefile
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-11-10 08:04:54 -0800
committerGravatar Carl Worth <cworth@cworth.org>2009-11-10 08:04:54 -0800
commit97c7cffdc6e0047bb49a899b013516bc3022e580 (patch)
tree5fa7fdc8975877c94410f33cfe5353f000e08788 /Makefile
parentc5dccd851a8b79d8cedbfc8f2d2b8f9be2b7fa5a (diff)
Makefile: Fix dependency generation to make .d files themselves dependent.
I saw this recommendation in the implementation notes for "Recursive Make Considered Harmful" and then the further recommendation for implementing the idea in the GNU make manual. The idea is that if any of the files change then we need to regenerate the dependency file before we regenerate any targets. The approach from the GNU make manual is simpler in that it just uses a sed script to fix up the output of an extra invocation of the compiler, (as opposed to the approach in the implementation notes from the paper's author which use a wrapper script for the compiler that's always invoked rather than the compiler itself).
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile25
1 files changed, 16 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 91ab9c02..7743ef52 100644
--- a/Makefile
+++ b/Makefile
@@ -19,14 +19,21 @@ include lib/Makefile.local
%.o: %.c
$(CC) -c $(CFLAGS) $(NOTMUCH_CFLAGS) $< -o $@
-.depends: $(SRCS)
- $(CXX) -M $(CPPFLAGS) $(NOTMUCH_DEPENDS_FLAGS) \
- $(NOTMUCH_CXX_DEPENDS_FLAGS) $^ > $@
--include .depends
-
-CLEAN := $(CLEAN) .depends
+.deps/%.d: %.c
+ @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
+ $(CC) -M $(CPPFLAGS) $(NOTMUCH_DEPENDS_FLAGS) $< > $@.$$$$; \
+ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+
+.deps/%.d: %.cc
+ @set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
+ $(CXX) -M $(CPPFLAGS) $(NOTMUCH_CXX_DEPENDS_FLAGS) $< > $@.$$$$; \
+ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
+ rm -f $@.$$$$
+
+DEPS := $(SRCS:%.c=.deps/%.d)
+DEPS := $(DEPS:%.cc=.deps/%.d)
+-include $(DEPS)
clean:
- rm -f $(CLEAN)
-
-
+ rm -f $(CLEAN); rm -rf .deps