presence: build: Add yaml file to generated deps

Makefile updates such that updates to the YAML file result
in a retrigger of the python script.

Change-Id: I83b637f71dc380a56be0fd40390176d3b201b29a
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/configure.ac b/configure.ac
index 4958bc2..382cb72 100644
--- a/configure.ac
+++ b/configure.ac
@@ -71,12 +71,12 @@
        AC_ARG_VAR(FAN_DETECT_YAML_FILE,
                   [The fan presence detection definition file to use])
        AS_IF([test "x$FAN_DETECT_YAML_FILE" == "x"],
-             [FAN_DETECT_YAML_FILE="${srcdir}/presence/example/fan-detect.yaml"])
+             [FAN_DETECT_YAML_FILE="\${top_srcdir}/presence/example/fan-detect.yaml"])
        AC_DEFINE_UNQUOTED([FAN_DETECT_YAML_FILE], ["$FAN_DETECT_YAML_FILE"],
                           [The fan presence detection definition file to use])
 
        AC_SUBST([GEN_FAN_DETECT_DEFS],
-                [$PYTHON ${srcdir}/presence/gen-fan-detect-defs.py -y $FAN_DETECT_YAML_FILE])
+                ["$PYTHON \${top_srcdir}/presence/gen-fan-detect-defs.py -y $FAN_DETECT_YAML_FILE"])
        AC_CONFIG_FILES([presence/Makefile])
        ])
 
diff --git a/presence/Makefile.am b/presence/Makefile.am
index 10a7363..b56ed4e 100644
--- a/presence/Makefile.am
+++ b/presence/Makefile.am
@@ -21,5 +21,5 @@
 
 BUILT_SOURCES = fan_detect_defs.cpp
 
-fan_detect_defs.cpp: ${srcdir}/gen-fan-detect-defs.py
-	$(AM_V_GEN)$(GEN_FAN_DETECT_DEFS) > $@
+fan_detect_defs.cpp: ${srcdir}/gen-fan-detect-defs.py $(FAN_DETECT_YAML_FILE)
+	$(AM_V_GEN)$(GEN_FAN_DETECT_DEFS) > $(builddir)/$@
diff --git a/presence/gen-fan-detect-defs.py b/presence/gen-fan-detect-defs.py
index 1bc980a..842bbeb 100755
--- a/presence/gen-fan-detect-defs.py
+++ b/presence/gen-fan-detect-defs.py
@@ -37,16 +37,6 @@
 '''
 
 
-def get_filename():
-    """
-    Constructs and returns the fully qualified header filename.
-    """
-    script_dir = os.path.dirname(os.path.abspath(__file__))
-    header_file = os.path.join(script_dir, "fan_detect_defs.cpp")
-
-    return header_file
-
-
 if __name__ == '__main__':
     parser = ArgumentParser()
     # Input yaml containing how each fan's presence detection should be done
@@ -66,7 +56,4 @@
     with open(yaml_file, 'r') as yaml_input:
         presence_data = yaml.safe_load(yaml_input) or {}
 
-    output_file = get_filename()
-
-    with open(output_file, 'w') as out:
-        out.write(Template(tmpl).render(presence=presence_data))
+    sys.stdout.write(Template(tmpl).render(presence=presence_data))