projects/xwrited

changeset 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 Sep 14 09:46:59 2016 +0200 (2016-09-14)
parents 48caa69c609d
children f0accfc74f7b
files Makefile README main.c xwrited-debug.c xwrited-unique.c xwrited-utmp-utempter.c xwrited-utmp-utmpx.c
line diff
     1.1 --- a/Makefile	Tue Sep 13 20:59:33 2016 +0200
     1.2 +++ b/Makefile	Wed Sep 14 09:46:59 2016 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  #
     1.5 -# Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
     1.6 +# Copyright (C) 2016 Guido Berhoerster <guido+xwrited@berhoerster.name>
     1.7  #
     1.8  # Permission is hereby granted, free of charge, to any person obtaining
     1.9  # a copy of this software and associated documentation files (the
    1.10 @@ -26,12 +26,15 @@
    1.11  VERSION =	2
    1.12  DISTNAME :=	$(PACKAGE)-$(VERSION)
    1.13  
    1.14 +# gcc, clang, icc, Sun/Solaris Studio
    1.15 +CC :=		$(CC) -std=c99
    1.16 +COMPILE.c =	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(TARGET_ARCH) -c
    1.17  # gcc, clang, icc
    1.18 -MAKEDEPEND.c =	$(CC) -MM $(CFLAGS) $(CPPFLAGS)
    1.19 +MAKEDEPEND.c =	$(CC) -MM $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
    1.20  # Sun/Solaris Studio
    1.21 -#MAKEDEPEND.c =	$(CC) -xM1 $(CFLAGS) $(CPPFLAGS)
    1.22 +#MAKEDEPEND.c =	$(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
    1.23  # X makedepend
    1.24 -#MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(CPPFLAGS) --
    1.25 +#MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
    1.26  INSTALL :=	install
    1.27  INSTALL.exec :=	$(INSTALL) -D -m 0755
    1.28  INSTALL.data :=	$(INSTALL) -D -m 0644
    1.29 @@ -72,50 +75,28 @@
    1.30  OS_NAME :=	$(shell uname -s)
    1.31  OS_RELEASE :=	$(shell uname -r)
    1.32  
    1.33 -is_in = $(if $(filter $2, $1),true,false)
    1.34 -
    1.35 -PKGCONFIG_LIBS :=	dbus-1 glib-2.0 libnotify
    1.36 -EXTRA_LIBS :=
    1.37 -
    1.38 -ifeq ($(OS_NAME),Linux)
    1.39 -    OBJS_UTMP :=	xwrited-utmp-utempter.o
    1.40 -    EXTRA_LIBS +=	-lutempter
    1.41 -else ifeq ($(OS_NAME),FreeBSD)
    1.42 -    OBJS_UTMP :=	xwrited-utmp-utempter.o
    1.43 -    FREEBSD_RELEASE_MAJOR := $(firstword $(subst ., ,$(OS_RELEASE)))
    1.44 -    # FreeBSD < 9.0 needs libutempter
    1.45 -    ifeq ($(call is_in, $(OS_RELEASE_MAJOR), 7 8), true)
    1.46 -	EXTRA_LIBS +=	-lutempter
    1.47 -    else
    1.48 -	EXTRA_LIBS +=	-lulog
    1.49 -    endif
    1.50 +ifeq ($(shell pkg-config --exists 'glib-2.0 >= 2.25.5' && printf "true"),true)
    1.51 +  HAVE_GLIB_GDBUS = 1
    1.52  else
    1.53 -    OBJS_UTMP :=	xwrited-utmp-utmpx.o
    1.54 +  HAVE_GLIB_GDBUS = 0
    1.55  endif
    1.56  
    1.57 -ifeq ($(shell pkg-config --exists 'glib-2.0 >= 2.25.5' && printf "true"), true)
    1.58 -    CPPFLAGS_EXTRA :=	-DHAVE_GLIB_GDBUS
    1.59 +PKGCONFIG_LIBS := dbus-1 glib-2.0 libnotify
    1.60 +ifeq ($(HAVE_GLIB_GDBUS),1)
    1.61 +  PKGCONFIG_LIBS +=	dbus-glib-1
    1.62 +endif
    1.63 +OBJS =		main.o xwrited-debug.o xwrited-unique.o
    1.64 +ifneq ($(findstring $(OS_NAME),Linux FreeBSD),)
    1.65 +  OBJS +=	xwrited-utmp-utempter.o
    1.66  else
    1.67 -    PKGCONFIG_LIBS +=	dbus-glib-1
    1.68 +  OBJS +=	xwrited-utmp-utmpx.o
    1.69  endif
    1.70 -
    1.71 -OBJS =		main.o xwrited-debug.o xwrited-unique.o $(OBJS_UTMP)
    1.72  MANPAGES =	data/$(PACKAGE).1
    1.73  AUTOSTART_FILE = data/$(PACKAGE).desktop
    1.74  MOFILES :=	$(patsubst %.po,%.mo,$(wildcard po/*.po))
    1.75  POTFILE =	po/$(PACKAGE).pot
    1.76  POSRCS :=	$(shell $(SED) -e 's/\#.*//' -e '/^[ \t]*$$/d' \
    1.77  		-e 's/^\[[^]]*\]//' po/POTFILES.in | $(PASTE) -s -d ' ')
    1.78 -CPPFLAGS := 	$(CPPFLAGS_EXTRA) \
    1.79 -		$(CPPFLAGS_LIBUTEMPTER) \
    1.80 -		$(shell pkg-config --cflags $(PKGCONFIG_LIBS)) \
    1.81 -		-DPACKAGE="\"$(PACKAGE)\"" \
    1.82 -		-DAPP_NAME=\"$(APP_NAME)\" \
    1.83 -		-DVERSION=\"$(VERSION)\" \
    1.84 -		-DLOCALEDIR="\"$(localedir)\"" \
    1.85 -		-DG_LOG_DOMAIN=\"$(PACKAGE)\"
    1.86 -LDLIBS :=	$(EXTRA_LIBS) \
    1.87 -		$(shell pkg-config --libs $(PKGCONFIG_LIBS))
    1.88  DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \
    1.89  			  --stringparam man.copyright.section.enabled 0
    1.90  
    1.91 @@ -125,6 +106,25 @@
    1.92  
    1.93  all: $(PACKAGE) $(MANPAGES) $(MOFILES) $(AUTOSTART_FILE)
    1.94  
    1.95 +$(PACKAGE): CPPFLAGS :=	$(shell pkg-config --cflags $(PKGCONFIG_LIBS)) \
    1.96 +			-D_XOPEN_SOURCE=600 \
    1.97 +			-DPACKAGE="\"$(PACKAGE)\"" \
    1.98 +			-DAPP_NAME=\"$(APP_NAME)\" \
    1.99 +			-DVERSION=\"$(VERSION)\" \
   1.100 +			-DLOCALEDIR="\"$(localedir)\"" \
   1.101 +			-DG_LOG_DOMAIN=\"$(PACKAGE)\"
   1.102 +$(PACKAGE): LDLIBS :=	$(shell pkg-config --libs $(PKGCONFIG_LIBS))
   1.103 +ifeq ($(HAVE_GLIB_GDBUS),1)
   1.104 +  $(PACKAGE): XCPPFLAGS += -DHAVE_GLIB_GDBUS
   1.105 +endif
   1.106 +ifeq ($(OS_NAME),Linux)
   1.107 +  $(PACKAGE): LDLIBS +=	-lutempter
   1.108 +else ifeq ($(OS_NAME),FreeBSD)
   1.109 +  $(PACKAGE): LDLIBS +=	-lulog
   1.110 +else ifeq ($(OS_NAME),SunOS)
   1.111 +  $(PACKAGE): XCPPFLAGS += -I/usr/xpg4/include
   1.112 +  $(PACKAGE): XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
   1.113 +endif
   1.114  $(PACKAGE): $(OBJS)
   1.115  	$(LINK.o) $^ $(LDLIBS) -o $@
   1.116  
     2.1 --- a/README	Tue Sep 13 20:59:33 2016 +0200
     2.2 +++ b/README	Wed Sep 14 09:46:59 2016 +0200
     2.3 @@ -10,7 +10,7 @@
     2.4  ------------------
     2.5  
     2.6  xwrited requires a POSIX:2004 compatible operating system, it has been tested
     2.7 -to work on Linux distributions, FreeBSD, NetBSD, and Solaris and
     2.8 +to work on Linux distributions, FreeBSD, DragonFly BSD, NetBSD, and Solaris and
     2.9  Illumos-derived distributions.  The following tools and shared libraries are
    2.10  required to build xwrited:
    2.11  
    2.12 @@ -18,7 +18,7 @@
    2.13  - GNU or BSD install
    2.14  - GLib version 2.26 or later
    2.15  - the D-Bus GLib bindings for GLib < 2.25.5
    2.16 -- libutempter on Linux and FreeBSD < 9.0
    2.17 +- libutempter on Linux
    2.18  
    2.19  Rebuilding the man pages additionally requires the xsltproc tool from libxml2.
    2.20  
     3.1 --- a/main.c	Tue Sep 13 20:59:33 2016 +0200
     3.2 +++ b/main.c	Wed Sep 14 09:46:59 2016 +0200
     3.3 @@ -21,8 +21,6 @@
     3.4   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     3.5   */
     3.6  
     3.7 -#define	_XOPEN_SOURCE	600
     3.8 -
     3.9  #include <stdio.h>
    3.10  #include <stdlib.h>
    3.11  #include <string.h>
     4.1 --- a/xwrited-debug.c	Tue Sep 13 20:59:33 2016 +0200
     4.2 +++ b/xwrited-debug.c	Wed Sep 14 09:46:59 2016 +0200
     4.3 @@ -21,8 +21,6 @@
     4.4   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     4.5   */
     4.6  
     4.7 -#define	_XOPEN_SOURCE	600
     4.8 -
     4.9  #include <string.h>
    4.10  #include <stdarg.h>
    4.11  #include <glib.h>
     5.1 --- a/xwrited-unique.c	Tue Sep 13 20:59:33 2016 +0200
     5.2 +++ b/xwrited-unique.c	Wed Sep 14 09:46:59 2016 +0200
     5.3 @@ -21,8 +21,6 @@
     5.4   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     5.5   */
     5.6  
     5.7 -#define	_XOPEN_SOURCE	600
     5.8 -
     5.9  #include <glib.h>
    5.10  #ifdef	HAVE_GLIB_GDBUS
    5.11  #include <gio/gio.h>
     6.1 --- a/xwrited-utmp-utempter.c	Tue Sep 13 20:59:33 2016 +0200
     6.2 +++ b/xwrited-utmp-utempter.c	Wed Sep 14 09:46:59 2016 +0200
     6.3 @@ -21,8 +21,6 @@
     6.4   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     6.5   */
     6.6  
     6.7 -#define	_XOPEN_SOURCE	600
     6.8 -
     6.9  #include <stdlib.h>
    6.10  #include <utempter.h>
    6.11  
     7.1 --- a/xwrited-utmp-utmpx.c	Tue Sep 13 20:59:33 2016 +0200
     7.2 +++ b/xwrited-utmp-utmpx.c	Wed Sep 14 09:46:59 2016 +0200
     7.3 @@ -21,8 +21,6 @@
     7.4   * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     7.5   */
     7.6  
     7.7 -#define	_XOPEN_SOURCE	600
     7.8 -
     7.9  #include <glib.h>
    7.10  #include <stdlib.h>
    7.11  #include <string.h>
    7.12 @@ -32,7 +30,9 @@
    7.13  #include <errno.h>
    7.14  #include <sys/time.h>
    7.15  
    7.16 +#ifndef	DEV_PREFIX
    7.17  #define	DEV_PREFIX	"/dev/"
    7.18 +#endif /* !DEV_PREFIX */
    7.19  
    7.20  static void
    7.21  utmp_write_entry(int fd, gboolean add)