From 1d65f6617fc0e02a4b0569c932485bfc798994f3 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Sat, 22 May 2021 07:22:57 +0200 Subject: [PATCH] Proper systemd support Follow the directions on integrating systemd with autotools provided by the systemd documentation itself: https://www.freedesktop.org/software/systemd/man/daemon.html#Installing%20systemd%20Service%20Files The snippet has been adapted to better match our coding style, e.g. directly use of `if` instead of `AS_IF`. --- Makefile.am | 3 +++ configure.ac | 30 ++++++++++++++++++++++++++++++ script/Makefile.am | 7 ++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 8a8a8fcd..288f86ed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,6 +29,9 @@ ACLOCAL_AMFLAGS = -I m4 +AM_DISTCHECK_CONFIGURE_FLAGS = \ + --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) + SUBDIRS = \ include \ script diff --git a/configure.ac b/configure.ac index e9517115..b19992cf 100644 --- a/configure.ac +++ b/configure.ac @@ -45,6 +45,7 @@ AM_INIT_AUTOMAKE([-Wall -Werror dist-bzip2 subdir-objects]) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_SRCDIR([config.h.in]) AC_CONFIG_MACRO_DIR([m4]) +PKG_PROG_PKG_CONFIG PKG_INSTALLDIR() #------------------------------------------------------------------------------ @@ -1078,6 +1079,35 @@ else AC_MSG_RESULT([no]) fi +#------------------------------------------------------------------------------ +# systemd service support +#------------------------------------------------------------------------------ + +AC_ARG_WITH([systemdsystemunitdir], + AS_HELP_STRING([--with-systemdsystemunitdir=DIR], + [Directory for systemd service files]), + , + [with_systemdsystemunitdir=auto] +) + +case "${with_systemdsystemunitdir}" in + yes) + with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd) + if test "x$with_systemdsystemunitdir" = "x"; then + AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package]) + fi + ;; + no) + with_systemdsystemunitdir= + ;; + auto) + with_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd) + ;; +esac + +AM_CONDITIONAL(HAVE_SYSTEMD, test "x$with_systemdsystemunitdir" != "x") +AC_SUBST(systemdsystemunitdir,[$with_systemdsystemunitdir]) + #------------------------------------------------------------------------------ AC_CONFIG_FILES([ diff --git a/script/Makefile.am b/script/Makefile.am index 419a024f..b3483f15 100644 --- a/script/Makefile.am +++ b/script/Makefile.am @@ -35,9 +35,6 @@ SUBDIRS = init.d sysconfig sbin_SCRIPTS = ethercatctl -systemddir = $(libdir)/systemd/system -systemd_DATA = ethercat.service - dist_sysconf_DATA = ethercat.conf EXTRA_DIST = \ @@ -49,4 +46,8 @@ BUILT_SOURCES = \ ethercatctl \ ethercat.service +if HAVE_SYSTEMD +systemdsystemunit_DATA = ethercat.service +endif + #------------------------------------------------------------------------------