Fix dependencies on auto-generated code

The sensor/entity/fru/inventory auto-generated cpp code should
depend on the mako template, the generator python, and the yaml
that it is built with. This modifies the autoconf to export the yaml
and the automake to set the dependencies.

Tested-by: modify one of the dependencies and watch it get rebuilt

Change-Id: Iaab9585c202baf4506e0b7e62aa42a3bf2828ae4
Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
diff --git a/Makefile.am b/Makefile.am
index 864eb93..e7a35a8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -70,16 +70,16 @@
 ipmiwhitelist.cpp: ${srcdir}/generate_whitelist.sh $(WHITELIST_CONF)
 	$(SHELL) $^ > $@
 
-sensor-gen.cpp:
+sensor-gen.cpp: scripts/writesensor.mako.cpp scripts/sensor_gen.py @SENSOR_YAML_GEN@
 	$(AM_V_GEN)@SENSORGEN@ -o $(top_builddir) generate-cpp
 
-inventory-sensor-gen.cpp:
+inventory-sensor-gen.cpp: scripts/inventorysensor.mako.cpp scripts/inventory-sensor.py @INVSENSOR_YAML_GEN@
 	$(AM_V_GEN)@INVSENSORGEN@ -o $(top_builddir) generate-cpp
 
-fru-read-gen.cpp:
+fru-read-gen.cpp: scripts/readfru.mako.cpp scripts/fru_gen.py @FRU_YAML_GEN@
 	$(AM_V_GEN)@FRUGEN@ -o $(top_builddir) generate-cpp
 
-entity-gen.cpp:
+entity-gen.cpp: scripts/writeentity.mako.cpp scripts/entity_gen.py @ENTITY_YAML_GEN@
 	$(AM_V_GEN)@ENTITYGEN@ -o $(top_builddir) generate-cpp
 
 providers_LTLIBRARIES += libipmi20.la
diff --git a/configure.ac b/configure.ac
index 2bb011f..8020fbd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,20 +103,24 @@
         WHITELIST_CONF=${srcdir}/host-ipmid-whitelist.conf
 fi
 
-AS_IF([test "x$SENSOR_YAML_GEN" == "x"], [SENSOR_YAML_GEN="sensor-example.yaml"])
+AS_IF([test "x$SENSOR_YAML_GEN" == "x"], [SENSOR_YAML_GEN="scripts/sensor-example.yaml"])
 SENSORGEN="$PYTHON ${srcdir}/scripts/sensor_gen.py -i $SENSOR_YAML_GEN"
+AC_SUBST(SENSOR_YAML_GEN)
 AC_SUBST(SENSORGEN)
 
-AS_IF([test "x$INVSENSOR_YAML_GEN" == "x"], [INVSENSOR_YAML_GEN="inventory-sensor-example.yaml"])
+AS_IF([test "x$INVSENSOR_YAML_GEN" == "x"], [INVSENSOR_YAML_GEN="scripts/inventory-sensor-example.yaml"])
 INVSENSORGEN="$PYTHON ${srcdir}/scripts/inventory-sensor.py -i $INVSENSOR_YAML_GEN"
+AC_SUBST(INVSENSOR_YAML_GEN)
 AC_SUBST(INVSENSORGEN)
 
-AS_IF([test "x$FRU_YAML_GEN" == "x"], [FRU_YAML_GEN="fru-read-example.yaml"])
+AS_IF([test "x$FRU_YAML_GEN" == "x"], [FRU_YAML_GEN="scripts/fru-read-example.yaml"])
 FRUGEN="$PYTHON $srcdir/scripts/fru_gen.py -i $FRU_YAML_GEN"
+AC_SUBST(FRU_YAML_GEN)
 AC_SUBST(FRUGEN)
 
-AS_IF([test "x$ENTITY_YAML_GEN" == "x"], [ENTITY_YAML_GEN="entity-example.yaml"])
+AS_IF([test "x$ENTITY_YAML_GEN" == "x"], [ENTITY_YAML_GEN="scripts/entity-example.yaml"])
 ENTITYGEN="$PYTHON $srcdir/scripts/entity_gen.py -i $ENTITY_YAML_GEN"
+AC_SUBST(ENTITY_YAML_GEN)
 AC_SUBST(ENTITYGEN)
 
 AC_DEFINE(CALLOUT_FWD_ASSOCIATION, "callout", [The name of the callout's forward association.])
diff --git a/scripts/entity_gen.py b/scripts/entity_gen.py
index 057821b..b558a44 100755
--- a/scripts/entity_gen.py
+++ b/scripts/entity_gen.py
@@ -8,7 +8,7 @@
 
 
 def generate_cpp(entity_yaml, output_dir):
-    with open(os.path.join(script_dir, entity_yaml), 'r') as f:
+    with open(entity_yaml, 'r') as f:
         ifile = yaml.safe_load(f)
         if not isinstance(ifile, dict):
             ifile = {}
@@ -48,7 +48,7 @@
 
     args = parser.parse_args()
 
-    if (not (os.path.isfile(os.path.join(script_dir, args.entity_yaml)))):
+    if (not (os.path.isfile(args.entity_yaml))):
         sys.exit("Can not find input yaml file " + args.entity_yaml)
 
     function = valid_commands[args.command]
diff --git a/scripts/fru_gen.py b/scripts/fru_gen.py
index f6111b7..a8d148a 100755
--- a/scripts/fru_gen.py
+++ b/scripts/fru_gen.py
@@ -8,7 +8,7 @@
 
 
 def generate_cpp(inventory_yaml, output_dir):
-    with open(os.path.join(script_dir, inventory_yaml), 'r') as f:
+    with open(inventory_yaml, 'r') as f:
         ifile = yaml.safe_load(f)
         if not isinstance(ifile, dict):
             ifile = {}
@@ -48,7 +48,7 @@
 
     args = parser.parse_args()
 
-    if (not (os.path.isfile(os.path.join(script_dir, args.inventory_yaml)))):
+    if (not (os.path.isfile(args.inventory_yaml))):
         sys.exit("Can not find input yaml file " + args.inventory_yaml)
 
     function = valid_commands[args.command]
diff --git a/scripts/inventory-sensor.py b/scripts/inventory-sensor.py
index 77222f5..2dd1e8d 100755
--- a/scripts/inventory-sensor.py
+++ b/scripts/inventory-sensor.py
@@ -8,7 +8,7 @@
 
 
 def generate_cpp(sensor_yaml, output_dir):
-    with open(os.path.join(script_dir, sensor_yaml), 'r') as f:
+    with open(sensor_yaml, 'r') as f:
         ifile = yaml.safe_load(f)
         if not isinstance(ifile, dict):
             ifile = {}
@@ -48,7 +48,7 @@
 
     args = parser.parse_args()
 
-    if (not (os.path.isfile(os.path.join(script_dir, args.sensor_yaml)))):
+    if (not (os.path.isfile(args.sensor_yaml))):
         sys.exit("Can not find input yaml file " + args.sensor_yaml)
 
     function = valid_commands[args.command]
diff --git a/scripts/sensor_gen.py b/scripts/sensor_gen.py
index 822a00a..6f59021 100755
--- a/scripts/sensor_gen.py
+++ b/scripts/sensor_gen.py
@@ -8,7 +8,7 @@
 
 
 def generate_cpp(sensor_yaml, output_dir):
-    with open(os.path.join(script_dir, sensor_yaml), 'r') as f:
+    with open(sensor_yaml, 'r') as f:
         ifile = yaml.safe_load(f)
         if not isinstance(ifile, dict):
             ifile = {}
@@ -48,7 +48,7 @@
 
     args = parser.parse_args()
 
-    if (not (os.path.isfile(os.path.join(script_dir, args.sensor_yaml)))):
+    if (not (os.path.isfile(args.sensor_yaml))):
         sys.exit("Can not find input yaml file " + args.sensor_yaml)
 
     function = valid_commands[args.command]