build: enable systemd system units
Enable the systemd system unit for the psu reset target
in the configuration and Makefile for this daemon instead of storing it
in the recipe, per the daemon(7) manpage guidelines.
Change-Id: I565b10619ae0250845b6a10f6fce73b018b494f7
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/Makefile.am b/Makefile.am
index 5b2db07..1559188 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,10 @@
AM_DEFAULT_SOURCE_EXT = .cpp
+if HAVE_SYSTEMD
+systemdsystemunit_DATA = \
+ gbmc-psu-hardreset.target
+endif
+
libsyscmdsdir = ${libdir}/ipmid-providers
libsyscmds_LTLIBRARIES = libsyscmds.la
libsyscmds_la_SOURCES = main.cpp cable.cpp cpld.cpp eth.cpp psu.cpp
diff --git a/configure.ac b/configure.ac
index bb81787..606ec17 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,6 +27,22 @@
# Checks for library functions.
LT_INIT # Required for systemd linking
+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"])
+
# Create configured output
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
diff --git a/gbmc-psu-hardreset.target b/gbmc-psu-hardreset.target
new file mode 100644
index 0000000..60f70a5
--- /dev/null
+++ b/gbmc-psu-hardreset.target
@@ -0,0 +1,2 @@
+[Unit]
+Description=Sys PSU Hard Reset