util/format: expose generated format packing functions through a header
[mesa.git] / src / util / format / u_format_table.py
index b1e58d4d4790aaffc75db242ea7606d7bc6aa91d..e079da44a64ad469ecad50f9676325913a2135f9 100644 (file)
@@ -30,7 +30,7 @@ CopyRight = '''
 '''
 
 
-import sys
+import sys, os
 
 from u_format_parse import *
 import u_format_pack
@@ -112,19 +112,24 @@ def has_access(format):
         return False
     return True
 
-def write_format_table(formats):
-    print('/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */')
-    print()
+def write_format_table_header(file):
+    print('/* This file is autogenerated by u_format_table.py from u_format.csv. Do not edit directly. */', file=file)
+    print(file=file)
     # This will print the copyright message on the top of this file
-    print(CopyRight.strip())
-    print()
-    print('#include "u_format.h"')
+    print(CopyRight.strip(), file=file)
+    print(file=file)
+    print('#include "util/format/u_format.h"', file=file)
+
+def write_format_table(formats):
+    write_format_table_header(sys.stdout)
     print('#include "u_format_bptc.h"')
     print('#include "u_format_s3tc.h"')
     print('#include "u_format_rgtc.h"')
     print('#include "u_format_latc.h"')
     print('#include "u_format_etc.h"')
     print()
+
+    write_format_table_header(sys.stdout2)
     
     u_format_pack.generate(formats)
     
@@ -261,12 +266,19 @@ def write_format_table(formats):
     generate_table_getter("unpack_")
 
 def main():
-
     formats = []
+
+    sys.stdout2 = open(os.devnull, "w")
+
     for arg in sys.argv[1:]:
+        if arg == '--header':
+            sys.stdout2 = sys.stdout
+            sys.stdout = open(os.devnull, "w")
+            continue
+
         formats.extend(parse(arg))
-    write_format_table(formats)
 
+    write_format_table(formats)
 
 if __name__ == '__main__':
     main()