blob: f4438cf546a0892317baccf05221fb28174342b3 [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)
37default_drivers = 'all'
38if default_platform in ('linux', 'freebsd', 'darwin'):
39 default_x11 = 'yes'
40else:
41 default_x11 = 'no'
José Fonsecad710a7c2008-02-19 18:53:16 +090042
José Fonsecac42e6252008-01-31 13:14:35 +090043# TODO: auto-detect defaults
44opts = Options('config.py')
45opts.Add(BoolOption('debug', 'build debug version', False))
José Fonsecac42e6252008-01-31 13:14:35 +090046opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
47 allowed_values=('generic', 'x86', 'x86-64')))
José Fonseca26c57d12008-02-23 00:46:40 +090048opts.Add(EnumOption('platform', 'target platform', default_platform,
José Fonsecad710a7c2008-02-19 18:53:16 +090049 allowed_values=('linux', 'cell', 'winddk')))
José Fonseca26c57d12008-02-23 00:46:40 +090050opts.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# ))
64opts.Add(BoolOption('llvm', 'use llvm', False))
65opts.Add(BoolOption('dri', 'build dri drivers', False))
66opts.Add(BoolOption('x11', 'build x11 driver', default_x11))
José Fonsecac42e6252008-01-31 13:14:35 +090067
José Fonseca81b6a802008-02-06 14:36:50 +090068env = Environment(
69 options = opts,
70 ENV = os.environ)
José Fonsecac42e6252008-01-31 13:14:35 +090071Help(opts.GenerateHelpText(env))
72
73# for debugging
74#print env.Dump()
75
José Fonsecac42e6252008-01-31 13:14:35 +090076# replicate options values in local variables
77debug = env['debug']
78dri = env['dri']
José Fonsecae773a812008-02-19 10:50:39 +090079llvm = env['llvm']
José Fonsecac42e6252008-01-31 13:14:35 +090080machine = env['machine']
José Fonsecad710a7c2008-02-19 18:53:16 +090081platform = env['platform']
José Fonsecac42e6252008-01-31 13:14:35 +090082
83# derived options
84x86 = machine == 'x86'
José Fonsecad710a7c2008-02-19 18:53:16 +090085gcc = platform in ('linux', 'freebsd', 'darwin')
86msvc = platform in ('win32', 'winddk')
José Fonsecac42e6252008-01-31 13:14:35 +090087
88Export([
89 'debug',
90 'x86',
91 'dri',
José Fonsecae773a812008-02-19 10:50:39 +090092 'llvm',
José Fonsecac42e6252008-01-31 13:14:35 +090093 'platform',
94 'gcc',
95 'msvc',
96])
97
98
99#######################################################################
100# Environment setup
101#
José Fonsecad710a7c2008-02-19 18:53:16 +0900102# TODO: put the compiler specific settings in separate files
José Fonsecac42e6252008-01-31 13:14:35 +0900103# TODO: auto-detect as much as possible
104
José Fonsecad710a7c2008-02-19 18:53:16 +0900105
106if 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
José Fonsecac42e6252008-01-31 13:14:35 +0900128# Optimization flags
129if 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
José Fonseca26c57d12008-02-23 00:46:40 +0900137 env.Append(CFLAGS = '-Wall -Wmissing-prototypes -Wno-long-long -ffast-math -pedantic')
José Fonsecac42e6252008-01-31 13:14:35 +0900138 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
José Fonsecac42e6252008-01-31 13:14:35 +0900144
José Fonseca00137962008-02-07 19:59:17 +0900145# Defines
José Fonsecac42e6252008-01-31 13:14:35 +0900146if debug:
147 env.Append(CPPDEFINES = ['DEBUG'])
148else:
149 env.Append(CPPDEFINES = ['NDEBUG'])
150
151
152# Includes
153env.Append(CPPPATH = [
154 '#/include',
José Fonseca33ceb672008-02-18 10:52:44 +0000155 '#/src/gallium/include',
156 '#/src/gallium/auxiliary',
157 '#/src/gallium/drivers',
José Fonsecac42e6252008-01-31 13:14:35 +0900158])
159
160
161# x86 assembly
162if 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
José Fonsecac42e6252008-01-31 13:14:35 +0900173
José Fonseca00137962008-02-07 19:59:17 +0900174# Posix
175if 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
José Fonsecac42e6252008-01-31 13:14:35 +0900195
196# DRI
197if 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
José Fonsecae773a812008-02-19 10:50:39 +0900206# LLVM
207if 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
José Fonsecac42e6252008-01-31 13:14:35 +0900214# libGL
215if 1:
216 env.Append(LIBS = [
217 'X11',
218 'Xext',
219 'Xxf86vm',
220 'Xdamage',
221 'Xfixes',
222 ])
223
224Export('env')
225
226
227#######################################################################
228# Convenience Library Builder
229# based on the stock StaticLibrary and SharedLibrary builders
230
231def 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
257createConvenienceLibBuilder(env)
258
259
260#######################################################################
261# Invoke SConscripts
262
José Fonsecaf4192cb42008-01-31 14:21:49 +0900263# Put build output in a separate dir, which depends on the current configuration
264# See also http://www.scons.org/wiki/AdvancedBuildExample
265build_topdir = 'build'
266build_subdir = platform
267if dri:
268 build_subdir += "-dri"
José Fonsecae773a812008-02-19 10:50:39 +0900269if llvm:
270 build_subdir += "-llvm"
José Fonsecaf4192cb42008-01-31 14:21:49 +0900271if x86:
272 build_subdir += "-x86"
273if debug:
274 build_subdir += "-debug"
275build_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
José Fonsecac42e6252008-01-31 13:14:35 +0900279
280SConscript(
José Fonseca33ceb672008-02-18 10:52:44 +0000281 'src/SConscript',
José Fonsecac42e6252008-01-31 13:14:35 +0900282 build_dir = build_dir,
283 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
284)