Properly install service file

If the service file is included in the yocto meta layer, it can be installed
directly. If it is included in the code source directory, it must be installed
using the build system. This adds the autoconf/automake magic to make this
happen.

Change-Id: I72ba8bb2ec2017b1c47fd6f7de2ee82aad4b8d01
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/Makefile.am b/Makefile.am
index 4fa8796..7e049af 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,3 +15,8 @@
 	-DBOOST_COROUTINES_NO_DEPRECATION_WARNING \
 	-DBOOST_ASIO_DISABLE_THREADS \
 	-DBOOST_ALL_NO_LIB
+
+if HAVE_SYSTEMD
+SYSTEMD_UNIT = phosphor-ipmi-kcs@.service
+systemdsystemunit_DATA = $(SYSTEMD_UNIT)
+endif  # HAVE_SYSTEMD
diff --git a/configure.ac b/configure.ac
index 08994cd..e155e62 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,6 +17,23 @@
 PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
 PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus])
 
+# systemd unit general configuration
+PKG_PROG_PKG_CONFIG
+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"])
+
 # Checks for header files.
 AC_CHECK_HEADER(systemd/sd-bus.h, ,[AC_MSG_ERROR([Could not find systemd/sd-bus.h...systemd development package required])])
 AC_CHECK_HEADER(linux/ipmi_bmc.h,[HAVE_LINUX_IPMI_BMC_H=""],[HAVE_LINUX_IPMI_BMC_H="-I linux/ipmi_bmc.h"])