Commit e1bc68b0 authored by Jose Fonseca's avatar Jose Fonseca

scons: Fix cross-compilation.

Hairy stuff. Don't know how to do it better though.
parent 0448f73f
...@@ -118,6 +118,39 @@ if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'): ...@@ -118,6 +118,39 @@ if env['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
Export('env') 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 # Invoke SConscripts
......
...@@ -19,17 +19,17 @@ _platform_map = { ...@@ -19,17 +19,17 @@ _platform_map = {
'win32': 'windows', 'win32': 'windows',
} }
default_platform = sys.platform host_platform = sys.platform
default_platform = _platform_map.get(default_platform, default_platform) host_platform = _platform_map.get(host_platform, host_platform)
# Search sys.argv[] for a "platform=foo" argument since we don't have # Search sys.argv[] for a "platform=foo" argument since we don't have
# an 'env' variable at this point. # an 'env' variable at this point.
if 'platform' in SCons.Script.ARGUMENTS: if 'platform' in SCons.Script.ARGUMENTS:
selected_platform = SCons.Script.ARGUMENTS['platform'] target_platform = SCons.Script.ARGUMENTS['platform']
else: else:
selected_platform = default_platform target_platform = host_platform
cross_compiling = selected_platform != default_platform cross_compiling = target_platform != host_platform
_machine_map = { _machine_map = {
'x86': 'x86', 'x86': 'x86',
...@@ -42,15 +42,17 @@ _machine_map = { ...@@ -42,15 +42,17 @@ _machine_map = {
} }
# find default_machine value # find host_machine value
if 'PROCESSOR_ARCHITECTURE' in os.environ: if 'PROCESSOR_ARCHITECTURE' in os.environ:
default_machine = os.environ['PROCESSOR_ARCHITECTURE'] host_machine = os.environ['PROCESSOR_ARCHITECTURE']
else: else:
default_machine = _platform.machine() host_machine = _platform.machine()
default_machine = _machine_map.get(default_machine, 'generic') host_machine = _machine_map.get(host_machine, 'generic')
default_machine = host_machine
default_toolchain = 'default' default_toolchain = 'default'
if selected_platform == 'windows' and cross_compiling: if target_platform == 'windows' and cross_compiling:
default_machine = 'x86' default_machine = 'x86'
default_toolchain = 'crossmingw' default_toolchain = 'crossmingw'
...@@ -61,7 +63,7 @@ if 'LLVM' in os.environ: ...@@ -61,7 +63,7 @@ if 'LLVM' in os.environ:
else: else:
default_llvm = 'no' default_llvm = 'no'
try: try:
if selected_platform != 'windows' and \ if target_platform != 'windows' and \
subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0: subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
default_llvm = 'yes' default_llvm = 'yes'
except: except:
...@@ -85,7 +87,7 @@ def AddOptions(opts): ...@@ -85,7 +87,7 @@ def AddOptions(opts):
opts.Add(BoolOption('quiet', 'quiet command lines', 'yes')) opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine, opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
allowed_values=('generic', 'ppc', 'x86', 'x86_64'))) 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'))) allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
opts.Add('toolchain', 'compiler toolchain', default_toolchain) opts.Add('toolchain', 'compiler toolchain', default_toolchain)
opts.Add(BoolOption('llvm', 'use LLVM', default_llvm)) opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
......
...@@ -3,6 +3,9 @@ Import('*') ...@@ -3,6 +3,9 @@ Import('*')
if env['platform'] == 'windows': if env['platform'] == 'windows':
SConscript('getopt/SConscript') SConscript('getopt/SConscript')
SConscript('talloc/SConscript') SConscript('talloc/SConscript')
else:
talloc = 'talloc'
Export('talloc')
SConscript('glsl/SConscript') SConscript('glsl/SConscript')
SConscript('mapi/glapi/SConscript') SConscript('mapi/glapi/SConscript')
......
...@@ -9,6 +9,7 @@ env = env.Clone() ...@@ -9,6 +9,7 @@ env = env.Clone()
env.Prepend(CPPPATH = [ env.Prepend(CPPPATH = [
'#src/mapi', '#src/mapi',
'#src/mesa', '#src/mesa',
'#src/glsl',
]) ])
if env['platform'] == 'windows': if env['platform'] == 'windows':
...@@ -80,34 +81,35 @@ sources = [ ...@@ -80,34 +81,35 @@ sources = [
'strtod.c', 'strtod.c',
] ]
if env['msvc']:
if env['platform'] == common.host_platform:
if env['msvc']:
env.Prepend(CPPPATH = ['#/src/getopt']) env.Prepend(CPPPATH = ['#/src/getopt'])
env.PrependUnique(LIBS = [getopt]) env.PrependUnique(LIBS = [getopt])
if env['platform'] == 'windows': if env['platform'] == 'windows':
env.Prepend(CPPPATH = ['#src/talloc'])
env.Prepend(LIBS = [talloc]) env.Prepend(LIBS = [talloc])
else: else:
env.Prepend(LIBS = ['talloc']) env.Prepend(LIBS = ['talloc'])
env.Append(CPPPATH = ['#/src/glsl']) builtin_compiler = env.Program(
builtin_compiler = env.Program(
target = 'builtin_compiler', target = 'builtin_compiler',
source = sources + ['main.cpp', 'builtin_stubs.cpp', source = sources + ['main.cpp', 'builtin_stubs.cpp',
'#src/mesa/program/hash_table.c', '#src/mesa/program/hash_table.c',
'#src/mesa/program/symbol_table.c'], '#src/mesa/program/symbol_table.c'],
) )
env.CodeGenerate( builtin_glsl_function = env.CodeGenerate(
target = 'builtin_function.cpp', target = 'builtin_function.cpp',
script = 'builtins/tools/generate_builtins.py', script = 'builtins/tools/generate_builtins.py',
source = builtin_compiler, source = builtin_compiler,
command = python_cmd + ' $SCRIPT $SOURCE > $TARGET' command = python_cmd + ' $SCRIPT $SOURCE > $TARGET'
) )
env.Depends('builtin_function.cpp', ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*')) env.Depends(builtin_glsl_function, ['builtins/tools/generate_builtins.py', 'builtins/tools/texture_builtins.py'] + Glob('builtins/ir/*'))
if env['msvc']: if env['msvc']:
# There is no LD_LIBRARY_PATH equivalent on Windows. We need to ensure # 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 is on the same dir as builtin_function.
talloc_dll_src = talloc.dir.File('talloc.dll') talloc_dll_src = talloc.dir.File('talloc.dll')
...@@ -115,9 +117,16 @@ if env['msvc']: ...@@ -115,9 +117,16 @@ if env['msvc']:
talloc_dll = env.Command(talloc_dll_dst, talloc_dll_src, Copy(talloc_dll_dst, talloc_dll_src)) talloc_dll = env.Command(talloc_dll_dst, talloc_dll_src, Copy(talloc_dll_dst, talloc_dll_src))
env.Depends('builtin_function.cpp', talloc_dll) env.Depends('builtin_function.cpp', talloc_dll)
Export('builtin_glsl_function')
if common.cross_compiling:
Return()
sources += builtin_glsl_function
glsl = env.ConvenienceLibrary( glsl = env.ConvenienceLibrary(
target = 'glsl', target = 'glsl',
source = sources + [ 'builtin_function.cpp' ], source = sources,
) )
Export('glsl') Export('glsl')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment