glapi: Generate GL API marshalling code from the XML.

This is not yet used in the build, just generated.

v2: Add missing build dependencies.
v3: Avoid mixing declarations and code, remove logic for avoiding emitting
    code that the compiler's optimizer can deal with anyway.
v4: (Timothy Arceri) move safe_mul() genereation here from a later patch.

Acked-by: Timothy Arceri <tarceri@itsqueeze.com>
Acked-by: Marek Olšák <maraeo@gmail.com>
Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
Tested-by: Mike Lothian <mike@fireburn.co.uk>
diff --git a/src/mesa/Android.gen.mk b/src/mesa/Android.gen.mk
index a985f0a..a1e58a6 100644
--- a/src/mesa/Android.gen.mk
+++ b/src/mesa/Android.gen.mk
@@ -113,6 +113,18 @@
 $(intermediates)/main/api_exec.c: $(dispatch_deps)
 	$(call es-gen)
 
+$(intermediates)/main/marshal_generated.c: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal.py
+$(intermediates)/main/marshal_generated.c: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml
+
+$(intermediates)/main/marshal_generated.c: $(dispatch_deps)
+	$(call es-gen)
+
+$(intermediates)/main/marshal_generated.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(glapi)/gl_marshal_h.py
+$(intermediates)/main/marshal_generated.h: PRIVATE_XML := -f $(glapi)/gl_and_es_API.xml
+
+$(intermediates)/main/marshal_generated.h: $(dispatch_deps)
+	$(call es-gen)
+
 GET_HASH_GEN := $(LOCAL_PATH)/main/get_hash_generator.py
 
 $(intermediates)/main/get_hash.h: PRIVATE_SCRIPT := $(MESA_PYTHON2) $(GET_HASH_GEN)
diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index e375de6..9398ddb 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -118,6 +118,22 @@
         env.Prepend(CPPPATH = [matypes[0].dir])
 
 
+# The marshal_generated.c file is generated from the GL/ES API.xml file
+env.CodeGenerate(
+    target = 'main/marshal_generated.c',
+    script = GLAPI + 'gen/gl_marshal.py',
+    source = GLAPI + 'gen/gl_and_es_API.xml',
+    command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET'
+    )
+
+# The marshal_generated.h file is generated from the GL/ES API.xml file
+env.CodeGenerate(
+    target = 'main/marshal_generated.h',
+    script = GLAPI + 'gen/gl_marshal_h.py',
+    source = GLAPI + 'gen/gl_and_es_API.xml',
+    command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET'
+    )
+
 #
 # Libraries
 #
diff --git a/src/mesa/main/.gitignore b/src/mesa/main/.gitignore
index a4da567..836d8f1 100644
--- a/src/mesa/main/.gitignore
+++ b/src/mesa/main/.gitignore
@@ -8,3 +8,5 @@
 format_info.c
 format_pack.c
 format_unpack.c
+marshal_generated.c
+marshal_generated.h