Install systemd services with autotools
Change-Id: I7e4dae6b8c1685e8a673c58a843c41fa0af1b35c
diff --git a/Makefile.am b/Makefile.am
index 3270e4f..1497f80 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,6 +24,9 @@
BUILT_SOURCES = $(top_srcdir)/.version
EXTRA_DIST = git-version-gen osmoappdesc.py .version
+DISTCHECK_CONFIGURE_FLAGS = \
+ --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
+
@RELMAKE@
$(top_srcdir)/.version:
diff --git a/configure.ac b/configure.ac
index 9f021df..3e6581d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,6 +128,22 @@
AC_MSG_RESULT([$enable_ext_tests])
AM_CONDITIONAL(ENABLE_EXT_TESTS, test "x$enable_ext_tests" = "xyes")
+# https://www.freedesktop.org/software/systemd/man/daemon.html
+AC_ARG_WITH([systemdsystemunitdir],
+ [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
+ [with_systemdsystemunitdir=auto])
+AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
+ def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
+
+ AS_IF([test "x$def_systemdsystemunitdir" = "x"],
+ [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
+ [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
+ with_systemdsystemunitdir=no],
+ [with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
+AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
+ [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
+AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
+
AC_MSG_RESULT([CFLAGS="$CFLAGS"])
AC_MSG_RESULT([CPPFLAGS="$CPPFLAGS"])
@@ -151,4 +167,5 @@
doc/Makefile
doc/examples/Makefile
contrib/Makefile
+ contrib/systemd/Makefile
Makefile)
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index db6d0f5..ab410c7 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -1 +1,3 @@
+SUBDIRS = systemd
+
EXTRA_DIST = ipa.py
diff --git a/contrib/systemd/Makefile.am b/contrib/systemd/Makefile.am
new file mode 100644
index 0000000..c0d95ff
--- /dev/null
+++ b/contrib/systemd/Makefile.am
@@ -0,0 +1,5 @@
+if HAVE_SYSTEMD
+EXTRA_DIST = osmo-mgw.service
+systemdsystemunit_DATA = \
+ osmo-mgw.service
+endif
diff --git a/debian/osmo-mgw.install b/debian/osmo-mgw.install
index 39f7c01..ad3d3c6 100644
--- a/debian/osmo-mgw.install
+++ b/debian/osmo-mgw.install
@@ -1,2 +1,3 @@
+lib/systemd/system/osmo-mgw.service
usr/bin/osmo-mgw
usr/share/doc/osmo-mgw/examples/osmo-mgw/osmo-mgw.cfg
diff --git a/debian/osmo-mgw.service b/debian/osmo-mgw.service
deleted file mode 120000
index 1e0664c..0000000
--- a/debian/osmo-mgw.service
+++ /dev/null
@@ -1 +0,0 @@
-../contrib/systemd/osmo-mgw.service
\ No newline at end of file
diff --git a/debian/rules b/debian/rules
index d13e426..d67243c 100755
--- a/debian/rules
+++ b/debian/rules
@@ -14,7 +14,7 @@
# main packaging script based on dh7 syntax
%:
- dh $@ --with autoreconf
+ dh $@ --with autoreconf
# debmake generated override targets
# Set options for ./configure
@@ -29,4 +29,7 @@
override_dh_auto_test:
dh_auto_test || (find . -name testsuite.log -exec cat {} \; ; false)
+override_dh_auto_configure:
+ dh_auto_configure -- --with-systemdsystemunitdir=/lib/systemd/system
+
# See https://www.debian.org/doc/manuals/developers-reference/best-pkging-practices.html#bpp-dbg