blob: 219997ca914804f50cc1ee20a402bf52d0bd0bdd [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'
José Fonsecae70a4312008-02-24 16:43:07 +090042 default_dri = 'yes'
José Fonseca58a3d7d2008-02-23 19:49:08 +090043elif default_platform in ('winddk',):
44 default_statetrackers = 'none'
45 default_drivers = 'softpipe,i915simple'
46 default_winsys = 'none'
José Fonsecae70a4312008-02-24 16:43:07 +090047 default_dri = 'no'
José Fonseca26c57d12008-02-23 00:46:40 +090048else:
José Fonseca58a3d7d2008-02-23 19:49:08 +090049 default_drivers = 'all'
50 default_winsys = 'all'
José Fonsecae70a4312008-02-24 16:43:07 +090051 default_dri = 'no'
52
José Fonsecad710a7c2008-02-19 18:53:16 +090053
José Fonsecac42e6252008-01-31 13:14:35 +090054# TODO: auto-detect defaults
55opts = Options('config.py')
56opts.Add(BoolOption('debug', 'build debug version', False))
José Fonsecac42e6252008-01-31 13:14:35 +090057opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
58 allowed_values=('generic', 'x86', 'x86-64')))
José Fonseca26c57d12008-02-23 00:46:40 +090059opts.Add(EnumOption('platform', 'target platform', default_platform,
José Fonsecad710a7c2008-02-19 18:53:16 +090060 allowed_values=('linux', 'cell', 'winddk')))
José Fonseca58a3d7d2008-02-23 19:49:08 +090061opts.Add(ListOption('statetrackers', 'state_trackers to build', default_statetrackers,
José Fonseca26c57d12008-02-23 00:46:40 +090062 [
63 'mesa',
64 ],
65 ))
José Fonseca58a3d7d2008-02-23 19:49:08 +090066opts.Add(ListOption('drivers', 'pipe drivers to build', default_drivers,
67 [
68 'softpipe',
69 'failover',
70 'i915simple',
71 'i965simple',
72 'cell',
73 ],
74 ))
75opts.Add(ListOption('winsys', 'winsys drivers to build', default_winsys,
76 [
77 'xlib',
78 'intel',
79 ],
80 ))
81opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
José Fonsecae70a4312008-02-24 16:43:07 +090082opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
José Fonsecac42e6252008-01-31 13:14:35 +090083
José Fonseca81b6a802008-02-06 14:36:50 +090084env = Environment(
85 options = opts,
86 ENV = os.environ)
José Fonsecac42e6252008-01-31 13:14:35 +090087Help(opts.GenerateHelpText(env))
88
89# for debugging
90#print env.Dump()
91
José Fonsecac42e6252008-01-31 13:14:35 +090092# replicate options values in local variables
93debug = env['debug']
94dri = env['dri']
José Fonsecae773a812008-02-19 10:50:39 +090095llvm = env['llvm']
José Fonsecac42e6252008-01-31 13:14:35 +090096machine = env['machine']
José Fonsecad710a7c2008-02-19 18:53:16 +090097platform = env['platform']
José Fonsecac42e6252008-01-31 13:14:35 +090098
99# derived options
100x86 = machine == 'x86'
José Fonsecad710a7c2008-02-19 18:53:16 +0900101gcc = platform in ('linux', 'freebsd', 'darwin')
102msvc = platform in ('win32', 'winddk')
José Fonsecac42e6252008-01-31 13:14:35 +0900103
104Export([
105 'debug',
106 'x86',
107 'dri',
José Fonsecae773a812008-02-19 10:50:39 +0900108 'llvm',
José Fonsecac42e6252008-01-31 13:14:35 +0900109 'platform',
110 'gcc',
111 'msvc',
112])
113
114
115#######################################################################
116# Environment setup
117#
José Fonsecad710a7c2008-02-19 18:53:16 +0900118# TODO: put the compiler specific settings in separate files
José Fonsecac42e6252008-01-31 13:14:35 +0900119# TODO: auto-detect as much as possible
120
José Fonsecad710a7c2008-02-19 18:53:16 +0900121
122if platform == 'winddk':
123 import ntpath
124 escape = env['ESCAPE']
José Fonseca58a3d7d2008-02-23 19:49:08 +0900125 env.Tool('winddk', '.')
José Fonsecad710a7c2008-02-19 18:53:16 +0900126 if 'BASEDIR' in os.environ:
127 WINDDK = os.environ['BASEDIR']
128 else:
129 WINDDK = "C:\\WINDDK\\3790.1830"
130 # NOTE: We need this elaborate construct to get the absolute paths and
131 # forward slashes to msvc unharmed when cross compiling from posix platforms
José Fonsecae70a4312008-02-24 16:43:07 +0900132 #env.Append(CPPFLAGS = [
133 # escape('/I' + ntpath.join(WINDDK, 'inc\\wxp')),
134 # escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wxp')),
135 # escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wdm\\wxp')),
136 # escape('/I' + ntpath.join(WINDDK, 'inc\\crt')),
137 #])
José Fonsecad710a7c2008-02-19 18:53:16 +0900138
José Fonsecae70a4312008-02-24 16:43:07 +0900139 env.Append(CFLAGS = '/W3')
140 if debug:
141 env.Append(CPPDEFINES = [
142 ('DBG', '1'),
143 ('DEBUG', '1'),
144 ('_DEBUG', '1'),
145 ])
146 env.Append(CFLAGS = '/Od /Zi')
147 env.Append(CXXFLAGS = '/Od /Zi')
148
José Fonsecad710a7c2008-02-19 18:53:16 +0900149
José Fonsecac42e6252008-01-31 13:14:35 +0900150# Optimization flags
151if gcc:
152 if debug:
153 env.Append(CFLAGS = '-O0 -g3')
154 env.Append(CXXFLAGS = '-O0 -g3')
155 else:
156 env.Append(CFLAGS = '-O3 -g3')
157 env.Append(CXXFLAGS = '-O3 -g3')
158
José Fonseca26c57d12008-02-23 00:46:40 +0900159 env.Append(CFLAGS = '-Wall -Wmissing-prototypes -Wno-long-long -ffast-math -pedantic')
José Fonsecac42e6252008-01-31 13:14:35 +0900160 env.Append(CXXFLAGS = '-Wall -pedantic')
161
162 # Be nice to Eclipse
163 env.Append(CFLAGS = '-fmessage-length=0')
164 env.Append(CXXFLAGS = '-fmessage-length=0')
165
José Fonsecac42e6252008-01-31 13:14:35 +0900166
José Fonseca00137962008-02-07 19:59:17 +0900167# Defines
José Fonsecac42e6252008-01-31 13:14:35 +0900168if debug:
169 env.Append(CPPDEFINES = ['DEBUG'])
170else:
171 env.Append(CPPDEFINES = ['NDEBUG'])
172
173
174# Includes
175env.Append(CPPPATH = [
176 '#/include',
José Fonseca33ceb672008-02-18 10:52:44 +0000177 '#/src/gallium/include',
178 '#/src/gallium/auxiliary',
179 '#/src/gallium/drivers',
José Fonsecac42e6252008-01-31 13:14:35 +0900180])
181
182
183# x86 assembly
184if x86:
185 env.Append(CPPDEFINES = [
186 'USE_X86_ASM',
187 'USE_MMX_ASM',
188 'USE_3DNOW_ASM',
189 'USE_SSE_ASM',
190 ])
191 if gcc:
192 env.Append(CFLAGS = '-m32')
193 env.Append(CXXFLAGS = '-m32')
194
José Fonsecac42e6252008-01-31 13:14:35 +0900195
José Fonseca00137962008-02-07 19:59:17 +0900196# Posix
197if platform in ('posix', 'linux', 'freebsd', 'darwin'):
198 env.Append(CPPDEFINES = [
199 '_POSIX_SOURCE',
200 ('_POSIX_C_SOURCE', '199309L'),
201 '_SVID_SOURCE',
202 '_BSD_SOURCE',
203 '_GNU_SOURCE',
204
205 'PTHREADS',
206 'HAVE_POSIX_MEMALIGN',
207 ])
208 env.Append(CPPPATH = ['/usr/X11R6/include'])
209 env.Append(LIBPATH = ['/usr/X11R6/lib'])
210 env.Append(LIBS = [
211 'm',
212 'pthread',
213 'expat',
214 'dl',
215 ])
216
José Fonsecac42e6252008-01-31 13:14:35 +0900217
218# DRI
219if dri:
220 env.ParseConfig('pkg-config --cflags --libs libdrm')
221 env.Append(CPPDEFINES = [
222 ('USE_EXTERNAL_DXTN_LIB', '1'),
223 'IN_DRI_DRIVER',
224 'GLX_DIRECT_RENDERING',
225 'GLX_INDIRECT_RENDERING',
226 ])
227
José Fonsecae773a812008-02-19 10:50:39 +0900228# LLVM
229if llvm:
230 # See also http://www.scons.org/wiki/UsingPkgConfig
231 env.ParseConfig('llvm-config --cflags --ldflags --libs')
232 env.Append(CPPDEFINES = ['MESA_LLVM'])
233 env.Append(CXXFLAGS = ['-Wno-long-long'])
234
235
José Fonsecac42e6252008-01-31 13:14:35 +0900236# libGL
José Fonsecae70a4312008-02-24 16:43:07 +0900237if platform not in ('winddk',):
José Fonsecac42e6252008-01-31 13:14:35 +0900238 env.Append(LIBS = [
239 'X11',
240 'Xext',
241 'Xxf86vm',
242 'Xdamage',
243 'Xfixes',
244 ])
245
246Export('env')
247
248
249#######################################################################
250# Convenience Library Builder
251# based on the stock StaticLibrary and SharedLibrary builders
252
253def createConvenienceLibBuilder(env):
254 """This is a utility function that creates the ConvenienceLibrary
255 Builder in an Environment if it is not there already.
256
257 If it is already there, we return the existing one.
258 """
259
260 try:
261 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
262 except KeyError:
263 action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
264 if env.Detect('ranlib'):
265 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
266 action_list.append(ranlib_action)
267
268 convenience_lib = Builder(action = action_list,
269 emitter = '$LIBEMITTER',
270 prefix = '$LIBPREFIX',
271 suffix = '$LIBSUFFIX',
272 src_suffix = '$SHOBJSUFFIX',
273 src_builder = 'SharedObject')
274 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
275 env['BUILDERS']['Library'] = convenience_lib
276
277 return convenience_lib
278
279createConvenienceLibBuilder(env)
280
281
282#######################################################################
283# Invoke SConscripts
284
José Fonsecaf4192cb42008-01-31 14:21:49 +0900285# Put build output in a separate dir, which depends on the current configuration
286# See also http://www.scons.org/wiki/AdvancedBuildExample
287build_topdir = 'build'
288build_subdir = platform
289if dri:
290 build_subdir += "-dri"
José Fonsecae773a812008-02-19 10:50:39 +0900291if llvm:
292 build_subdir += "-llvm"
José Fonsecaf4192cb42008-01-31 14:21:49 +0900293if x86:
294 build_subdir += "-x86"
295if debug:
296 build_subdir += "-debug"
297build_dir = os.path.join(build_topdir, build_subdir)
298
299# TODO: Build several variants at the same time?
300# http://www.scons.org/wiki/SimultaneousVariantBuilds
José Fonsecac42e6252008-01-31 13:14:35 +0900301
302SConscript(
José Fonseca33ceb672008-02-18 10:52:44 +0000303 'src/SConscript',
José Fonsecac42e6252008-01-31 13:14:35 +0900304 build_dir = build_dir,
305 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
306)