Mesa (glsl-pp-rework-2): scons: Get GLSL code building correctly when cross compiling.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Thu Dec 10 08:31:39 PST 2009


Module: Mesa
Branch: glsl-pp-rework-2
Commit: 491f384c3958067e6c4c994041f5d8d413b806bc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=491f384c3958067e6c4c994041f5d8d413b806bc

Author: José Fonseca <jfonseca at vmware.com>
Date:   Thu Dec 10 16:29:04 2009 +0000

scons: Get GLSL code building correctly when cross compiling.

This is quite messy. GLSL code has to be built twice: one for the
host OS, another for the target OS.

---

 SConstruct                               |   19 ++++++++
 src/SConscript                           |    4 +-
 src/gallium/winsys/gdi/SConscript        |    2 +-
 src/glsl/SConscript                      |   68 ++++++++++++++++++++++++++++++
 src/glsl/apps/SConscript                 |   36 ----------------
 src/glsl/cl/SConscript                   |   11 -----
 src/glsl/pp/SConscript                   |   24 ----------
 src/mesa/shader/slang/library/SConscript |    8 ++++
 8 files changed, 97 insertions(+), 75 deletions(-)

diff --git a/SConstruct b/SConstruct
index e9baab0..e71fcd6 100644
--- a/SConstruct
+++ b/SConstruct
@@ -160,6 +160,25 @@ Export('env')
 # TODO: Build several variants at the same time?
 # http://www.scons.org/wiki/SimultaneousVariantBuilds
 
+if env['platform'] != common.default_platform:
+    # GLSL code has to be built twice -- one for the host OS, another for the target OS...
+
+    host_env = Environment(
+        # options are ignored
+        # default tool is used
+        toolpath = ['#scons'],	
+        ENV = os.environ,
+    )
+
+    host_env['platform'] = common.default_platform
+
+    SConscript(
+        'src/glsl/SConscript',
+        variant_dir = env['build'] + '/host',
+        duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
+        exports={'env':host_env},
+    )
+
 SConscript(
 	'src/SConscript',
 	variant_dir = env['build'],
diff --git a/src/SConscript b/src/SConscript
index f7fac33..6083fcb 100644
--- a/src/SConscript
+++ b/src/SConscript
@@ -1,8 +1,6 @@
 Import('*')
 
-SConscript('glsl/pp/SConscript')
-SConscript('glsl/cl/SConscript')
-SConscript('glsl/apps/SConscript')
+SConscript('glsl/SConscript')
 SConscript('gallium/SConscript')
 
 if 'mesa' in env['statetrackers']:
diff --git a/src/gallium/winsys/gdi/SConscript b/src/gallium/winsys/gdi/SConscript
index 5b6364a..9fbe9e8 100644
--- a/src/gallium/winsys/gdi/SConscript
+++ b/src/gallium/winsys/gdi/SConscript
@@ -39,5 +39,5 @@ if env['platform'] == 'windows':
     env.SharedLibrary(
         target ='opengl32',
         source = sources,
-        LIBS = wgl + glapi + mesa + drivers + auxiliaries + glsl + glslcl + env['LIBS'],
+        LIBS = wgl + glapi + mesa + drivers + auxiliaries + glsl + env['LIBS'],
     )
diff --git a/src/glsl/SConscript b/src/glsl/SConscript
new file mode 100644
index 0000000..6f1f81b
--- /dev/null
+++ b/src/glsl/SConscript
@@ -0,0 +1,68 @@
+import common
+
+Import('*')
+
+env = env.Clone()
+
+sources = [
+    'pp/sl_pp_context.c',
+    'pp/sl_pp_define.c',
+    'pp/sl_pp_dict.c',
+    'pp/sl_pp_error.c',
+    'pp/sl_pp_expression.c',
+    'pp/sl_pp_extension.c',
+    'pp/sl_pp_if.c',
+    'pp/sl_pp_line.c',
+    'pp/sl_pp_macro.c',
+    'pp/sl_pp_pragma.c',
+    'pp/sl_pp_process.c',
+    'pp/sl_pp_purify.c',
+    'pp/sl_pp_token.c',
+    'pp/sl_pp_version.c',
+    'cl/sl_cl_parse.c',
+]
+
+glsl = env.StaticLibrary(
+    target = 'glsl',
+    source = sources,
+)
+
+Export('glsl')
+
+env = env.Clone()
+
+if env['platform'] == 'windows':
+    env.PrependUnique(LIBS = [
+        'user32',
+    ])
+
+env.Prepend(LIBS = [glsl])
+
+env.Program(
+    target = 'purify',
+    source = ['apps/purify.c'],
+)
+
+env.Program(
+    target = 'tokenise',
+    source = ['apps/tokenise.c'],
+)
+
+env.Program(
+    target = 'version',
+    source = ['apps/version.c'],
+)
+
+env.Program(
+    target = 'process',
+    source = ['apps/process.c'],
+)
+
+glsl_compile = env.Program(
+    target = 'compile',
+    source = ['apps/compile.c'],
+)
+
+if env['platform'] == common.default_platform:
+    # Only export the GLSL compiler when building for the host platform
+    Export('glsl_compile')
diff --git a/src/glsl/apps/SConscript b/src/glsl/apps/SConscript
deleted file mode 100644
index 4c81b3b..0000000
--- a/src/glsl/apps/SConscript
+++ /dev/null
@@ -1,36 +0,0 @@
-Import('*')
-
-env = env.Clone()
-
-if env['platform'] == 'windows':
-    env.PrependUnique(LIBS = [
-        'user32',
-    ])
-
-env.Prepend(LIBS = [glsl, glslcl])
-
-env.Program(
-    target = 'purify',
-    source = ['purify.c'],
-)
-
-env.Program(
-    target = 'tokenise',
-    source = ['tokenise.c'],
-)
-
-env.Program(
-    target = 'version',
-    source = ['version.c'],
-)
-
-env.Program(
-    target = 'process',
-    source = ['process.c'],
-)
-
-glsl_compile = env.Program(
-    target = 'compile',
-    source = ['compile.c'],
-)
-Export('glsl_compile')
diff --git a/src/glsl/cl/SConscript b/src/glsl/cl/SConscript
deleted file mode 100644
index 9a4e4c1..0000000
--- a/src/glsl/cl/SConscript
+++ /dev/null
@@ -1,11 +0,0 @@
-Import('*')
-
-env = env.Clone()
-
-glslcl = env.StaticLibrary(
-    target = 'glslcl',
-    source = [
-        'sl_cl_parse.c',
-    ],
-)
-Export('glslcl')
diff --git a/src/glsl/pp/SConscript b/src/glsl/pp/SConscript
deleted file mode 100644
index 5bd615c..0000000
--- a/src/glsl/pp/SConscript
+++ /dev/null
@@ -1,24 +0,0 @@
-Import('*')
-
-env = env.Clone()
-
-glsl = env.StaticLibrary(
-    target = 'glsl',
-    source = [
-        'sl_pp_context.c',
-        'sl_pp_define.c',
-        'sl_pp_dict.c',
-        'sl_pp_error.c',
-        'sl_pp_expression.c',
-        'sl_pp_extension.c',
-        'sl_pp_if.c',
-        'sl_pp_line.c',
-        'sl_pp_macro.c',
-        'sl_pp_pragma.c',
-        'sl_pp_process.c',
-        'sl_pp_purify.c',
-        'sl_pp_token.c',
-        'sl_pp_version.c',
-    ],
-)
-Export('glsl')
diff --git a/src/mesa/shader/slang/library/SConscript b/src/mesa/shader/slang/library/SConscript
index 8b3fd03..ef13114 100644
--- a/src/mesa/shader/slang/library/SConscript
+++ b/src/mesa/shader/slang/library/SConscript
@@ -5,13 +5,21 @@ Import('*')
 
 env = env.Clone()
 
+# See also http://www.scons.org/wiki/UsingCodeGenerators
+
+def glsl_compile_emitter(target, source, env):
+	env.Depends(target, glsl_compile)
+	return (target, source)
+ 
 bld_frag = Builder(
 	action = glsl_compile[0].abspath + ' fragment $SOURCE $TARGET',
+	emitter = glsl_compile_emitter,
 	suffix = '.gc',
 	src_suffix = '_gc.h')
 	
 bld_vert = Builder(
 	action = glsl_compile[0].abspath + ' vertex $SOURCE $TARGET',
+	emitter = glsl_compile_emitter,
 	suffix = '.gc',
 	src_suffix = '_gc.h')
 



More information about the mesa-commit mailing list