gallium: Only use C++ compiler for linking when using LLVM.
[mesa.git] / SConstruct
1 #######################################################################
2 # Top-level SConstruct
3 #
4 # For example, invoke scons as
5 #
6 # scons debug=1 dri=0 machine=x86
7 #
8 # to set configuration variables. Or you can write those options to a file
9 # named config.py:
10 #
11 # # config.py
12 # debug=1
13 # dri=0
14 # machine='x86'
15 #
16 # Invoke
17 #
18 # scons -h
19 #
20 # to get the full list of options. See scons manpage for more info.
21 #
22
23 import os
24 import os.path
25 import sys
26
27 import common
28
29 #######################################################################
30 # Configuration options
31
32 if common.default_platform in ('linux', 'freebsd', 'darwin'):
33 default_statetrackers = 'mesa'
34 default_drivers = 'softpipe,failover,i915simple,i965simple'
35 default_winsys = 'xlib'
36 elif common.default_platform in ('winddk',):
37 default_statetrackers = 'none'
38 default_drivers = 'softpipe,i915simple'
39 default_winsys = 'none'
40 else:
41 default_drivers = 'all'
42 default_winsys = 'all'
43
44 opts = Options('config.py')
45 common.AddOptions(opts)
46 opts.Add(ListOption('statetrackers', 'state_trackers to build', default_statetrackers,
47 ['mesa']))
48 opts.Add(ListOption('drivers', 'pipe drivers to build', default_drivers,
49 ['softpipe', 'failover', 'i915simple', 'i965simple', 'cell']))
50 opts.Add(ListOption('winsys', 'winsys drivers to build', default_winsys,
51 ['xlib', 'intel']))
52
53 env = Environment(
54 options = opts,
55 ENV = os.environ)
56 Help(opts.GenerateHelpText(env))
57
58 # for debugging
59 #print env.Dump()
60
61 # replicate options values in local variables
62 debug = env['debug']
63 dri = env['dri']
64 llvm = env['llvm']
65 machine = env['machine']
66 platform = env['platform']
67
68 # derived options
69 x86 = machine == 'x86'
70 gcc = platform in ('linux', 'freebsd', 'darwin')
71 msvc = platform in ('win32', 'winddk')
72
73 Export([
74 'debug',
75 'x86',
76 'dri',
77 'llvm',
78 'platform',
79 'gcc',
80 'msvc',
81 ])
82
83
84 #######################################################################
85 # Environment setup
86 #
87 # TODO: put the compiler specific settings in separate files
88 # TODO: auto-detect as much as possible
89
90
91 if platform == 'winddk':
92 env.Tool('winddk', ['.'])
93
94 env.Append(CPPPATH = [
95 env['SDK_INC_PATH'],
96 env['DDK_INC_PATH'],
97 env['WDM_INC_PATH'],
98 env['CRT_INC_PATH'],
99 ])
100
101 # Optimization flags
102 if gcc:
103 if debug:
104 env.Append(CFLAGS = '-O0 -g3')
105 env.Append(CXXFLAGS = '-O0 -g3')
106 else:
107 env.Append(CFLAGS = '-O3 -g3')
108 env.Append(CXXFLAGS = '-O3 -g3')
109
110 env.Append(CFLAGS = '-Wall -Wmissing-prototypes -Wno-long-long -ffast-math -pedantic')
111 env.Append(CXXFLAGS = '-Wall -pedantic')
112
113 # Be nice to Eclipse
114 env.Append(CFLAGS = '-fmessage-length=0')
115 env.Append(CXXFLAGS = '-fmessage-length=0')
116
117 if msvc:
118 env.Append(CFLAGS = '/W3')
119 if debug:
120 cflags = [
121 '/Od', # disable optimizations
122 '/Oy-', # disable frame pointer omission
123 ]
124 else:
125 cflags = [
126 '/Ox', # maximum optimizations
127 '/Os', # favor code space
128 ]
129 env.Append(CFLAGS = cflags)
130 env.Append(CXXFLAGS = cflags)
131 # Put debugging information in a separate .pdb file for each object file as
132 # descrived in the scons manpage
133 env['CCPDBFLAGS'] = '/Zi /Fd${TARGET}.pdb'
134
135 # Defines
136 if debug:
137 if gcc:
138 env.Append(CPPDEFINES = ['DEBUG'])
139 if msvc:
140 env.Append(CPPDEFINES = [
141 ('DBG', '1'),
142 ('DEBUG', '1'),
143 ('_DEBUG', '1'),
144 ])
145 else:
146 env.Append(CPPDEFINES = ['NDEBUG'])
147
148
149 # Includes
150 env.Append(CPPPATH = [
151 '#/include',
152 '#/src/gallium/include',
153 '#/src/gallium/auxiliary',
154 '#/src/gallium/drivers',
155 ])
156
157
158 # x86 assembly
159 if x86:
160 env.Append(CPPDEFINES = [
161 'USE_X86_ASM',
162 'USE_MMX_ASM',
163 'USE_3DNOW_ASM',
164 'USE_SSE_ASM',
165 ])
166 if gcc:
167 env.Append(CFLAGS = '-m32')
168 env.Append(CXXFLAGS = '-m32')
169
170
171 # Posix
172 if platform in ('posix', 'linux', 'freebsd', 'darwin'):
173 env.Append(CPPDEFINES = [
174 '_POSIX_SOURCE',
175 ('_POSIX_C_SOURCE', '199309L'),
176 '_SVID_SOURCE',
177 '_BSD_SOURCE',
178 '_GNU_SOURCE',
179
180 'PTHREADS',
181 'HAVE_POSIX_MEMALIGN',
182 ])
183 env.Append(CPPPATH = ['/usr/X11R6/include'])
184 env.Append(LIBPATH = ['/usr/X11R6/lib'])
185 env.Append(LIBS = [
186 'm',
187 'pthread',
188 'expat',
189 'dl',
190 ])
191
192
193 # DRI
194 if dri:
195 env.ParseConfig('pkg-config --cflags --libs libdrm')
196 env.Append(CPPDEFINES = [
197 ('USE_EXTERNAL_DXTN_LIB', '1'),
198 'IN_DRI_DRIVER',
199 'GLX_DIRECT_RENDERING',
200 'GLX_INDIRECT_RENDERING',
201 ])
202
203 # LLVM
204 if llvm:
205 # See also http://www.scons.org/wiki/UsingPkgConfig
206 env.ParseConfig('llvm-config --cflags --ldflags --libs')
207 env.Append(CPPDEFINES = ['MESA_LLVM'])
208 env.Append(CXXFLAGS = ['-Wno-long-long'])
209 # Force C++ linkage
210 env['LINK'] = env['CXX']
211
212 # libGL
213 if platform not in ('winddk',):
214 env.Append(LIBS = [
215 'X11',
216 'Xext',
217 'Xxf86vm',
218 'Xdamage',
219 'Xfixes',
220 ])
221
222 # Convenience library support
223 common.createConvenienceLibBuilder(env)
224
225 Export('env')
226
227
228 #######################################################################
229 # Invoke SConscripts
230
231 # TODO: Build several variants at the same time?
232 # http://www.scons.org/wiki/SimultaneousVariantBuilds
233
234 SConscript(
235 'src/SConscript',
236 build_dir = common.make_build_dir(env),
237 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
238 )