scons: Use print_function ins SConstruct
[mesa.git] / SConstruct
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
23 from __future__ import print_function
24 import os
25 import os.path
26 import sys
27 import SCons.Util
28
29 import common
30
31 #######################################################################
32 # Minimal scons version
33
34 EnsureSConsVersion(2, 4)
35 EnsurePythonVersion(2, 7)
36
37
38 #######################################################################
39 # Configuration options
40
41 opts = Variables('config.py')
42 common.AddOptions(opts)
43
44 env = Environment(
45 options = opts,
46 tools = ['gallium'],
47 toolpath = ['#scons'],
48 ENV = os.environ,
49 )
50
51 # XXX: This creates a many problems as it saves...
52 #opts.Save('config.py', env)
53
54 # Backwards compatability with old target configuration variable
55 try:
56 targets = ARGUMENTS['targets']
57 except KeyError:
58 pass
59 else:
60 targets = targets.split(',')
61 print('scons: warning: targets option is deprecated; pass the targets on their own such as')
62 print()
63 print(' scons %s' % ' '.join(targets))
64 print()
65 COMMAND_LINE_TARGETS.append(targets)
66
67
68 Help(opts.GenerateHelpText(env))
69
70 #######################################################################
71 # Environment setup
72
73 with open("VERSION") as f:
74 mesa_version = f.read().strip()
75 env.Append(CPPDEFINES = [
76 ('PACKAGE_VERSION', '\\"%s\\"' % mesa_version),
77 ('PACKAGE_BUGREPORT', '\\"https://gitlab.freedesktop.org/mesa/mesa/issues\\"'),
78 ])
79
80 # Includes
81 env.Prepend(CPPPATH = [
82 '#/include',
83 ])
84 env.Append(CPPPATH = [
85 '#/src/gallium/include',
86 '#/src/gallium/auxiliary',
87 '#/src/gallium/drivers',
88 '#/src/gallium/winsys',
89 ])
90
91 # for debugging
92 #print env.Dump()
93
94
95 # Add a check target for running tests
96 check = env.Alias('check')
97 env.AlwaysBuild(check)
98
99
100 #######################################################################
101 # Invoke host SConscripts
102 #
103 # For things that are meant to be run on the native host build machine, instead
104 # of the target machine.
105 #
106
107 # Create host environent
108 if env['crosscompile'] and not env['embedded']:
109 host_env = Environment(
110 options = opts,
111 # no tool used
112 tools = [],
113 toolpath = ['#scons'],
114 ENV = os.environ,
115 )
116
117 # Override options
118 host_env['platform'] = common.host_platform
119 host_env['machine'] = common.host_machine
120 host_env['toolchain'] = 'default'
121 host_env['llvm'] = False
122
123 host_env.Tool('gallium')
124
125 host_env['hostonly'] = True
126 assert host_env['crosscompile'] == False
127
128 target_env = env
129 env = host_env
130 Export('env')
131
132 SConscript(
133 'src/SConscript',
134 variant_dir = host_env['build_dir'],
135 duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
136 )
137
138 env = target_env
139
140 Export('env')
141
142 #######################################################################
143 # Invoke SConscripts
144
145 # TODO: Build several variants at the same time?
146 # http://www.scons.org/wiki/SimultaneousVariantBuilds
147
148 SConscript(
149 'src/SConscript',
150 variant_dir = env['build_dir'],
151 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
152 )
153
154
155 ########################################################################
156 # List all aliases
157
158 try:
159 from SCons.Node.Alias import default_ans
160 except ImportError:
161 pass
162 else:
163 aliases = sorted(default_ans.keys())
164 env.Help('\n')
165 env.Help('Recognized targets:\n')
166 for alias in aliases:
167 env.Help(' %s\n' % alias)