changeset 35:b84b4ae937e3

Fix automatic dependency generation and improve portability
author Guido Berhoerster <gber@opensuse.org>
date Fri, 07 Feb 2014 17:55:13 +0100
parents 6049c7540dba
children 82a31628a26d
files Makefile deps.sed
diffstat 2 files changed, 61 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sat Apr 27 14:36:55 2013 +0000
+++ b/Makefile	Fri Feb 07 17:55:13 2014 +0100
@@ -1,3 +1,34 @@
+#
+# Copyright (C) 2014 Guido Berhoerster <gber@opensuse.org>
+#
+# Licensed under the GNU General Public License Version 2
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+PACKAGE =	pk-update-icon
+APP_NAME =	org.opensuse.pk-update-icon
+VERSION =	0.2.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
@@ -17,10 +48,6 @@
 sysconfdir ?=	/etc
 xdgautostartdir ?=	$(sysconfdir)/xdg/autostart
 
-PACKAGE =	pk-update-icon
-APP_NAME =	org.opensuse.pk-update-icon
-VERSION =	0.2.2
-DISTNAME :=	$(PACKAGE)-$(VERSION)
 OBJS =		main.o pkui-icon.o pkui-backend.o
 AUTOSTART_FILE =	$(PACKAGE).desktop
 MOFILES :=	$(patsubst %.po,%.mo,$(wildcard po/*.po))
@@ -54,11 +81,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 $@ $<
 
 %.desktop: %.desktop.in $(MOFILES)
 	$(INTLTOOL_MERGE) --desktop-style --utf8 po $< $@
@@ -81,11 +105,11 @@
 	rm -f $(PACKAGE) $(OBJS) $(POTFILE) $(MOFILES) $(AUTOSTART_FILE)
 
 clobber: clean
-	rm -f *.P
+	rm -f $(patsubst %.o,%.d,$(OBJS))
 
 dist: clobber
 	rm -f $(DISTNAME)
 	ln -s -f . $(DISTNAME)
 	$(TAR) cv $(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:55:13 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)\
+&/
+}