gallium: Make the build output dir depend on the configuration.
[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 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
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(EnumOption('machine', 'use machine-specific assembly code', 'x86',
36 allowed_values=('generic', 'x86', 'x86-64')))
37
38 env = Environment(options = opts)
39 Help(opts.GenerateHelpText(env))
40
41 # for debugging
42 #print env.Dump()
43
44 if 0:
45 # platform will be typically 'posix' or 'win32'
46 platform = env['PLATFORM']
47 else:
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
54 debug = env['debug']
55 dri = env['dri']
56 machine = env['machine']
57
58 # derived options
59 x86 = machine == 'x86'
60 gcc = platform in ('posix', 'linux', 'freebsd', 'darwin')
61 msvc = platform == 'win32'
62
63 Export([
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
81 if 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
97 env.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
109 if debug:
110 env.Append(CPPDEFINES = ['DEBUG'])
111 else:
112 env.Append(CPPDEFINES = ['NDEBUG'])
113
114
115 # Includes
116 env.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
127 if 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
138 env.Append(LIBPATH = ['/usr/X11R6/lib'])
139
140 env.Append(LIBS = [
141 'm',
142 'pthread',
143 'expat',
144 'dl',
145 ])
146
147 # DRI
148 if 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
158 if 1:
159 env.Append(LIBS = [
160 'X11',
161 'Xext',
162 'Xxf86vm',
163 'Xdamage',
164 'Xfixes',
165 ])
166
167 Export('env')
168
169
170 #######################################################################
171 # Convenience Library Builder
172 # based on the stock StaticLibrary and SharedLibrary builders
173
174 def 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
200 createConvenienceLibBuilder(env)
201
202
203 #######################################################################
204 # Invoke SConscripts
205
206 # Put build output in a separate dir, which depends on the current configuration
207 # See also http://www.scons.org/wiki/AdvancedBuildExample
208 build_topdir = 'build'
209 build_subdir = platform
210 if dri:
211 build_subdir += "-dri"
212 if x86:
213 build_subdir += "-x86"
214 if debug:
215 build_subdir += "-debug"
216 build_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
220
221 SConscript(
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 )