summaryrefslogtreecommitdiff
path: root/makefiles/depend.mk
diff options
context:
space:
mode:
Diffstat (limited to 'makefiles/depend.mk')
-rw-r--r--makefiles/depend.mk30
1 files changed, 30 insertions, 0 deletions
diff --git a/makefiles/depend.mk b/makefiles/depend.mk
new file mode 100644
index 0000000..bd49fe1
--- /dev/null
+++ b/makefiles/depend.mk
@@ -0,0 +1,30 @@
+# provides generic rules for C/C++ dependeny generation using
+# 'makedepend', 'gcc -MM' or similar mechanisms
+#
+# requires:
+# - compilers CC and CCPP
+# - INCLUDEDIRS
+# - OBJS, CPP_OBJS and BIN_OBJS
+#
+# provides:
+# - included dependency files
+#
+# author: Andreas Baumann, abaumann at yahoo dot com
+
+MAKEDEPEND = $(CC) -MM $(INCLUDE_DIRS)
+CCPP_MAKEDEPEND = $(CCPP) -MM $(INCLUDE_DIRS)
+
+%.d : %.c
+ @echo Generating dependencies for $<
+ @$(MAKEDEPEND) $(CFLAGS) $< | \
+ sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@
+
+%.d : %.cpp
+ @echo Generating dependencies for $<
+ @$(CCPP_MAKEDEPEND) $(CCPPFLAGS) $< | \
+ sed "s,\($*\.o\)[ :]*\(.*\),$@ : $$\(wildcard \2\)\&\&\&\1 : \2,g" | tr -s '&' "\n" > $@
+
+-include $(OBJS:.o=.d)
+-include $(CPP_OBJS:.o=.d)
+-include $(BIN_OBJS:.o=.d)
+-include $(CPP_BIN_OBJS:.o=.d)