presence: Install JSON config files from repo

Install the JSON config files for the machine name provided in the
environment variable "MACHINE" into the application's data directory.
When no "MACHINE" name is given, the entire contents of the
`config_files` directory is installed and when a given "MACHINE" named
directory does not exist, the installation is intended to fail. This
failure of installation is to ensure that the fan application's
necessary JSON config files will exist so the fan application does not
fail to start.

Change-Id: I350643cc7378963da39a9c2ebc2a6d9748f04c46
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/configure.ac b/configure.ac
index fca81d5..a23dc37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -102,6 +102,7 @@
     # Use runtime(json) config, otherwise default to compile time(yaml) config
     AM_COND_IF([WANT_JSON],
     [
+        AC_ARG_VAR(MACHINE, [Machine name to install a particular set of associated config file(s)])
         AC_CHECK_HEADER(nlohmann/json.hpp, ,
                 [AC_MSG_ERROR([Could not find nlohmann/json.hpp... nlohmann/json package required])])
         # Set config flag for runtime json usage
diff --git a/presence/Makefile.am b/presence/Makefile.am
index b0b00df..136c6a8 100644
--- a/presence/Makefile.am
+++ b/presence/Makefile.am
@@ -7,6 +7,21 @@
 systemdsystemunit_DATA=
 
 if WANT_JSON
+CONFIGSDIR = "${pkgdatadir}/presence/"
+CONFIGSLOC = "${srcdir}/config_files/$(MACHINE)/"
+
+EXTRA_DIST = $(CONFIGSLOC)
+
+# No $(MACHINE) given results in installing entire config_files contents
+install-data-hook:
+	for config in `cd $(CONFIGSLOC) && find * -type f`; do \
+		$(MKDIR_P) "$(DESTDIR)$(CONFIGSDIR)`dirname $${config}`"; \
+		$(INSTALL_DATA) "$(CONFIGSLOC)$${config}" "$(DESTDIR)$(CONFIGSDIR)`dirname $${config}`"; \
+	done
+
+uninstall-hook:
+	rm -rf "$(DESTDIR)$(CONFIGSDIR)"
+
 systemdsystemunit_DATA += \
 	service_files/json/phosphor-fan-presence-tach@.service
 else