changeset 7:56a7ed833d0a

allow overriding CFLAGS add automatic target dependencies to makefile add install target to Makefile minor makefile fixes
author Guido Berhoerster <guido@berhoerster.name>
date Tue, 11 Oct 2011 17:07:49 +0200
parents 7539e6e1c299
children 58a3312a1c59
files Makefile
diffstat 1 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Thu Oct 06 16:02:19 2011 +0200
+++ b/Makefile	Tue Oct 11 17:07:49 2011 +0200
@@ -1,16 +1,44 @@
-CC=gcc
-OBJS=main.o notify.o packagekit.o
-CFLAGS=$(shell pkg-config --cflags gtk+-2.0 libnotify packagekit-glib2) -Wall -DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
-LDFLAGS=$(shell pkg-config --libs gtk+-2.0 libnotify packagekit-glib2)
-NAME=pk-update-icon
+INSTALL :=	install
+INSTALL.exec :=	$(INSTALL) -D -m 0755
+INSTALL.data :=	$(INSTALL) -D -m 0644
+SED :=		sed
+
+DESTDIR ?=
+prefix ?=	/usr/local
+bindir ?=	$(prefix)/bin
+sysconfdir ?=	/etc
+xdgautostartdir ?=	$(sysconfdir)/xdg/autostart
 
-all: $(NAME)
+PACKAGE =	pk-update-icon
+VERSION =	0.1
+OBJS =		main.o notify.o packagekit.o
+AUTOSTART_FILE =	$(PACKAGE).desktop
+CPPFLAGS :=	$(shell pkg-config --cflags gtk+-2.0 libnotify packagekit-glib2) \
+		-DI_KNOW_THE_PACKAGEKIT_GLIB2_API_IS_SUBJECT_TO_CHANGE
+LDLIBS :=	$(shell pkg-config --libs gtk+-2.0 libnotify packagekit-glib2)
 
-$(NAME): $(OBJS)
-	$(CC) $(OBJS) $(LDFLAGS) -o $(NAME)
+.DEFAULT_TARGET = all
+
+.PHONY: all clean install
+
+all: $(PACKAGE)
+
+$(PACKAGE): $(OBJS)
+	$(LINK.o) $^ $(LDLIBS) -o $@
 
 %.o: %.c
-	$(CC) -c $< $(CFLAGS) -o $@
+	$(COMPILE.c) -MD -o $@ $<
+	@cp $*.d $*.P; \
+	$(SED) -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
+	       -e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
+	rm -f $*.d
+
+install:
+	$(INSTALL.exec) $(PACKAGE) $(DESTDIR)$(bindir)/$(PACKAGE)
+	$(INSTALL.data) $(AUTOSTART_FILE) \
+			$(DESTDIR)$(xdgautostartdir)/$(AUTOSTART_FILE)
 
 clean:
-	rm -f $(OBJS) $(NAME)
+	-rm -f $(PACKAGE) $(OBJS)
+
+-include $(patsubst %.o,%.P,$(OBJS))