Install systemd services with autotools

Change-Id: Ie4c7e81495181059d1dff1c194d52d11fb72ed03
diff --git a/configure.ac b/configure.ac
index 7288c24..90394e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -157,6 +157,22 @@
 STD_DEFINES_AND_INCLUDES="-Wall"
 AC_SUBST(STD_DEFINES_AND_INCLUDES)
 
+# 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([CPPFLAGS="$CPPFLAGS"])
 AC_MSG_RESULT([CFLAGS="$CFLAGS"])
 AC_MSG_RESULT([CXXFLAGS="$CXXFLAGS"])
@@ -168,4 +184,6 @@
     src/Makefile
     examples/Makefile
     tests/Makefile
+    contrib/Makefile
+    contrib/systemd/Makefile
     Makefile)