]> git.notmuchmail.org Git - notmuch/commitdiff
Makefile: Fix dependency generation to make .d files themselves dependent.
authorCarl Worth <cworth@cworth.org>
Tue, 10 Nov 2009 16:04:54 +0000 (08:04 -0800)
committerCarl Worth <cworth@cworth.org>
Tue, 10 Nov 2009 16:04:54 +0000 (08:04 -0800)
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).

Makefile
lib/Makefile.local

index 91ab9c02cd623f583e03b5b241858f4b0fb40f43..7743ef52cf98f0b3babd0cd99d9c8c47f6de49bb 100644 (file)
--- 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
index b5182bc4cb0d650e9d298feb1d36f57d1ba6a706..43882a3dfcb2dbdb9567ae9e3b9112615f27f219 100644 (file)
@@ -1,19 +1,22 @@
 dir=lib
 
-lib_notmuch_modules =          \
-       $(dir)/database.o       \
-       $(dir)/index.o          \
-       $(dir)/$(dir)sha1.o     \
-       $(dir)/message.o        \
-       $(dir)/message-file.o   \
-       $(dir)/query.o          \
-       $(dir)/sha1.o           \
-       $(dir)/tags.o           \
-       $(dir)/thread.o         \
-       $(dir)/xutil.o
+libnotmuch_c_srcs =            \
+       $(dir)/libsha1.c        \
+       $(dir)/message-file.c   \
+       $(dir)/sha1.c           \
+       $(dir)/tags.c           \
+       $(dir)/xutil.c
 
-$(dir)/notmuch.a: $(lib_notmuch_modules)
+libnotmuch_cxx_srcs =          \
+       $(dir)/database.cc      \
+       $(dir)/index.cc         \
+       $(dir)/message.cc       \
+       $(dir)/query.cc         \
+       $(dir)/thread.cc
+
+libnotmuch_modules = $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o)
+$(dir)/notmuch.a: $(libnotmuch_modules)
        $(AR) rcs $@ $^
 
-SRCS  := $(SRCS) lib/*.c lib/*.cc
-CLEAN := $(CLEAN) $(dir)/*.o $(dir)/notmuch.a
+SRCS  := $(SRCS) $(libnotmuch_c_srcs) $(libnotmuch_cxx_srcs)
+CLEAN := $(CLEAN) $(libnotmuch_modules) $(dir)/notmuch.a