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