about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-22T15·10+0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-22T15·11+0000
commitbc96c4518e4430f0cd996b2c77fe8e08d7694efa (patch)
treebc727872eb7d9511ab1d78eb8b2b3982d5683601
parentb8e9efc476abc248a17c9e9cd117f3d53e4a7f63 (diff)
Automatically emit make rules for header files
-rw-r--r--.gitignore1
-rw-r--r--Makefile.lib10
2 files changed, 7 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index a8f5a2379116..ed9bd45a45a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -129,6 +129,7 @@ Makefile.config
 *.la
 *.o
 *.so
+*.dep
 *~
 
 # GNU Global
diff --git a/Makefile.lib b/Makefile.lib
index d681cf7412a2..1aec37c76f33 100644
--- a/Makefile.lib
+++ b/Makefile.lib
@@ -7,10 +7,10 @@ LIBS =
 QUIET = @
 
 %.o: %.cc
-	$(QUIET) g++ -o $@ -c $^ -g -fPIC $(CXXFLAGS) $($@_CXXFLAGS)
+	$(QUIET) g++ -o $@ -c $< -g -fPIC $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP
 
 %.o: %.c
-	$(QUIET) gcc -o $@ -c $^ -g -fPIC $(CFLAGS) $($@_CFLAGS)
+	$(QUIET) gcc -o $@ -c $< -g -fPIC $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP
 
 
 # Generate Make rules for libraries.
@@ -28,7 +28,9 @@ define LIBS_template =
   # Propagate CXXFLAGS to the individual object files.
   $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
 
-  clean_list += $$(_lib) $$(_objs)
+  include $$(wildcard $$(_d)/*.dep)
+
+  clean_list += $$(_lib) $$(_objs) $$(_d)*.dep
   libs_list += $$(_lib)
 endef
 
@@ -48,7 +50,7 @@ define PROGRAMS_template =
   # Propagate CXXFLAGS to the individual object files.
   $$(foreach obj, $$(_objs), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
 
-  clean_list += $$(_prog) $$(_objs)
+  clean_list += $$(_prog) $$(_objs) $$(_d)*.dep
   programs_list += $$(_prog)
 endef