Conditional compilation of procedures

Only compile in the procedures for chips specified
during configure.

Change-Id: Ie069f472b86bfbe8ad5d00bc6db8def573f86b4b
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/.gitignore b/.gitignore
index 3cfe4c1..7168564 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
 openpower-proc-control
+openpower_procedures.cpp
+Makefile.generated
 *.o
 *.lo
 *.la
diff --git a/Makefile.am b/Makefile.am
index 6f785bc..942b5d7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,10 +9,13 @@
 	filedescriptor.cpp \
 	registration.cpp \
 	targeting.cpp \
-	procedures/p9/start_host.cpp \
-	procedures/p9/vcs_workaround.cpp
+	openpower_procedures.cpp
+
+CLEANFILES = openpower_procedures.cpp
 
 openpower_proc_control_LDFLAGS = $(PHOSPHOR_LOGGING_LIBS) -lstdc++fs
 openpower_proc_control_CXXFLAGS = $(PHOSPHOR_LOGGING_CFLAGS)
 
 SUBDIRS = test
+
+-include Makefile.generated
diff --git a/Makefile.generated.in b/Makefile.generated.in
new file mode 100644
index 0000000..0aad258
--- /dev/null
+++ b/Makefile.generated.in
@@ -0,0 +1 @@
+#Empty file so that 'configure' attempts to generate Makefile.generated.
diff --git a/configure.ac b/configure.ac
index b0b9e85..b5a14ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,14 @@
     AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
 )
 
+#CHIPS can be passed in a from a recipe, or it will default to P9
+AC_ARG_VAR(CHIPS, [The list of chips to build the procedures for])
+AS_IF([test "x$CHIPS" == "x"], [CHIPS="p9"])
+
+AC_CONFIG_FILES([Makefile.generated],
+    [${srcdir}/gen_makefile.sh "$myChips" > Makefile.generated],
+    [myChips="$CHIPS"])
+
 PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging],, [AC_MSG_ERROR([Could not find phosphor-logging...openbmc/phosphor-logging package required])])
 
 AC_CONFIG_FILES([Makefile test/Makefile])
diff --git a/gen_makefile.sh b/gen_makefile.sh
new file mode 100755
index 0000000..a6fc076
--- /dev/null
+++ b/gen_makefile.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+files=()
+echo "openpower_procedures_cpp_files = \\"
+for type in "$@";
+do
+    type=${type// /} #remove spaces
+    for file in $(ls procedures/$type/*.cpp);
+    do
+        files+=($file)
+    done
+done
+
+for file in ${files[@]};
+do
+    echo "	$file \\"
+done
+echo
+
+cat << MAKEFILE
+openpower_procedures.cpp: \$(openpower_procedures_cpp_files)
+	cat \$^ > \$@
+
+MAKEFILE