layers: Add output file option to vk-generate scripts.

With some build systems, it's not easy to pipe stdout into a file.
This solution allows the scripts to use the last argument as an
output file option. This is a problem in partiuclar for GN.
diff --git a/vk-generate.py b/vk-generate.py
index a1a7165..c740494 100755
--- a/vk-generate.py
+++ b/vk-generate.py
@@ -35,9 +35,14 @@
         self.argv = argv
         self.headers = vulkan.headers
         self.protos = vulkan.protos
+        self.outfile = None
 
     def run(self):
-        print(self.generate())
+        if self.outfile:
+            with open(self.outfile, "w") as outfile:
+                outfile.write(self.generate())
+        else:
+            print(self.generate())
 
     def generate(self):
         copyright = self.generate_copyright()
@@ -91,11 +96,19 @@
 
 class DispatchTableOpsSubcommand(Subcommand):
     def run(self):
-        if len(self.argv) != 1:
+        if len(self.argv) < 1:
             print("DispatchTableOpsSubcommand: <prefix> unspecified")
             return
 
         self.prefix = self.argv[0]
+
+        if len(self.argv) > 2:
+            print("DispatchTableOpsSubcommand: <prefix> [outfile]")
+            return
+
+        if len(self.argv) == 2:
+            self.outfile = self.argv[1]
+
         super(DispatchTableOpsSubcommand, self).run()
 
     def generate_header(self):
@@ -167,8 +180,8 @@
                 ]
         }
 
-        if len(self.argv) != 2 or self.argv[1] not in library_exports:
-            print("WinDefFileSubcommand: <library-name> {%s}" %
+        if len(self.argv) < 2 or len(self.argv) > 3 or self.argv[1] not in library_exports:
+            print("WinDefFileSubcommand: <library-name> {%s} [outfile]" %
                     "|".join(library_exports.keys()))
             return
 
@@ -178,6 +191,9 @@
         else:
             self.exports = library_exports[self.argv[1]]
 
+        if len(self.argv) == 3:
+            self.outfile = self.argv[2]
+
         super(WinDefFileSubcommand, self).run()
 
     def generate_copyright(self):
diff --git a/vk-layer-generate.py b/vk-layer-generate.py
index e57f8ec..a76c29a 100755
--- a/vk-layer-generate.py
+++ b/vk-layer-generate.py
@@ -164,8 +164,8 @@
     return (obj_uses, local_decls)
 
 class Subcommand(object):
-    def __init__(self, argv):
-        self.argv = argv
+    def __init__(self, outfile):
+        self.outfile = outfile
         self.headers = vulkan.headers
         self.protos = vulkan.protos
         self.no_addr = False
@@ -174,7 +174,11 @@
         self.wsi = sys.argv[1]
 
     def run(self):
-        print(self.generate())
+        if self.outfile:
+            with open(self.outfile, "w") as outfile:
+                outfile.write(self.generate())
+        else:
+            print(self.generate())
 
     def generate(self):
         copyright = self.generate_copyright()
@@ -1664,7 +1668,7 @@
     }
 
     if len(sys.argv) < 4 or sys.argv[1] not in wsi or sys.argv[2] not in subcommands or not os.path.exists(sys.argv[3]):
-        print("Usage: %s <wsi> <subcommand> <input_header> [options]" % sys.argv[0])
+        print("Usage: %s <wsi> <subcommand> <input_header> [outdir]" % sys.argv[0])
         print
         print("Available subcommands are: %s" % " ".join(subcommands))
         exit(1)
@@ -1678,7 +1682,11 @@
     vk_helper.typedef_rev_dict = hfp.get_typedef_rev_dict()
     vk_helper.types_dict = hfp.get_types_dict()
 
-    subcmd = subcommands[sys.argv[2]](sys.argv[3:])
+    outfile = None
+    if len(sys.argv) >= 5:
+        outfile = sys.argv[4]
+
+    subcmd = subcommands[sys.argv[2]](outfile)
     subcmd.run()
 
 if __name__ == "__main__":