diff Makefile @ 18:4a5330979433

Modernize and improve build system Do not clobber CPPFLAGS, use XCPPFLAGS instead. Request POSIX:2004 headers and libraries. Remove support for FreeBSD < 9. Add support for DragonFly BSD.
author Guido Berhoerster <guido+xwrited@berhoerster.name>
date Wed, 14 Sep 2016 09:46:59 +0200
parents 48caa69c609d
children f0accfc74f7b
line wrap: on
line diff
--- a/Makefile	Tue Sep 13 20:59:33 2016 +0200
+++ b/Makefile	Wed Sep 14 09:46:59 2016 +0200
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
+# Copyright (C) 2016 Guido Berhoerster <guido+xwrited@berhoerster.name>
 #
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
@@ -26,12 +26,15 @@
 VERSION =	2
 DISTNAME :=	$(PACKAGE)-$(VERSION)
 
+# gcc, clang, icc, Sun/Solaris Studio
+CC :=		$(CC) -std=c99
+COMPILE.c =	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(TARGET_ARCH) -c
 # gcc, clang, icc
-MAKEDEPEND.c =	$(CC) -MM $(CFLAGS) $(CPPFLAGS)
+MAKEDEPEND.c =	$(CC) -MM $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
 # Sun/Solaris Studio
-#MAKEDEPEND.c =	$(CC) -xM1 $(CFLAGS) $(CPPFLAGS)
+#MAKEDEPEND.c =	$(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
 # X makedepend
-#MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(CPPFLAGS) --
+#MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
 INSTALL :=	install
 INSTALL.exec :=	$(INSTALL) -D -m 0755
 INSTALL.data :=	$(INSTALL) -D -m 0644
@@ -72,50 +75,28 @@
 OS_NAME :=	$(shell uname -s)
 OS_RELEASE :=	$(shell uname -r)
 
-is_in = $(if $(filter $2, $1),true,false)
-
-PKGCONFIG_LIBS :=	dbus-1 glib-2.0 libnotify
-EXTRA_LIBS :=
-
-ifeq ($(OS_NAME),Linux)
-    OBJS_UTMP :=	xwrited-utmp-utempter.o
-    EXTRA_LIBS +=	-lutempter
-else ifeq ($(OS_NAME),FreeBSD)
-    OBJS_UTMP :=	xwrited-utmp-utempter.o
-    FREEBSD_RELEASE_MAJOR := $(firstword $(subst ., ,$(OS_RELEASE)))
-    # FreeBSD < 9.0 needs libutempter
-    ifeq ($(call is_in, $(OS_RELEASE_MAJOR), 7 8), true)
-	EXTRA_LIBS +=	-lutempter
-    else
-	EXTRA_LIBS +=	-lulog
-    endif
+ifeq ($(shell pkg-config --exists 'glib-2.0 >= 2.25.5' && printf "true"),true)
+  HAVE_GLIB_GDBUS = 1
 else
-    OBJS_UTMP :=	xwrited-utmp-utmpx.o
+  HAVE_GLIB_GDBUS = 0
 endif
 
-ifeq ($(shell pkg-config --exists 'glib-2.0 >= 2.25.5' && printf "true"), true)
-    CPPFLAGS_EXTRA :=	-DHAVE_GLIB_GDBUS
+PKGCONFIG_LIBS := dbus-1 glib-2.0 libnotify
+ifeq ($(HAVE_GLIB_GDBUS),1)
+  PKGCONFIG_LIBS +=	dbus-glib-1
+endif
+OBJS =		main.o xwrited-debug.o xwrited-unique.o
+ifneq ($(findstring $(OS_NAME),Linux FreeBSD),)
+  OBJS +=	xwrited-utmp-utempter.o
 else
-    PKGCONFIG_LIBS +=	dbus-glib-1
+  OBJS +=	xwrited-utmp-utmpx.o
 endif
-
-OBJS =		main.o xwrited-debug.o xwrited-unique.o $(OBJS_UTMP)
 MANPAGES =	data/$(PACKAGE).1
 AUTOSTART_FILE = data/$(PACKAGE).desktop
 MOFILES :=	$(patsubst %.po,%.mo,$(wildcard po/*.po))
 POTFILE =	po/$(PACKAGE).pot
 POSRCS :=	$(shell $(SED) -e 's/\#.*//' -e '/^[ \t]*$$/d' \
 		-e 's/^\[[^]]*\]//' po/POTFILES.in | $(PASTE) -s -d ' ')
-CPPFLAGS := 	$(CPPFLAGS_EXTRA) \
-		$(CPPFLAGS_LIBUTEMPTER) \
-		$(shell pkg-config --cflags $(PKGCONFIG_LIBS)) \
-		-DPACKAGE="\"$(PACKAGE)\"" \
-		-DAPP_NAME=\"$(APP_NAME)\" \
-		-DVERSION=\"$(VERSION)\" \
-		-DLOCALEDIR="\"$(localedir)\"" \
-		-DG_LOG_DOMAIN=\"$(PACKAGE)\"
-LDLIBS :=	$(EXTRA_LIBS) \
-		$(shell pkg-config --libs $(PKGCONFIG_LIBS))
 DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \
 			  --stringparam man.copyright.section.enabled 0
 
@@ -125,6 +106,25 @@
 
 all: $(PACKAGE) $(MANPAGES) $(MOFILES) $(AUTOSTART_FILE)
 
+$(PACKAGE): CPPFLAGS :=	$(shell pkg-config --cflags $(PKGCONFIG_LIBS)) \
+			-D_XOPEN_SOURCE=600 \
+			-DPACKAGE="\"$(PACKAGE)\"" \
+			-DAPP_NAME=\"$(APP_NAME)\" \
+			-DVERSION=\"$(VERSION)\" \
+			-DLOCALEDIR="\"$(localedir)\"" \
+			-DG_LOG_DOMAIN=\"$(PACKAGE)\"
+$(PACKAGE): LDLIBS :=	$(shell pkg-config --libs $(PKGCONFIG_LIBS))
+ifeq ($(HAVE_GLIB_GDBUS),1)
+  $(PACKAGE): XCPPFLAGS += -DHAVE_GLIB_GDBUS
+endif
+ifeq ($(OS_NAME),Linux)
+  $(PACKAGE): LDLIBS +=	-lutempter
+else ifeq ($(OS_NAME),FreeBSD)
+  $(PACKAGE): LDLIBS +=	-lulog
+else ifeq ($(OS_NAME),SunOS)
+  $(PACKAGE): XCPPFLAGS += -I/usr/xpg4/include
+  $(PACKAGE): XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
+endif
 $(PACKAGE): $(OBJS)
 	$(LINK.o) $^ $(LDLIBS) -o $@