1#######################################################################
2# Top-level SConstruct
3#
4# For example, invoke scons as 
5#
6#   scons build=debug llvm=yes machine=x86
7#
8# to set configuration variables. Or you can write those options to a file
9# named config.py:
10#
11#   # config.py
12#   build='debug'
13#   llvm=True
14#   machine='x86'
15# 
16# Invoke
17#
18#   scons -h
19#
20# to get the full list of options. See scons manpage for more info.
21#  
22
23import os
24import os.path
25import sys
26import SCons.Util
27
28import common
29
30#######################################################################
31# Configuration options
32
33opts = Variables('config.py')
34common.AddOptions(opts)
35
36env = Environment(
37	options = opts,
38	tools = ['gallium'],
39	toolpath = ['#scons'],	
40	ENV = os.environ,
41)
42
43# XXX: This creates a many problems as it saves...
44#opts.Save('config.py', env)
45
46# Backwards compatability with old target configuration variable
47try:
48    targets = ARGUMENTS['targets']
49except KeyError:
50    pass
51else:
52    targets = targets.split(',')
53    print 'scons: warning: targets option is deprecated; pass the targets on their own such as'
54    print
55    print '  scons %s' % ' '.join(targets)
56    print 
57    COMMAND_LINE_TARGETS.append(targets)
58
59
60Help(opts.GenerateHelpText(env))
61
62# fail early for a common error on windows
63if env['gles']:
64    try:
65        import libxml2
66    except ImportError:
67        raise SCons.Errors.UserError, "GLES requires libxml2-python to build"
68
69#######################################################################
70# Environment setup
71
72# Includes
73env.Prepend(CPPPATH = [
74	'#/include',
75])
76env.Append(CPPPATH = [
77	'#/src/gallium/include',
78	'#/src/gallium/auxiliary',
79	'#/src/gallium/drivers',
80	'#/src/gallium/winsys',
81])
82
83if env['msvc']:
84    env.Append(CPPPATH = ['#include/c99'])
85
86# for debugging
87#print env.Dump()
88
89
90#######################################################################
91# Invoke host SConscripts 
92# 
93# For things that are meant to be run on the native host build machine, instead
94# of the target machine.
95#
96
97# Create host environent
98if env['crosscompile'] and not env['embedded']:
99    host_env = Environment(
100        options = opts,
101        # no tool used
102        tools = [],
103        toolpath = ['#scons'],
104        ENV = os.environ,
105    )
106
107    # Override options
108    host_env['platform'] = common.host_platform
109    host_env['machine'] = common.host_machine
110    host_env['toolchain'] = 'default'
111    host_env['llvm'] = False
112
113    host_env.Tool('gallium')
114
115    host_env['hostonly'] = True
116    assert host_env['crosscompile'] == False
117
118    if host_env['msvc']:
119        host_env.Append(CPPPATH = ['#include/c99'])
120
121    target_env = env
122    env = host_env
123    Export('env')
124
125    SConscript(
126        'src/SConscript',
127        variant_dir = host_env['build_dir'],
128        duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
129    )
130
131    env = target_env
132
133Export('env')
134
135#######################################################################
136# Invoke SConscripts
137
138# TODO: Build several variants at the same time?
139# http://www.scons.org/wiki/SimultaneousVariantBuilds
140
141SConscript(
142	'src/SConscript',
143	variant_dir = env['build_dir'],
144	duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
145)
146
147
148########################################################################
149# List all aliases
150
151try:
152    from SCons.Node.Alias import default_ans
153except ImportError:
154    pass
155else:
156    aliases = default_ans.keys()
157    aliases.sort()
158    env.Help('\n')
159    env.Help('Recognized targets:\n')
160    for alias in aliases:
161        env.Help('    %s\n' % alias)
162