scons: Fix cross-compilation.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 13 Jan 2011 20:52:01 +0000 (20:52 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 13 Jan 2011 20:53:42 +0000 (20:53 +0000)
Hairy stuff. Don't know how to do it better though.

SConstruct
common.py
src/SConscript
src/glsl/SConscript

index 8880d851e645541e95ca3990ddb55646993016d4..368ad83edf3f552bf837c9368784370c8e885d92 100644 (file)
@@ -118,6 +118,39 @@ if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
 Export('env')
 
 
+#######################################################################
+# Invoke host SConscripts 
+# 
+# For things that are meant to be run on the native host build machine, instead
+# of the target machine.
+#
+
+# Create host environent
+if env['platform'] != common.host_platform:
+    host_env = Environment(
+        options = opts,
+        # no tool used
+        tools = [],
+        toolpath = ['#scons'],
+        ENV = os.environ,
+    )
+
+    # Override options
+    host_env['platform'] = common.host_platform
+    host_env['machine'] = common.host_machine
+    host_env['toolchain'] = 'default'
+    host_env['llvm'] = False
+
+    host_env.Tool('gallium')
+
+    SConscript(
+        'src/glsl/SConscript',
+        variant_dir = host_env['build_dir'],
+        duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
+        exports={'env':host_env},
+    )
+
+
 #######################################################################
 # Invoke SConscripts
 
index 78e2d0fb24f112ffd0a76dcbe301026917077193..76184d577a3433231885a10755ab4f0b73905e0d 100644 (file)
--- a/common.py
+++ b/common.py
@@ -19,17 +19,17 @@ _platform_map = {
        'win32': 'windows',
 }
 
-default_platform = sys.platform
-default_platform = _platform_map.get(default_platform, default_platform)
+host_platform = sys.platform
+host_platform = _platform_map.get(host_platform, host_platform)
 
 # Search sys.argv[] for a "platform=foo" argument since we don't have
 # an 'env' variable at this point.
 if 'platform' in SCons.Script.ARGUMENTS:
-    selected_platform = SCons.Script.ARGUMENTS['platform']
+    target_platform = SCons.Script.ARGUMENTS['platform']
 else:
-    selected_platform = default_platform
+    target_platform = host_platform
 
-cross_compiling = selected_platform != default_platform
+cross_compiling = target_platform != host_platform
 
 _machine_map = {
        'x86': 'x86',
@@ -42,15 +42,17 @@ _machine_map = {
 }
 
 
-# find default_machine value
+# find host_machine value
 if 'PROCESSOR_ARCHITECTURE' in os.environ:
-       default_machine = os.environ['PROCESSOR_ARCHITECTURE']
+       host_machine = os.environ['PROCESSOR_ARCHITECTURE']
 else:
-       default_machine = _platform.machine()
-default_machine = _machine_map.get(default_machine, 'generic')
+       host_machine = _platform.machine()
+host_machine = _machine_map.get(host_machine, 'generic')
+
+default_machine = host_machine
 default_toolchain = 'default'
 
-if selected_platform == 'windows' and cross_compiling:
+if target_platform == 'windows' and cross_compiling:
     default_machine = 'x86'
     default_toolchain = 'crossmingw'
 
@@ -61,7 +63,7 @@ if 'LLVM' in os.environ:
 else:
     default_llvm = 'no'
     try:
-        if selected_platform != 'windows' and \
+        if target_platform != 'windows' and \
            subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
             default_llvm = 'yes'
     except:
@@ -85,7 +87,7 @@ def AddOptions(opts):
        opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
        opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
                                                                                         allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
-       opts.Add(EnumOption('platform', 'target platform', default_platform,
+       opts.Add(EnumOption('platform', 'target platform', host_platform,
                                                                                         allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
        opts.Add('toolchain', 'compiler toolchain', default_toolchain)
        opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
index 38137ee9028d941daf98720a7035524697c1a96c..201812c5ac3f1199c79c50ff34c203724f28278a 100644 (file)
@@ -3,6 +3,9 @@ Import('*')
 if env['platform'] == 'windows':
     SConscript('getopt/SConscript')
     SConscript('talloc/SConscript')
+else:
+    talloc = 'talloc'
+    Export('talloc')
 
 SConscript('glsl/SConscript')
 SConscript('mapi/glapi/SConscript')
index a22fceb75c7389c4644c297feef5089273d634f8..88a83fdb6fa0c37649d2c5a3cf523c1bdf14e4e0 100644 (file)
@@ -9,6 +9,7 @@ env = env.Clone()
 env.Prepend(CPPPATH = [
     '#src/mapi',
     '#src/mesa',
+    '#src/glsl',
 ])
 
 if env['platform'] == 'windows':
@@ -78,46 +79,54 @@ sources = [
     'opt_tree_grafting.cpp',
     's_expression.cpp',
     'strtod.c',
-]
+] 
 
-if env['msvc']:
-    env.Prepend(CPPPATH = ['#/src/getopt'])
-    env.PrependUnique(LIBS = [getopt])
 
-if env['platform'] == 'windows':
-    env.Prepend(LIBS = [talloc])
-else:
-    env.Prepend(LIBS = ['talloc'])
+if env['platform'] == common.host_platform:
+    if env['msvc']:
+        env.Prepend(CPPPATH = ['#/src/getopt'])
+        env.PrependUnique(LIBS = [getopt])
 
-env.Append(CPPPATH = ['#/src/glsl'])
+    if env['platform'] == 'windows':
+        env.Prepend(CPPPATH = ['#src/talloc'])
+        env.Prepend(LIBS = [talloc])
+    else:
+        env.Prepend(LIBS = ['talloc'])
 
-builtin_compiler = env.Program(
-    target = 'builtin_compiler',
-    source = sources + ['main.cpp', 'builtin_stubs.cpp',
-                        '#src/mesa/program/hash_table.c',
-                        '#src/mesa/program/symbol_table.c'],
-)
+    builtin_compiler = env.Program(
+        target = 'builtin_compiler',
+        source = sources + ['main.cpp', 'builtin_stubs.cpp',
+                            '#src/mesa/program/hash_table.c',
+                            '#src/mesa/program/symbol_table.c'],
+    )
 
-env.CodeGenerate(
-    target = 'builtin_function.cpp',
-    script = 'builtins/tools/generate_builtins.py',
-    source = builtin_compiler,
-    command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
-)
+    builtin_glsl_function = env.CodeGenerate(
+        target = 'builtin_function.cpp',
+        script = 'builtins/tools/generate_builtins.py',
+        source = builtin_compiler,
+        command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
+    )
+
+    env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
+
+    if env['msvc']:
+        # There is no LD_LIBRARY_PATH equivalent on Windows. We need to ensure
+        # talloc.dll is on the same dir as builtin_function.
+        talloc_dll_src = talloc.dir.File('talloc.dll')
+        talloc_dll_dst = builtin_compiler[0].dir.File('talloc.dll')
+        talloc_dll = env.Command(talloc_dll_dst, talloc_dll_src, Copy(talloc_dll_dst, talloc_dll_src))
+        env.Depends('builtin_function.cpp', talloc_dll)
+
+    Export('builtin_glsl_function')
 
-env.Depends('builtin_function.cpp', ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
+    if common.cross_compiling:
+        Return()
 
-if env['msvc']:
-    # There is no LD_LIBRARY_PATH equivalent on Windows. We need to ensure
-    # talloc.dll is on the same dir as builtin_function.
-    talloc_dll_src = talloc.dir.File('talloc.dll')
-    talloc_dll_dst = builtin_compiler[0].dir.File('talloc.dll')
-    talloc_dll = env.Command(talloc_dll_dst, talloc_dll_src, Copy(talloc_dll_dst, talloc_dll_src))
-    env.Depends('builtin_function.cpp', talloc_dll)
+sources += builtin_glsl_function
 
 glsl = env.ConvenienceLibrary(
     target = 'glsl',
-    source = sources + [ 'builtin_function.cpp' ],
+    source = sources,
 )
 
 Export('glsl')