Revamp the Makefile.
authorAntoine Jacoutot <ajacoutot@bsdfrog.org>
Fri, 15 Aug 2014 18:59:06 +0000 (20:59 +0200)
committerAntoine Jacoutot <ajacoutot@bsdfrog.org>
Fri, 15 Aug 2014 18:59:06 +0000 (20:59 +0200)
Create the service files as part of the build so that they respect BINDIR.

ok Ian

Makefile
conf/conf/org.freedesktop.hostname1.service.in [moved from conf/service-files/org.freedesktop.hostname1.service with 52% similarity]
conf/conf/org.freedesktop.locale1.service.in [moved from conf/service-files/org.freedesktop.locale1.service with 52% similarity]
conf/conf/org.freedesktop.login1.service.in [moved from conf/service-files/org.freedesktop.login1.service with 52% similarity]
conf/conf/org.freedesktop.timedate1.service.in [moved from conf/service-files/org.freedesktop.timedate1.service with 52% similarity]

index 236fd3cdb110ec33a62e41cfdec78aa2a9679d07..d5165a645e60efe593d156c1342cc6c424ff04ea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,42 +1,63 @@
 .PHONY: all
 
-CC=/usr/bin/cc
-CFLAGS=-Wall -Wextra -Werror -std=c89
-DEBUGF=-O0 -g
-
-LINKGN=bin/obj/hostnamed-gen.o bin/obj/localed-gen.o bin/obj/timedated-gen.o bin/obj/logind-gen.o
-LINKHN=bin/systemd-hostnamed bin/systemd-localed bin/systemd-timedated bin/systemd-logind
+CC?=           /usr/bin/cc
+CFLAGS+=       -Wall -Wextra -Werror -std=c89
+
+DEBUG=         1
+.ifdef DEBUG
+CFLAGS+=       -O0 -g
+.endif
+
+SANITY=                1
+.ifdef SANITY
+CFLAGS+=       -Wno-unused-variable -Wno-unused-parameter # -Wno-comment
+.endif
+
+PREFIX?=       /usr/local
+BINDIR=                $(PREFIX)/libexec
+SYSCONFDIR?=   /etc
+
+INSTALL_PROGRAM=       install -c -s -o root -g bin -m 555
+INSTALL_PROGRAM_DIR=   install -d -o root -g bin -m 755
+INSTALL_DATA=          install -c -o root -g bin -m 444
+INSTALL_DATA_DIR=      install -d -o root -g bin -m 755
+
+LINKGN=                bin/obj/hostnamed-gen.o \
+               bin/obj/localed-gen.o \
+               bin/obj/timedated-gen.o \
+               bin/obj/logind-gen.o
+
+LINKHN=                bin/systemd-hostnamed \
+               bin/systemd-localed \
+               bin/systemd-timedated \
+               bin/systemd-logind
+
+DBUS_SERVICES= org.freedesktop.hostname1.service \
+               org.freedesktop.locale1.service \
+               org.freedesktop.login1.service \
+               org.freedesktop.timedate1.service
 
 GLIBEF=`pkg-config --cflags --libs glib-2.0 gobject-2.0 gio-2.0 gio-unix-2.0 polkit-agent-1`
 GLIBOF=`pkg-config --cflags        glib-2.0 gobject-2.0 gio-2.0 gio-unix-2.0 polkit-agent-1`
 
-SANITY=-Wno-unused-variable -Wno-unused-parameter # -Wno-comment
-
-PREFIX=/usr/local
-LIBDIR=$(PREFIX)/lib
-OUR_LIBDIR=$(LIBDIR)/systemd-compat
-SYSCONFDIR=/etc
+SRCDIR=                src
+CONFDIR=       conf
+POLICYDIR=     $(CONFDIR)/sysbus-policy
+ISPECTDIR=     $(CONFDIR)/introspect-xml
+SERVICEFDIR=   $(CONFDIR)/service-files
 
-SRCDIR=src
-CONFDIR=conf
-POLICYDIR=$(CONFDIR)/sysbus-policy
-ISPECTDIR=$(CONFDIR)/introspect-xml
-SERVICEFDIR=$(CONFDIR)/service-files
+INTFDIR=       $(SRCDIR)/interfaces
 
-INTFDIR=$(SRCDIR)/interfaces
+DBUS_POLICYDIR=        $(SYSCONFDIR)/dbus-1/system.d
+DBUS_CONFIGDIR=        $(PREFIX)/share/dbus-1/system-services
 
-DBUS_POLICYDIR=$(SYSCONFDIR)/dbus-1/system.d
-DBUS_CONFIGDIR=$(PREFIX)/share/dbus-1/system-services
-
-INVOKE_GENFILE_SCRIPT=./scripts/gen-gdbus-interfaces.sh 
+INVOKE_GENFILE_SCRIPT= \
+               ./scripts/gen-gdbus-interfaces.sh 
 
 all: build
 
-build: _build_interface_objs_debug 
-       $(CC) -o bin/out.bin $(DEBUGF) $(GLIBEF) $(SANITY) $(SRCDIR)/main.c
-
-publish: _build_interface_objs 
-       $(CC) -o bin/out.bin $(CFLAGS) $(GLIBEF) $(SANITY) $(SRCDIR)/main.c
+build: _build_interface_objs
+       $(CC) -o bin/out.bin $(CFLAGS) $(GLIBEF) $(SRCDIR)/main.c
 
 clean:
        find ./bin -type f -exec rm {} \;
@@ -45,28 +66,16 @@ clean:
 install: _install_conf _install_interface_binaries
 
 _build_interface_objs: _build_genfile_objs
-       $(CC) -o bin/systemd-hostnamed $(CFLAGS) $(GLIBEF) $(SANITY) $(INTFDIR)/hostnamed/hostnamed.c bin/obj/hostnamed-gen.o 
-       $(CC) -o bin/systemd-localed   $(CFLAGS) $(GLIBEF) $(SANITY) $(INTFDIR)/localed/localed.c     bin/obj/localed-gen.o
-       $(CC) -o bin/systemd-timedated $(CFLAGS) $(GLIBEF) $(SANITY) $(INTFDIR)/timedated/timedated.c bin/obj/timedated-gen.o
-       $(CC) -o bin/systemd-logind    $(CFLAGS) $(GLIBEF) $(SANITY) $(INTFDIR)/logind/logind.c       bin/obj/logind-gen.o
-
-_build_interface_objs_debug: _build_genfile_objs_debug
-       $(CC) -o bin/systemd-hostnamed $(DEBUGF) $(GLIBEF) $(SANITY) $(INTFDIR)/hostnamed/hostnamed.c bin/obj/hostnamed-gen.o  
-       $(CC) -o bin/systemd-localed   $(DEBUGF) $(GLIBEF) $(SANITY) $(INTFDIR)/localed/localed.c     bin/obj/localed-gen.o
-       $(CC) -o bin/systemd-timedated $(DEBUGF) $(GLIBEF) $(SANITY) $(INTFDIR)/timedated/timedated.c bin/obj/timedated-gen.o
-       $(CC) -o bin/systemd-logind    $(DEBUGF) $(GLIBEF) $(SANITY) $(INTFDIR)/logind/logind.c       bin/obj/logind-gen.o
+       $(CC) -o bin/systemd-hostnamed $(CFLAGS) $(GLIBEF) $(INTFDIR)/hostnamed/hostnamed.c bin/obj/hostnamed-gen.o 
+       $(CC) -o bin/systemd-localed   $(CFLAGS) $(GLIBEF) $(INTFDIR)/localed/localed.c     bin/obj/localed-gen.o
+       $(CC) -o bin/systemd-timedated $(CFLAGS) $(GLIBEF) $(INTFDIR)/timedated/timedated.c bin/obj/timedated-gen.o
+       $(CC) -o bin/systemd-logind    $(CFLAGS) $(GLIBEF) $(INTFDIR)/logind/logind.c       bin/obj/logind-gen.o
 
 _build_genfile_objs: _generate_genfiles
-       $(CC) -o bin/obj/hostnamed-gen.o $(CFLAGS) $(GLIBOF) $(SANITY) -c $(INTFDIR)/hostnamed/hostnamed-gen.c
-       $(CC) -o bin/obj/localed-gen.o   $(CFLAGS) $(GLIBOF) $(SANITY) -c $(INTFDIR)/localed/localed-gen.c
-       $(CC) -o bin/obj/timedated-gen.o $(CFLAGS) $(GLIBOF) $(SANITY) -c $(INTFDIR)/timedated/timedated-gen.c
-       $(CC) -o bin/obj/logind-gen.o    $(CFLAGS) $(GLIBOF) $(SANITY) -c $(INTFDIR)/logind/logind-gen.c
-
-_build_genfile_objs_debug: _generate_genfiles
-       $(CC) -o bin/obj/hostnamed-gen.o $(DEBUGF) $(GLIBOF) $(SANITY) -c $(INTFDIR)/hostnamed/hostnamed-gen.c
-       $(CC) -o bin/obj/localed-gen.o   $(DEBUGF) $(GLIBOF) $(SANITY) -c $(INTFDIR)/localed/localed-gen.c
-       $(CC) -o bin/obj/timedated-gen.o $(DEBUGF) $(GLIBOF) $(SANITY) -c $(INTFDIR)/timedated/timedated-gen.c
-       $(CC) -o bin/obj/logind-gen.o    $(DEBUGF) $(GLIBOF) $(SANITY) -c $(INTFDIR)/logind/logind-gen.c
+       $(CC) -o bin/obj/hostnamed-gen.o $(CFLAGS) $(GLIBOF) -c $(INTFDIR)/hostnamed/hostnamed-gen.c
+       $(CC) -o bin/obj/localed-gen.o   $(CFLAGS) $(GLIBOF) -c $(INTFDIR)/localed/localed-gen.c
+       $(CC) -o bin/obj/timedated-gen.o $(CFLAGS) $(GLIBOF) -c $(INTFDIR)/timedated/timedated-gen.c
+       $(CC) -o bin/obj/logind-gen.o    $(CFLAGS) $(GLIBOF) -c $(INTFDIR)/logind/logind-gen.c
 
 _generate_genfiles:
        $(INVOKE_GENFILE_SCRIPT) hostnamed
@@ -74,11 +83,19 @@ _generate_genfiles:
        $(INVOKE_GENFILE_SCRIPT) timedated
        $(INVOKE_GENFILE_SCRIPT) logind
 
-_install_conf:
-       cp $(POLICYDIR)/*-dbus.conf       $(DBUS_POLICYDIR)/
-       cp $(SERVICEFDIR)/*.service       $(DBUS_CONFIGDIR)/
-       cp $(CONFDIR)/systemd_compat.conf $(SYSCONFDIR)/
+_generate_servicefiles:
+       for svc in $(DBUS_SERVICES); do \
+               sed -e 's,@BINDIR@,${BINDIR},' $(SERVICEFDIR)/$$svc.in > $(SERVICEFDIR)/$$svc; \
+       done
+
+_install_conf: _generate_servicefiles
+       ${INSTALL_DATA_DIR} $(DESTDIR)$(DBUS_POLICYDIR)
+       ${INSTALL_DATA_DIR} $(DESTDIR)$(DBUS_CONFIGDIR)
+       ${INSTALL_DATA_DIR} $(DESTDIR)$(SYSCONFDIR)
+       ${INSTALL_DATA} $(POLICYDIR)/*-dbus.conf $(DESTDIR)$(DBUS_POLICYDIR)/
+       ${INSTALL_DATA} $(SERVICEFDIR)/*.service $(DESTDIR)$(DBUS_CONFIGDIR)/
+       ${INSTALL_DATA} $(CONFDIR)/systemd_compat.conf $(DESTDIR)$(SYSCONFDIR)/
 
 _install_interface_binaries: $(LINKHN)
-       mkdir -p $(OUR_LIBDIR)
-       cp bin/systemd-* $(OUR_LIBDIR)/ 
+       ${INSTALL_PROGRAM_DIR} $(DESTDIR)$(BINDIR)
+       ${INSTALL_PROGRAM} bin/systemd-* $(DESTDIR)$(BINDIR)/ 
similarity index 52%
rename from conf/service-files/org.freedesktop.hostname1.service
rename to conf/conf/org.freedesktop.hostname1.service.in
index 4ab56a7b6ca443a870acc4e03540011d8b899f7f..0d3abf0618f84ea65470818c131537862a8d702d 100644 (file)
@@ -1,4 +1,4 @@
 [D-BUS Service]
 Names=org.freedesktop.hostname1i
-Exec=/usr/local/bin/systemd-compat/systemd-hostnamed
+Exec=@BINDIR@/systemd-hostnamed
 User=root
similarity index 52%
rename from conf/service-files/org.freedesktop.locale1.service
rename to conf/conf/org.freedesktop.locale1.service.in
index b85f8b91d9ed137cabc7103fe6c880821ef9e2bc..25b39f7cfc7c52704467c5ac7b2ccb5138081954 100644 (file)
@@ -1,4 +1,4 @@
 [D-BUS Service]
 Names=org.freedesktop.locale1
-Exec=/usr/local/bin/systemd-compat/systemd-localed
+Exec=@BINDIR@/systemd-localed
 User=root
similarity index 52%
rename from conf/service-files/org.freedesktop.login1.service
rename to conf/conf/org.freedesktop.login1.service.in
index 834f17b49cf90e2ee772e64d39299df3142da5d9..fac4a3aecdff62f164b874df425615264aeec08a 100644 (file)
@@ -1,4 +1,4 @@
 [D-BUS Service]
 Names=org.freedesktop.login1
-Exec=/usr/local/bin/systemd-compat/systemd-logind
+Exec=@BINDIR@/systemd-logind
 User=root
similarity index 52%
rename from conf/service-files/org.freedesktop.timedate1.service
rename to conf/conf/org.freedesktop.timedate1.service.in
index 096d622943b3e6429198513b0ec660a2b9cacb55..29cfea68c95523f67bc358aaf6a47ca5c5a7afb2 100644 (file)
@@ -1,4 +1,4 @@
 [D-BUS Service]
 Names=org.freedesktop.timedate1
-Exec=/usr/local/bin/systemd-compat/systemd-timedated
+Exec=@BINDIR@/systemd-timedated
 User=root