Merge branch 'master' of git+ssh://git.freedesktop.org/git/mesa/mesa
[mesa.git] / SConstruct
1 #######################################################################
2 # Top-level SConstruct
3 #
4 # For example, invoke scons as
5 #
6 # scons debug=1 dri=0 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 # debug=1
13 # dri=0
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 import os
24 import os.path
25 import sys
26 import SCons.Util
27
28 import common
29
30 #######################################################################
31 # Configuration options
32
33 default_statetrackers = 'mesa'
34
35 if common.default_platform in ('linux', 'freebsd', 'darwin'):
36 default_drivers = 'softpipe,failover,svga,i915,i965,trace,identity,llvmpipe'
37 default_winsys = 'xlib'
38 elif common.default_platform in ('winddk',):
39 default_drivers = 'softpipe,svga,i915,i965,trace,identity'
40 default_winsys = 'all'
41 elif common.default_platform in ('embedded',):
42 default_drivers = 'softpipe,llvmpipe'
43 default_winsys = 'xlib'
44 else:
45 default_drivers = 'all'
46 default_winsys = 'all'
47
48 opts = Variables('config.py')
49 common.AddOptions(opts)
50 opts.Add(ListVariable('statetrackers', 'state trackers to build', default_statetrackers,
51 ['mesa', 'python', 'xorg']))
52 opts.Add(ListVariable('drivers', 'pipe drivers to build', default_drivers,
53 ['softpipe', 'failover', 'svga', 'i915', 'i965', 'trace', 'r300', 'identity', 'llvmpipe']))
54 opts.Add(ListVariable('winsys', 'winsys drivers to build', default_winsys,
55 ['xlib', 'vmware', 'intel', 'i965', 'gdi', 'radeon']))
56
57 opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
58
59 env = Environment(
60 options = opts,
61 tools = ['gallium'],
62 toolpath = ['#scons'],
63 ENV = os.environ,
64 )
65
66 if os.environ.has_key('CC'):
67 env['CC'] = os.environ['CC']
68 if os.environ.has_key('CFLAGS'):
69 env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
70 if os.environ.has_key('CXX'):
71 env['CXX'] = os.environ['CXX']
72 if os.environ.has_key('CXXFLAGS'):
73 env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
74 if os.environ.has_key('LDFLAGS'):
75 env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
76
77 Help(opts.GenerateHelpText(env))
78
79 # replicate options values in local variables
80 debug = env['debug']
81 dri = env['dri']
82 machine = env['machine']
83 platform = env['platform']
84 drawllvm = 'llvmpipe' in env['drivers']
85
86 # LLVM support in the Draw module
87 if drawllvm:
88 env.Tool('llvm')
89 if not env.has_key('LLVM_VERSION'):
90 drawllvm = False
91
92 # derived options
93 x86 = machine == 'x86'
94 ppc = machine == 'ppc'
95 gcc = platform in ('linux', 'freebsd', 'darwin', 'embedded')
96 msvc = platform in ('windows', 'winddk')
97
98 Export([
99 'debug',
100 'x86',
101 'ppc',
102 'dri',
103 'drawllvm',
104 'platform',
105 'gcc',
106 'msvc',
107 ])
108
109
110 #######################################################################
111 # Environment setup
112
113 # Includes
114 env.Append(CPPPATH = [
115 '#/include',
116 '#/src/gallium/include',
117 '#/src/gallium/auxiliary',
118 '#/src/gallium/drivers',
119 ])
120
121 if env['msvc']:
122 env.Append(CPPPATH = ['#include/c99'])
123
124 # Embedded
125 if platform == 'embedded':
126 env.Append(CPPDEFINES = [
127 '_POSIX_SOURCE',
128 ('_POSIX_C_SOURCE', '199309L'),
129 '_SVID_SOURCE',
130 '_BSD_SOURCE',
131 '_GNU_SOURCE',
132
133 'PTHREADS',
134 ])
135 env.Append(LIBS = [
136 'm',
137 'pthread',
138 'dl',
139 ])
140
141 # Posix
142 if platform in ('posix', 'linux', 'freebsd', 'darwin'):
143 env.Append(CPPDEFINES = [
144 '_POSIX_SOURCE',
145 ('_POSIX_C_SOURCE', '199309L'),
146 '_SVID_SOURCE',
147 '_BSD_SOURCE',
148 '_GNU_SOURCE',
149
150 'PTHREADS',
151 'HAVE_POSIX_MEMALIGN',
152 ])
153 if platform == 'darwin':
154 env.Append(CPPDEFINES = ['_DARWIN_C_SOURCE'])
155 env.Append(CPPPATH = ['/usr/X11R6/include'])
156 env.Append(LIBPATH = ['/usr/X11R6/lib'])
157 env.Append(LIBS = [
158 'm',
159 'pthread',
160 'expat',
161 'dl',
162 ])
163
164 # DRI
165 if dri:
166 env.ParseConfig('pkg-config --cflags --libs libdrm')
167 env.Append(CPPDEFINES = [
168 ('USE_EXTERNAL_DXTN_LIB', '1'),
169 'IN_DRI_DRIVER',
170 'GLX_DIRECT_RENDERING',
171 'GLX_INDIRECT_RENDERING',
172 ])
173
174 # LLVM support in the Draw module
175 if drawllvm:
176 env.Append(CPPDEFINES = ['DRAW_LLVM'])
177
178 # libGL
179 if platform in ('linux', 'freebsd', 'darwin'):
180 env.Append(LIBS = [
181 'X11',
182 'Xext',
183 'Xxf86vm',
184 'Xdamage',
185 'Xfixes',
186 ])
187
188 # for debugging
189 #print env.Dump()
190
191 Export('env')
192
193
194 #######################################################################
195 # Invoke SConscripts
196
197 # TODO: Build several variants at the same time?
198 # http://www.scons.org/wiki/SimultaneousVariantBuilds
199
200 if env['platform'] != common.default_platform:
201 # GLSL code has to be built twice -- one for the host OS, another for the target OS...
202
203 host_env = Environment(
204 # options are ignored
205 # default tool is used
206 tools = ['default', 'custom'],
207 toolpath = ['#scons'],
208 ENV = os.environ,
209 )
210
211 host_env['platform'] = common.default_platform
212 host_env['machine'] = common.default_machine
213 host_env['debug'] = env['debug']
214
215 SConscript(
216 'src/glsl/SConscript',
217 variant_dir = os.path.join(env['build'], 'host'),
218 duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
219 exports={'env':host_env},
220 )
221
222 SConscript(
223 'src/SConscript',
224 variant_dir = env['build'],
225 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
226 )
227
228 if 'progs' in COMMAND_LINE_TARGETS:
229 SConscript(
230 'progs/SConscript',
231 variant_dir = os.path.join('progs', env['build']),
232 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
233 )