gallium: fix a state validation bug found w/ pointblast.c
[mesa.git] / SConstruct
1 #######################################################################
2 # Top-level SConstruct
3
4 import os
5 import os.path
6 import sys
7
8
9 #######################################################################
10 # Configuration options
11 #
12 # For example, invoke scons as
13 #
14 # scons debug=1 dri=0 machine=x86
15 #
16 # to set configuration variables. Or you can write those options to a file
17 # named config.py:
18 #
19 # # config.py
20 # debug=1
21 # dri=0
22 # machine='x86'
23 #
24 # Invoke
25 #
26 # scons -h
27 #
28 # to get the full list of options. See scons manpage for more info.
29 #
30
31 platform_map = {
32 'linux2': 'linux',
33 'win32': 'winddk',
34 }
35
36 default_platform = platform_map.get(sys.platform, sys.platform)
37 default_drivers = 'all'
38 if default_platform in ('linux', 'freebsd', 'darwin'):
39 default_x11 = 'yes'
40 else:
41 default_x11 = 'no'
42
43 # TODO: auto-detect defaults
44 opts = Options('config.py')
45 opts.Add(BoolOption('debug', 'build debug version', False))
46 opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
47 allowed_values=('generic', 'x86', 'x86-64')))
48 opts.Add(EnumOption('platform', 'target platform', default_platform,
49 allowed_values=('linux', 'cell', 'winddk')))
50 opts.Add(ListOption('statetrackers', 'state_trackers to build', 'all',
51 [
52 'mesa',
53 ],
54 ))
55 #opts.Add(ListOption('drivers', 'pipe drivers to build', 'all',
56 # [
57 # 'softpipe',
58 # 'failover',
59 # 'i915simple',
60 # 'i965simple',
61 # 'cell',
62 # ],
63 # ))
64 opts.Add(BoolOption('llvm', 'use llvm', False))
65 opts.Add(BoolOption('dri', 'build dri drivers', False))
66 opts.Add(BoolOption('x11', 'build x11 driver', default_x11))
67
68 env = Environment(
69 options = opts,
70 ENV = os.environ)
71 Help(opts.GenerateHelpText(env))
72
73 # for debugging
74 #print env.Dump()
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 gcc = platform in ('linux', 'freebsd', 'darwin')
86 msvc = platform in ('win32', 'winddk')
87
88 Export([
89 'debug',
90 'x86',
91 'dri',
92 'llvm',
93 'platform',
94 'gcc',
95 'msvc',
96 ])
97
98
99 #######################################################################
100 # Environment setup
101 #
102 # TODO: put the compiler specific settings in separate files
103 # TODO: auto-detect as much as possible
104
105
106 if platform == 'winddk':
107 import ntpath
108 escape = env['ESCAPE']
109 env.Tool('msvc')
110 if 'BASEDIR' in os.environ:
111 WINDDK = os.environ['BASEDIR']
112 else:
113 WINDDK = "C:\\WINDDK\\3790.1830"
114 # NOTE: We need this elaborate construct to get the absolute paths and
115 # forward slashes to msvc unharmed when cross compiling from posix platforms
116 env.Append(CPPFLAGS = [
117 escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wxp')),
118 escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wdm\\wxp')),
119 escape('/I' + ntpath.join(WINDDK, 'inc\\crt')),
120 ])
121 env.Append(CPPDEFINES = [
122 ('i386', '1'),
123 ])
124 if debug:
125 env.Append(CPPDEFINES = ['DBG'])
126
127
128 # Optimization flags
129 if gcc:
130 if debug:
131 env.Append(CFLAGS = '-O0 -g3')
132 env.Append(CXXFLAGS = '-O0 -g3')
133 else:
134 env.Append(CFLAGS = '-O3 -g3')
135 env.Append(CXXFLAGS = '-O3 -g3')
136
137 env.Append(CFLAGS = '-Wall -Wmissing-prototypes -Wno-long-long -ffast-math -pedantic')
138 env.Append(CXXFLAGS = '-Wall -pedantic')
139
140 # Be nice to Eclipse
141 env.Append(CFLAGS = '-fmessage-length=0')
142 env.Append(CXXFLAGS = '-fmessage-length=0')
143
144
145 # Defines
146 if debug:
147 env.Append(CPPDEFINES = ['DEBUG'])
148 else:
149 env.Append(CPPDEFINES = ['NDEBUG'])
150
151
152 # Includes
153 env.Append(CPPPATH = [
154 '#/include',
155 '#/src/gallium/include',
156 '#/src/gallium/auxiliary',
157 '#/src/gallium/drivers',
158 ])
159
160
161 # x86 assembly
162 if x86:
163 env.Append(CPPDEFINES = [
164 'USE_X86_ASM',
165 'USE_MMX_ASM',
166 'USE_3DNOW_ASM',
167 'USE_SSE_ASM',
168 ])
169 if gcc:
170 env.Append(CFLAGS = '-m32')
171 env.Append(CXXFLAGS = '-m32')
172
173
174 # Posix
175 if platform in ('posix', 'linux', 'freebsd', 'darwin'):
176 env.Append(CPPDEFINES = [
177 '_POSIX_SOURCE',
178 ('_POSIX_C_SOURCE', '199309L'),
179 '_SVID_SOURCE',
180 '_BSD_SOURCE',
181 '_GNU_SOURCE',
182
183 'PTHREADS',
184 'HAVE_POSIX_MEMALIGN',
185 ])
186 env.Append(CPPPATH = ['/usr/X11R6/include'])
187 env.Append(LIBPATH = ['/usr/X11R6/lib'])
188 env.Append(LIBS = [
189 'm',
190 'pthread',
191 'expat',
192 'dl',
193 ])
194
195
196 # DRI
197 if dri:
198 env.ParseConfig('pkg-config --cflags --libs libdrm')
199 env.Append(CPPDEFINES = [
200 ('USE_EXTERNAL_DXTN_LIB', '1'),
201 'IN_DRI_DRIVER',
202 'GLX_DIRECT_RENDERING',
203 'GLX_INDIRECT_RENDERING',
204 ])
205
206 # LLVM
207 if llvm:
208 # See also http://www.scons.org/wiki/UsingPkgConfig
209 env.ParseConfig('llvm-config --cflags --ldflags --libs')
210 env.Append(CPPDEFINES = ['MESA_LLVM'])
211 env.Append(CXXFLAGS = ['-Wno-long-long'])
212
213
214 # libGL
215 if 1:
216 env.Append(LIBS = [
217 'X11',
218 'Xext',
219 'Xxf86vm',
220 'Xdamage',
221 'Xfixes',
222 ])
223
224 Export('env')
225
226
227 #######################################################################
228 # Convenience Library Builder
229 # based on the stock StaticLibrary and SharedLibrary builders
230
231 def createConvenienceLibBuilder(env):
232 """This is a utility function that creates the ConvenienceLibrary
233 Builder in an Environment if it is not there already.
234
235 If it is already there, we return the existing one.
236 """
237
238 try:
239 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
240 except KeyError:
241 action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
242 if env.Detect('ranlib'):
243 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
244 action_list.append(ranlib_action)
245
246 convenience_lib = Builder(action = action_list,
247 emitter = '$LIBEMITTER',
248 prefix = '$LIBPREFIX',
249 suffix = '$LIBSUFFIX',
250 src_suffix = '$SHOBJSUFFIX',
251 src_builder = 'SharedObject')
252 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
253 env['BUILDERS']['Library'] = convenience_lib
254
255 return convenience_lib
256
257 createConvenienceLibBuilder(env)
258
259
260 #######################################################################
261 # Invoke SConscripts
262
263 # Put build output in a separate dir, which depends on the current configuration
264 # See also http://www.scons.org/wiki/AdvancedBuildExample
265 build_topdir = 'build'
266 build_subdir = platform
267 if dri:
268 build_subdir += "-dri"
269 if llvm:
270 build_subdir += "-llvm"
271 if x86:
272 build_subdir += "-x86"
273 if debug:
274 build_subdir += "-debug"
275 build_dir = os.path.join(build_topdir, build_subdir)
276
277 # TODO: Build several variants at the same time?
278 # http://www.scons.org/wiki/SimultaneousVariantBuilds
279
280 SConscript(
281 'src/SConscript',
282 build_dir = build_dir,
283 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
284 )