changeset 11:4df0dc4dcc3d

Fix automatic dependency generation and improve portability
author Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
date Fri, 07 Feb 2014 17:54:41 +0100
parents d3e7ff315d98
children a59a7fd5be70
files Makefile deps.sed
diffstat 2 files changed, 36 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Aug 08 17:39:15 2013 +0200
+++ b/Makefile	Fri Feb 07 17:54:41 2014 +0100
@@ -26,6 +26,12 @@
 VERSION =	2
 DISTNAME :=	$(PACKAGE)-$(VERSION)
 
+# gcc, clang, icc
+MAKEDEPEND.c =	$(CC) -MM $(CFLAGS) $(CPPFLAGS)
+# Sun/Solaris Studio
+#MAKEDEPEND.c =	$(CC) -xM1 $(CFLAGS) $(CPPFLAGS)
+# X makedepend
+#MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(CPPFLAGS) --
 INSTALL :=	install
 INSTALL.exec :=	$(INSTALL) -D -m 0755
 INSTALL.data :=	$(INSTALL) -D -m 0644
@@ -109,11 +115,8 @@
 	done
 
 %.o: %.c
-	$(COMPILE.c) -MD -o $@ $<
-	@cp $*.d $*.P; \
-	$(SED) -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' \
-	        -e 's/$$/ :/' < $*.d >> $*.P; \
-	rm -f $*.d
+	$(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
+	$(COMPILE.c) -o $@ $<
 
 $(foreach section,1 2 3 4 5 6 7 8 9,$(eval $(call generate-manpage-rule,$(section))))
 
@@ -142,10 +145,10 @@
 	rm -f $(PACKAGE) $(OBJS) $(POTFILE) $(MOFILES) $(MANPAGES) $(AUTOSTART_FILE)
 
 clobber: clean
-	rm -f *.P
+	rm -f $(patsubst %.o,%.d,$(OBJS))
 
 dist: clobber
 	$(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
 	    -s ',\./,$(DISTNAME)/,' . | $(GZIP) > $(DISTNAME).tar.gz
 
--include $(patsubst %.o,%.P,$(OBJS))
+-include $(patsubst %.o,%.d,$(OBJS))
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/deps.sed	Fri Feb 07 17:54:41 2014 +0100
@@ -0,0 +1,26 @@
+/^[^:]\{1,\}:.*\\$/{
+    h
+    s/\([^:]\{1,\}:\).*/\1/
+    x
+    s/[^:]\{1,\}://
+}
+/\\$/,/^$/bgen
+/\\$/,/[^\\]$/{
+:gen
+    s/[[:blank:]]*\\$//
+    s/^[[:blank:]]*//
+    G
+    s/\(.*\)\n\(.*\)/\2 \1/
+}
+/^[^:]\{1,\}:[[:blank:]]*$/d
+/^[^:]\{1,\}\.o:/{
+    s/[[:blank:]]*[^[:blank:]]\{1,\}\.[cC][[:blank:]]*/ /g
+    s/[[:blank:]]*[^[:blank:]]\{1,\}\.[cC]$//g
+    s/[[:blank:]]*[^[:blank:]]\{1,\}\.cc[[:blank:]]*/ /g
+    s/[[:blank:]]*[^[:blank:]]\{1,\}\.cc$//g
+    s/[[:blank:]]*[^[:blank:]]\{1,\}\.cpp[[:blank:]]*/ /g
+    s/[[:blank:]]*[^[:blank:]]\{1,\}\.cpp$//g
+    /^[^:]\{1,\}:[[:blank:]]*$/d
+    s/^\([^:]\{1,\}\)\.o[[:blank:]]*:[[:blank:]]*\(.*\)/\1.d: $(wildcard \2)\
+&/
+}