build: split app/test pimgen invocation

Run pimgen twice, once for the application with the real YAML
and once for the testcase with the example YAML so that the
testcase can run and build sucessfully when an alternate YAML
tree is provided.

Move extra interface rule generation from pimgen to a makefile
generating script.

Change-Id: Ib0c01bd2207007b815019232a466fa16889f2005
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/test/.gitignore b/test/.gitignore
index 65c2e9e..1520cd8 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1 +1,2 @@
 phosphor-inventory-test
+xyz
diff --git a/test/Makefile.am b/test/Makefile.am
index 1f6470d..07f8453 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,8 +1,27 @@
+BUILT_SOURCES=generated.cpp extra_ifaces.cpp
+CLEANFILES=$(BUILT_SOURCES)
+
+AM_CPPFLAGS = -iquote$(top_srcdir)
+
 check_PROGRAMS =
 noinst_PROGRAMS = phosphor-inventory-test
+noinst_LTLIBRARIES = libtest.la
 
-phosphor_inventory_test_SOURCES = \
-	test.cpp
-phosphor_inventory_test_LDFLAGS = $(SYSTEMD_LIBS) $(PTHREAD_CFLAGS)
-phosphor_inventory_test_CFLAGS = $(SYSTEMD_CFLAGS)
-phosphor_inventory_test_LDADD = ${top_builddir}/libmanager.la
+extra_yamldir=$(top_srcdir)/example/extra_interfaces.d
+
+phosphor_inventory_test_SOURCES = test.cpp
+phosphor_inventory_test_LDADD = libtest.la
+phosphor_inventory_test_LDFLAGS = $(SDBSUPLUS_LIBS) $(PTHREAD_CFLAGS)
+phosphor_inventory_test_CFLAGS = $(SDBUSPLUS_CFLAGS)
+
+libtest_la_SOURCES = \
+	extra_ifaces.cpp \
+	generated.cpp
+libtest_la_LIBADD = $(top_builddir)/libmanagercommon.la $(SDBUSPLUS_LIBS)
+
+clean-local: clean-extra
+
+generated.cpp:
+	$(AM_V_GEN)$(PYTHON) $(top_srcdir)/pimgen.py -d $(extra_yamldir)/.. -o $(builddir) generate-cpp
+
+-include Makefile.extra
diff --git a/test/Makefile.extra.in b/test/Makefile.extra.in
new file mode 100644
index 0000000..128a178
--- /dev/null
+++ b/test/Makefile.extra.in
@@ -0,0 +1 @@
+# Empty file so that 'configure' attempts to generate Makefile.extra.
diff --git a/test/test.cpp b/test/test.cpp
index 3f39fa9..6ffad51 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -13,15 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "../manager.hpp"
-#include "../config.h"
+#include "manager.hpp"
+#include "config.h"
 #include <cassert>
 #include <iostream>
 #include <algorithm>
 #include <thread>
 #include <chrono>
-#include <xyz/openbmc_project/Example/Iface1/server.hpp>
-#include <xyz/openbmc_project/Example/Iface2/server.hpp>
+#include "xyz/openbmc_project/Example/Iface1/server.hpp"
+#include "xyz/openbmc_project/Example/Iface2/server.hpp"
 
 using namespace std::literals::chrono_literals;
 using namespace std::literals::string_literals;