blob: 02e61650057f2f1f8f53b90dbc8b9dd75fbc43f0 [file] [log] [blame]
José Fonsecac42e6252008-01-31 13:14:35 +09001#######################################################################
2# Top-level SConstruct
3
4import os
José Fonsecaf4192cb42008-01-31 14:21:49 +09005import os.path
José Fonsecac42e6252008-01-31 13:14:35 +09006import sys
7
8
9#######################################################################
10# Configuration options
11#
12# For example, invoke scons as
13#
José Fonseca81b6a802008-02-06 14:36:50 +090014# scons debug=1 dri=0 machine=x86
José Fonsecac42e6252008-01-31 13:14:35 +090015#
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
José Fonseca81b6a802008-02-06 14:36:50 +090022# machine='x86'
José Fonsecac42e6252008-01-31 13:14:35 +090023#
24# Invoke
25#
26# scons -h
27#
28# to get the full list of options. See scons manpage for more info.
29#
30
José Fonsecad710a7c2008-02-19 18:53:16 +090031platform_map = {
32 'linux2': 'linux',
33 'win32': 'winddk',
34}
35
José Fonseca26c57d12008-02-23 00:46:40 +090036default_platform = platform_map.get(sys.platform, sys.platform)
José Fonseca58a3d7d2008-02-23 19:49:08 +090037
José Fonseca26c57d12008-02-23 00:46:40 +090038if default_platform in ('linux', 'freebsd', 'darwin'):
José Fonseca58a3d7d2008-02-23 19:49:08 +090039 default_statetrackers = 'mesa'
40 default_drivers = 'softpipe,failover,i915simple,i965simple'
41 default_winsys = 'xlib'
42elif default_platform in ('winddk',):
43 default_statetrackers = 'none'
44 default_drivers = 'softpipe,i915simple'
45 default_winsys = 'none'
José Fonseca26c57d12008-02-23 00:46:40 +090046else:
José Fonseca58a3d7d2008-02-23 19:49:08 +090047 default_drivers = 'all'
48 default_winsys = 'all'
José Fonsecad710a7c2008-02-19 18:53:16 +090049
José Fonsecac42e6252008-01-31 13:14:35 +090050# TODO: auto-detect defaults
51opts = Options('config.py')
52opts.Add(BoolOption('debug', 'build debug version', False))
José Fonsecac42e6252008-01-31 13:14:35 +090053opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
54 allowed_values=('generic', 'x86', 'x86-64')))
José Fonseca26c57d12008-02-23 00:46:40 +090055opts.Add(EnumOption('platform', 'target platform', default_platform,
José Fonsecad710a7c2008-02-19 18:53:16 +090056 allowed_values=('linux', 'cell', 'winddk')))
José Fonseca58a3d7d2008-02-23 19:49:08 +090057opts.Add(ListOption('statetrackers', 'state_trackers to build', default_statetrackers,
José Fonseca26c57d12008-02-23 00:46:40 +090058 [
59 'mesa',
60 ],
61 ))
José Fonseca58a3d7d2008-02-23 19:49:08 +090062opts.Add(ListOption('drivers', 'pipe drivers to build', default_drivers,
63 [
64 'softpipe',
65 'failover',
66 'i915simple',
67 'i965simple',
68 'cell',
69 ],
70 ))
71opts.Add(ListOption('winsys', 'winsys drivers to build', default_winsys,
72 [
73 'xlib',
74 'intel',
75 ],
76 ))
77opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
78opts.Add(BoolOption('dri', 'build DRI drivers', 'no'))
José Fonsecac42e6252008-01-31 13:14:35 +090079
José Fonseca81b6a802008-02-06 14:36:50 +090080env = Environment(
81 options = opts,
82 ENV = os.environ)
José Fonsecac42e6252008-01-31 13:14:35 +090083Help(opts.GenerateHelpText(env))
84
85# for debugging
86#print env.Dump()
87
José Fonsecac42e6252008-01-31 13:14:35 +090088# replicate options values in local variables
89debug = env['debug']
90dri = env['dri']
José Fonsecae773a812008-02-19 10:50:39 +090091llvm = env['llvm']
José Fonsecac42e6252008-01-31 13:14:35 +090092machine = env['machine']
José Fonsecad710a7c2008-02-19 18:53:16 +090093platform = env['platform']
José Fonsecac42e6252008-01-31 13:14:35 +090094
95# derived options
96x86 = machine == 'x86'
José Fonsecad710a7c2008-02-19 18:53:16 +090097gcc = platform in ('linux', 'freebsd', 'darwin')
98msvc = platform in ('win32', 'winddk')
José Fonsecac42e6252008-01-31 13:14:35 +090099
100Export([
101 'debug',
102 'x86',
103 'dri',
José Fonsecae773a812008-02-19 10:50:39 +0900104 'llvm',
José Fonsecac42e6252008-01-31 13:14:35 +0900105 'platform',
106 'gcc',
107 'msvc',
108])
109
110
111#######################################################################
112# Environment setup
113#
José Fonsecad710a7c2008-02-19 18:53:16 +0900114# TODO: put the compiler specific settings in separate files
José Fonsecac42e6252008-01-31 13:14:35 +0900115# TODO: auto-detect as much as possible
116
José Fonsecad710a7c2008-02-19 18:53:16 +0900117
118if platform == 'winddk':
119 import ntpath
120 escape = env['ESCAPE']
José Fonseca58a3d7d2008-02-23 19:49:08 +0900121 env.Tool('winddk', '.')
José Fonsecad710a7c2008-02-19 18:53:16 +0900122 if 'BASEDIR' in os.environ:
123 WINDDK = os.environ['BASEDIR']
124 else:
125 WINDDK = "C:\\WINDDK\\3790.1830"
126 # NOTE: We need this elaborate construct to get the absolute paths and
127 # forward slashes to msvc unharmed when cross compiling from posix platforms
128 env.Append(CPPFLAGS = [
129 escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wxp')),
130 escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wdm\\wxp')),
131 escape('/I' + ntpath.join(WINDDK, 'inc\\crt')),
132 ])
133 env.Append(CPPDEFINES = [
134 ('i386', '1'),
135 ])
136 if debug:
137 env.Append(CPPDEFINES = ['DBG'])
138
139
José Fonsecac42e6252008-01-31 13:14:35 +0900140# Optimization flags
141if gcc:
142 if debug:
143 env.Append(CFLAGS = '-O0 -g3')
144 env.Append(CXXFLAGS = '-O0 -g3')
145 else:
146 env.Append(CFLAGS = '-O3 -g3')
147 env.Append(CXXFLAGS = '-O3 -g3')
148
José Fonseca26c57d12008-02-23 00:46:40 +0900149 env.Append(CFLAGS = '-Wall -Wmissing-prototypes -Wno-long-long -ffast-math -pedantic')
José Fonsecac42e6252008-01-31 13:14:35 +0900150 env.Append(CXXFLAGS = '-Wall -pedantic')
151
152 # Be nice to Eclipse
153 env.Append(CFLAGS = '-fmessage-length=0')
154 env.Append(CXXFLAGS = '-fmessage-length=0')
155
José Fonsecac42e6252008-01-31 13:14:35 +0900156
José Fonseca00137962008-02-07 19:59:17 +0900157# Defines
José Fonsecac42e6252008-01-31 13:14:35 +0900158if debug:
159 env.Append(CPPDEFINES = ['DEBUG'])
160else:
161 env.Append(CPPDEFINES = ['NDEBUG'])
162
163
164# Includes
165env.Append(CPPPATH = [
166 '#/include',
José Fonseca33ceb672008-02-18 10:52:44 +0000167 '#/src/gallium/include',
168 '#/src/gallium/auxiliary',
169 '#/src/gallium/drivers',
José Fonsecac42e6252008-01-31 13:14:35 +0900170])
171
172
173# x86 assembly
174if x86:
175 env.Append(CPPDEFINES = [
176 'USE_X86_ASM',
177 'USE_MMX_ASM',
178 'USE_3DNOW_ASM',
179 'USE_SSE_ASM',
180 ])
181 if gcc:
182 env.Append(CFLAGS = '-m32')
183 env.Append(CXXFLAGS = '-m32')
184
José Fonsecac42e6252008-01-31 13:14:35 +0900185
José Fonseca00137962008-02-07 19:59:17 +0900186# Posix
187if platform in ('posix', 'linux', 'freebsd', 'darwin'):
188 env.Append(CPPDEFINES = [
189 '_POSIX_SOURCE',
190 ('_POSIX_C_SOURCE', '199309L'),
191 '_SVID_SOURCE',
192 '_BSD_SOURCE',
193 '_GNU_SOURCE',
194
195 'PTHREADS',
196 'HAVE_POSIX_MEMALIGN',
197 ])
198 env.Append(CPPPATH = ['/usr/X11R6/include'])
199 env.Append(LIBPATH = ['/usr/X11R6/lib'])
200 env.Append(LIBS = [
201 'm',
202 'pthread',
203 'expat',
204 'dl',
205 ])
206
José Fonsecac42e6252008-01-31 13:14:35 +0900207
208# DRI
209if dri:
210 env.ParseConfig('pkg-config --cflags --libs libdrm')
211 env.Append(CPPDEFINES = [
212 ('USE_EXTERNAL_DXTN_LIB', '1'),
213 'IN_DRI_DRIVER',
214 'GLX_DIRECT_RENDERING',
215 'GLX_INDIRECT_RENDERING',
216 ])
217
José Fonsecae773a812008-02-19 10:50:39 +0900218# LLVM
219if llvm:
220 # See also http://www.scons.org/wiki/UsingPkgConfig
221 env.ParseConfig('llvm-config --cflags --ldflags --libs')
222 env.Append(CPPDEFINES = ['MESA_LLVM'])
223 env.Append(CXXFLAGS = ['-Wno-long-long'])
224
225
José Fonsecac42e6252008-01-31 13:14:35 +0900226# libGL
227if 1:
228 env.Append(LIBS = [
229 'X11',
230 'Xext',
231 'Xxf86vm',
232 'Xdamage',
233 'Xfixes',
234 ])
235
236Export('env')
237
238
239#######################################################################
240# Convenience Library Builder
241# based on the stock StaticLibrary and SharedLibrary builders
242
243def createConvenienceLibBuilder(env):
244 """This is a utility function that creates the ConvenienceLibrary
245 Builder in an Environment if it is not there already.
246
247 If it is already there, we return the existing one.
248 """
249
250 try:
251 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
252 except KeyError:
253 action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
254 if env.Detect('ranlib'):
255 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
256 action_list.append(ranlib_action)
257
258 convenience_lib = Builder(action = action_list,
259 emitter = '$LIBEMITTER',
260 prefix = '$LIBPREFIX',
261 suffix = '$LIBSUFFIX',
262 src_suffix = '$SHOBJSUFFIX',
263 src_builder = 'SharedObject')
264 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
265 env['BUILDERS']['Library'] = convenience_lib
266
267 return convenience_lib
268
269createConvenienceLibBuilder(env)
270
271
272#######################################################################
273# Invoke SConscripts
274
José Fonsecaf4192cb42008-01-31 14:21:49 +0900275# Put build output in a separate dir, which depends on the current configuration
276# See also http://www.scons.org/wiki/AdvancedBuildExample
277build_topdir = 'build'
278build_subdir = platform
279if dri:
280 build_subdir += "-dri"
José Fonsecae773a812008-02-19 10:50:39 +0900281if llvm:
282 build_subdir += "-llvm"
José Fonsecaf4192cb42008-01-31 14:21:49 +0900283if x86:
284 build_subdir += "-x86"
285if debug:
286 build_subdir += "-debug"
287build_dir = os.path.join(build_topdir, build_subdir)
288
289# TODO: Build several variants at the same time?
290# http://www.scons.org/wiki/SimultaneousVariantBuilds
José Fonsecac42e6252008-01-31 13:14:35 +0900291
292SConscript(
José Fonseca33ceb672008-02-18 10:52:44 +0000293 'src/SConscript',
José Fonsecac42e6252008-01-31 13:14:35 +0900294 build_dir = build_dir,
295 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
296)