%.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
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