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