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