Ensure android/avd/hw-config-defs.h is properly regenerated as needed.

This modifies the emulator's build system to ensure that the file at
android/avd/hw-config-defs.h is regenerated automatically each time that
android/avd/hardware-properties.ini is itself changed.

Tested with both the Android build system, and the standalone one.
diff --git a/Makefile.android b/Makefile.android
index 6a8e3fd..b0d3cea 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -637,6 +637,20 @@
 
 LOCAL_GENERATED_SOURCES += $(QEMU_GDBSTUB_XML_C)
 
+# hw-config-defs.h is generated from android/avd/hardware-properties.ini
+#
+QEMU_HARDWARE_PROPERTIES_INI := android/avd/hardware-properties.ini
+QEMU_HW_CONFIG_DEFS_H := $(LOCAL_PATH)/android/avd/hw-config-defs.h
+$(QEMU_HW_CONFIG_DEFS_H): PRIVATE_PATH := $(LOCAL_PATH)
+$(QEMU_HW_CONFIG_DEFS_H): PRIVATE_SOURCES := $(LOCAL_PATH)/$(QEMU_HARDWARE_PROPERTIES_INI)
+$(QEMU_HW_CONFIG_DEFS_H): PRIVATE_CUSTOM_TOOL = $(PRIVATE_PATH)/android/tools/gen-hw-config.py $(LOCAL_PATH)/$(QEMU_HARDWARE_PROPERTIES_INI) $@
+$(QEMU_HW_CONFIG_DEFS_H): $(LOCAL_PATH)/$(QEMU_HARDWARE_PROPERTIES_INI) $(LOCAL_PATH)/android/tools/gen-hw-config.py
+	$(hide) rm -f $@
+	$(transform-generated-source)
+
+$(LOCAL_PATH)/android/avd/hw-config.h: $(QEMU_HW_CONFIG_DEFS_H)
+
+LOCAL_GENERATED_SOURCES += $(QEMU_HW_CONFIG_DEFS_H)
 
 # this is already done by the Android build system, but is done for the
 # benefit of the stand-alone one.
diff --git a/android/main.c b/android/main.c
index 682cfce..ee1cbdb 100644
--- a/android/main.c
+++ b/android/main.c
@@ -2399,7 +2399,7 @@
     }
 
     /* Check the size of the /data partition. The only interesting cases here are:
-     * - when the USERDATA image already exists and is larger than the deffault
+     * - when the USERDATA image already exists and is larger than the default
      * - when we're wiping data and the INITDATA is larger than the default.
      */
 
diff --git a/android/tools/gen-hw-config.py b/android/tools/gen-hw-config.py
index 928ccc5..3822485 100755
--- a/android/tools/gen-hw-config.py
+++ b/android/tools/gen-hw-config.py
@@ -43,12 +43,17 @@
 targetHeader = """\
 /* this file is automatically generated from 'hardware-properties.ini'
  * DO NOT EDIT IT. To re-generate it, use android/tools/gen-hw-config.py'
- */"""
+ */
+"""
 
 # locate source and target
 programDir = os.path.dirname(sys.argv[0])
-sourceFile = os.path.normpath(os.path.join(programDir,relativeSourcePath))
-targetFile = os.path.normpath(os.path.join(programDir,relativeTargetPath))
+if len(sys.argv) != 3:
+    print "Usage: %s source target\n" % os.path.basename(sys.argv[0])
+    sys.exit(1)
+
+sourceFile = sys.argv[1]
+targetFile = sys.argv[2]
 
 # parse the source file and record items
 # I would love to use Python's ConfigParser, but it doesn't
@@ -94,16 +99,21 @@
 if lastItem:
     items.append(lastItem)
 
+if targetFile == '--':
+    out = sys.stdout
+else:
+    out = open(targetFile,"wb")
 
-print  targetHeader
+out.write(targetHeader)
 
 # write guards to prevent bad compiles
 for m in macroNames:
-    print """\
+    out.write("""\
 #ifndef %(macro)s
 #error  %(macro)s not defined
-#endif""" % { 'macro':m }
-print ""
+#endif
+""" % { 'macro':m })
+out.write("\n")
 
 for item in items:
     if item.type == None:
@@ -131,11 +141,12 @@
         # quote default value for strings
         varDefault = quoteStringForC(varDefault)
 
-    print "%s(\n  %s,\n  %s,\n  %s,\n  %s,\n  %s)\n" % \
-            (varMacro,varName,varNameStr,varDefault,varAbstract,varDesc)
+    out.write("%s(\n  %s,\n  %s,\n  %s,\n  %s,\n  %s)\n\n" % \
+            (varMacro,varName,varNameStr,varDefault,varAbstract,varDesc))
 
 
 for m in macroNames:
-    print "#undef %s" % m
+    out.write("#undef %s\n" % m)
 
-print "/* end of auto-generated file */"
+out.write("/* end of auto-generated file */\n")
+out.close()