Initial scons support to build gallivm.
[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/mesa',
113 '#/src/mesa/main',
114 '#/src/gallium/include',
115 '#/src/gallium/auxiliary',
116 '#/src/gallium/drivers',
117 ])
118
119
120 # x86 assembly
121 if x86:
122 env.Append(CPPDEFINES = [
123 'USE_X86_ASM',
124 'USE_MMX_ASM',
125 'USE_3DNOW_ASM',
126 'USE_SSE_ASM',
127 ])
128 if gcc:
129 env.Append(CFLAGS = '-m32')
130 env.Append(CXXFLAGS = '-m32')
131
132
133 # Posix
134 if platform in ('posix', 'linux', 'freebsd', 'darwin'):
135 env.Append(CPPDEFINES = [
136 '_POSIX_SOURCE',
137 ('_POSIX_C_SOURCE', '199309L'),
138 '_SVID_SOURCE',
139 '_BSD_SOURCE',
140 '_GNU_SOURCE',
141
142 'PTHREADS',
143 'HAVE_POSIX_MEMALIGN',
144 ])
145 env.Append(CPPPATH = ['/usr/X11R6/include'])
146 env.Append(LIBPATH = ['/usr/X11R6/lib'])
147 env.Append(LIBS = [
148 'm',
149 'pthread',
150 'expat',
151 'dl',
152 ])
153
154
155 # DRI
156 if dri:
157 env.ParseConfig('pkg-config --cflags --libs libdrm')
158 env.Append(CPPDEFINES = [
159 ('USE_EXTERNAL_DXTN_LIB', '1'),
160 'IN_DRI_DRIVER',
161 'GLX_DIRECT_RENDERING',
162 'GLX_INDIRECT_RENDERING',
163 ])
164
165 # LLVM
166 if llvm:
167 # See also http://www.scons.org/wiki/UsingPkgConfig
168 env.ParseConfig('llvm-config --cflags --ldflags --libs')
169 env.Append(CPPDEFINES = ['MESA_LLVM'])
170 env.Append(CXXFLAGS = ['-Wno-long-long'])
171
172
173 # libGL
174 if 1:
175 env.Append(LIBS = [
176 'X11',
177 'Xext',
178 'Xxf86vm',
179 'Xdamage',
180 'Xfixes',
181 ])
182
183 Export('env')
184
185
186 #######################################################################
187 # Convenience Library Builder
188 # based on the stock StaticLibrary and SharedLibrary builders
189
190 def createConvenienceLibBuilder(env):
191 """This is a utility function that creates the ConvenienceLibrary
192 Builder in an Environment if it is not there already.
193
194 If it is already there, we return the existing one.
195 """
196
197 try:
198 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
199 except KeyError:
200 action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
201 if env.Detect('ranlib'):
202 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
203 action_list.append(ranlib_action)
204
205 convenience_lib = Builder(action = action_list,
206 emitter = '$LIBEMITTER',
207 prefix = '$LIBPREFIX',
208 suffix = '$LIBSUFFIX',
209 src_suffix = '$SHOBJSUFFIX',
210 src_builder = 'SharedObject')
211 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
212 env['BUILDERS']['Library'] = convenience_lib
213
214 return convenience_lib
215
216 createConvenienceLibBuilder(env)
217
218
219 #######################################################################
220 # Invoke SConscripts
221
222 # Put build output in a separate dir, which depends on the current configuration
223 # See also http://www.scons.org/wiki/AdvancedBuildExample
224 build_topdir = 'build'
225 build_subdir = platform
226 if dri:
227 build_subdir += "-dri"
228 if llvm:
229 build_subdir += "-llvm"
230 if x86:
231 build_subdir += "-x86"
232 if debug:
233 build_subdir += "-debug"
234 build_dir = os.path.join(build_topdir, build_subdir)
235
236 # TODO: Build several variants at the same time?
237 # http://www.scons.org/wiki/SimultaneousVariantBuilds
238
239 SConscript(
240 'src/SConscript',
241 build_dir = build_dir,
242 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
243 )