blob: 01732b0c5287f7e4734eb0cb26cff52e1bc01e40 [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#
14# scons debug=1 dri=0 x86=1
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# x86=1
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# TODO: auto-detect defaults
32opts = Options('config.py')
33opts.Add(BoolOption('debug', 'build debug version', False))
34opts.Add(BoolOption('dri', 'build dri drivers', False))
35opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
36 allowed_values=('generic', 'x86', 'x86-64')))
37
38env = Environment(options = opts)
39Help(opts.GenerateHelpText(env))
40
41# for debugging
42#print env.Dump()
43
José Fonsecaf4192cb42008-01-31 14:21:49 +090044if 0:
José Fonsecac42e6252008-01-31 13:14:35 +090045 # platform will be typically 'posix' or 'win32'
46 platform = env['PLATFORM']
47else:
48 # platform will be one of 'linux', 'freebsd', 'win32', 'darwin', etc.
49 platform = sys.platform
50 if platform == 'linux2':
51 platform = 'linux'
52
53# replicate options values in local variables
54debug = env['debug']
55dri = env['dri']
56machine = env['machine']
57
58# derived options
59x86 = machine == 'x86'
José Fonsecaf4192cb42008-01-31 14:21:49 +090060gcc = platform in ('posix', 'linux', 'freebsd', 'darwin')
José Fonsecac42e6252008-01-31 13:14:35 +090061msvc = platform == 'win32'
62
63Export([
64 'debug',
65 'x86',
66 'dri',
67 'platform',
68 'gcc',
69 'msvc',
70])
71
72
73#######################################################################
74# Environment setup
75#
76# TODO: put the compiler specific settings in seperate files
77# TODO: auto-detect as much as possible
78
79
80# Optimization flags
81if gcc:
82 if debug:
83 env.Append(CFLAGS = '-O0 -g3')
84 env.Append(CXXFLAGS = '-O0 -g3')
85 else:
86 env.Append(CFLAGS = '-O3 -g3')
87 env.Append(CXXFLAGS = '-O3 -g3')
88
89 env.Append(CFLAGS = '-Wall -Wmissing-prototypes -std=c99 -ffast-math -pedantic')
90 env.Append(CXXFLAGS = '-Wall -pedantic')
91
92 # Be nice to Eclipse
93 env.Append(CFLAGS = '-fmessage-length=0')
94 env.Append(CXXFLAGS = '-fmessage-length=0')
95
96# Defines
97env.Append(CPPDEFINES = [
98 '_POSIX_SOURCE',
99 ('_POSIX_C_SOURCE', '199309L'),
100 '_SVID_SOURCE',
101 '_BSD_SOURCE',
102 '_GNU_SOURCE',
103
104 'PTHREADS',
105 'HAVE_ALIAS',
106 'HAVE_POSIX_MEMALIGN',
107])
108
109if debug:
110 env.Append(CPPDEFINES = ['DEBUG'])
111else:
112 env.Append(CPPDEFINES = ['NDEBUG'])
113
114
115# Includes
116env.Append(CPPPATH = [
117 '#/include',
118 '#/src/mesa',
119 '#/src/mesa/main',
120 '#/src/mesa/pipe',
121
122 '/usr/X11R6/include',
123])
124
125
126# x86 assembly
127if x86:
128 env.Append(CPPDEFINES = [
129 'USE_X86_ASM',
130 'USE_MMX_ASM',
131 'USE_3DNOW_ASM',
132 'USE_SSE_ASM',
133 ])
134 if gcc:
135 env.Append(CFLAGS = '-m32')
136 env.Append(CXXFLAGS = '-m32')
137
138env.Append(LIBPATH = ['/usr/X11R6/lib'])
139
140env.Append(LIBS = [
141 'm',
142 'pthread',
143 'expat',
144 'dl',
145])
146
147# DRI
148if dri:
149 env.ParseConfig('pkg-config --cflags --libs libdrm')
150 env.Append(CPPDEFINES = [
151 ('USE_EXTERNAL_DXTN_LIB', '1'),
152 'IN_DRI_DRIVER',
153 'GLX_DIRECT_RENDERING',
154 'GLX_INDIRECT_RENDERING',
155 ])
156
157# libGL
158if 1:
159 env.Append(LIBS = [
160 'X11',
161 'Xext',
162 'Xxf86vm',
163 'Xdamage',
164 'Xfixes',
165 ])
166
167Export('env')
168
169
170#######################################################################
171# Convenience Library Builder
172# based on the stock StaticLibrary and SharedLibrary builders
173
174def createConvenienceLibBuilder(env):
175 """This is a utility function that creates the ConvenienceLibrary
176 Builder in an Environment if it is not there already.
177
178 If it is already there, we return the existing one.
179 """
180
181 try:
182 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
183 except KeyError:
184 action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
185 if env.Detect('ranlib'):
186 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
187 action_list.append(ranlib_action)
188
189 convenience_lib = Builder(action = action_list,
190 emitter = '$LIBEMITTER',
191 prefix = '$LIBPREFIX',
192 suffix = '$LIBSUFFIX',
193 src_suffix = '$SHOBJSUFFIX',
194 src_builder = 'SharedObject')
195 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
196 env['BUILDERS']['Library'] = convenience_lib
197
198 return convenience_lib
199
200createConvenienceLibBuilder(env)
201
202
203#######################################################################
204# Invoke SConscripts
205
José Fonsecaf4192cb42008-01-31 14:21:49 +0900206# Put build output in a separate dir, which depends on the current configuration
207# See also http://www.scons.org/wiki/AdvancedBuildExample
208build_topdir = 'build'
209build_subdir = platform
210if dri:
211 build_subdir += "-dri"
212if x86:
213 build_subdir += "-x86"
214if debug:
215 build_subdir += "-debug"
216build_dir = os.path.join(build_topdir, build_subdir)
217
218# TODO: Build several variants at the same time?
219# http://www.scons.org/wiki/SimultaneousVariantBuilds
José Fonsecac42e6252008-01-31 13:14:35 +0900220
221SConscript(
222 'src/mesa/SConscript',
223 build_dir = build_dir,
224 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
225)