Allow the environment to override certain flags.
[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 default_statetrackers = 'mesa'
33
34 if common.default_platform in ('linux', 'freebsd', 'darwin'):
35         default_drivers = 'softpipe,failover,svga,i915,i965,trace,identity,llvmpipe'
36         default_winsys = 'xlib'
37 elif common.default_platform in ('winddk',):
38         default_drivers = 'softpipe,svga,i915,i965,trace,identity'
39         default_winsys = 'all'
40 else:
41         default_drivers = 'all'
42         default_winsys = 'all'
43
44 opts = Variables('config.py')
45 common.AddOptions(opts)
46 opts.Add(ListVariable('statetrackers', 'state trackers to build', default_statetrackers,
47                      ['mesa', 'python', 'xorg']))
48 opts.Add(ListVariable('drivers', 'pipe drivers to build', default_drivers,
49                      ['softpipe', 'failover', 'svga', 'i915', 'i965', 'trace', 'r300', 'identity', 'llvmpipe']))
50 opts.Add(ListVariable('winsys', 'winsys drivers to build', default_winsys,
51                      ['xlib', 'vmware', 'intel', 'i965', 'gdi', 'radeon']))
52
53 opts.Add(EnumVariable('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))
54
55 env = Environment(
56         options = opts,
57         tools = ['gallium'],
58         toolpath = ['#scons'],  
59         ENV = os.environ,
60 )
61
62 if os.environ.has_key('CC'):
63         env['CC'] = os.environ['CC']
64 if os.environ.has_key('CFLAGS'):
65         env['CCFLAGS'] += SCons.Util.CLVar(os.environ['CFLAGS'])
66 if os.environ.has_key('CXX'):
67         env['CXX'] = os.environ['CXX']
68 if os.environ.has_key('CXXFLAGS'):
69         env['CXXFLAGS'] += SCons.Util.CLVar(os.environ['CXXFLAGS'])
70 if os.environ.has_key('LDFLAGS'):
71         env['LINKFLAGS'] += SCons.Util.CLVar(os.environ['LDFLAGS'])
72
73 Help(opts.GenerateHelpText(env))
74
75 # replicate options values in local variables
76 debug = env['debug']
77 dri = env['dri']
78 llvm = env['llvm']
79 machine = env['machine']
80 platform = env['platform']
81
82 # derived options
83 x86 = machine == 'x86'
84 ppc = machine == 'ppc'
85 gcc = platform in ('linux', 'freebsd', 'darwin')
86 msvc = platform in ('windows', 'winddk')
87
88 Export([
89         'debug', 
90         'x86', 
91         'ppc', 
92         'dri', 
93         'llvm',
94         'platform',
95         'gcc',
96         'msvc',
97 ])
98
99
100 #######################################################################
101 # Environment setup
102
103 # Includes
104 env.Append(CPPPATH = [
105         '#/include',
106         '#/src/gallium/include',
107         '#/src/gallium/auxiliary',
108         '#/src/gallium/drivers',
109 ])
110
111 if env['msvc']:
112     env.Append(CPPPATH = ['#include/c99'])
113
114
115 # Posix
116 if platform in ('posix', 'linux', 'freebsd', 'darwin'):
117         env.Append(CPPDEFINES = [
118                 '_POSIX_SOURCE',
119                 ('_POSIX_C_SOURCE', '199309L'), 
120                 '_SVID_SOURCE',
121                 '_BSD_SOURCE', 
122                 '_GNU_SOURCE',
123                 
124                 'PTHREADS',
125                 'HAVE_POSIX_MEMALIGN',
126         ])
127         if platform == 'darwin':
128                 env.Append(CPPDEFINES = ['_DARWIN_C_SOURCE'])
129         env.Append(CPPPATH = ['/usr/X11R6/include'])
130         env.Append(LIBPATH = ['/usr/X11R6/lib'])
131         env.Append(LIBS = [
132                 'm',
133                 'pthread',
134                 'expat',
135                 'dl',
136         ])
137
138
139 # DRI
140 if dri:
141         env.ParseConfig('pkg-config --cflags --libs libdrm')
142         env.Append(CPPDEFINES = [
143                 ('USE_EXTERNAL_DXTN_LIB', '1'), 
144                 'IN_DRI_DRIVER',
145                 'GLX_DIRECT_RENDERING',
146                 'GLX_INDIRECT_RENDERING',
147         ])
148
149 # LLVM
150 if llvm:
151         # See also http://www.scons.org/wiki/UsingPkgConfig
152         env.ParseConfig('llvm-config --cflags --ldflags --libs backend bitreader engine instrumentation interpreter ipo')
153         env.Append(CPPDEFINES = ['MESA_LLVM'])
154         # Force C++ linkage
155         env['LINK'] = env['CXX']
156
157 # libGL
158 if platform in ('linux', 'freebsd', 'darwin'):
159         env.Append(LIBS = [
160                 'X11',
161                 'Xext',
162                 'Xxf86vm',
163                 'Xdamage',
164                 'Xfixes',
165         ])
166
167 # for debugging
168 #print env.Dump()
169
170 Export('env')
171
172
173 #######################################################################
174 # Invoke SConscripts
175
176 # TODO: Build several variants at the same time?
177 # http://www.scons.org/wiki/SimultaneousVariantBuilds
178
179 if env['platform'] != common.default_platform:
180     # GLSL code has to be built twice -- one for the host OS, another for the target OS...
181
182     host_env = Environment(
183         # options are ignored
184         # default tool is used
185         tools = ['default', 'custom'],
186         toolpath = ['#scons'],  
187         ENV = os.environ,
188     )
189
190     host_env['platform'] = common.default_platform
191     host_env['machine'] = common.default_machine
192     host_env['debug'] = env['debug']
193
194     SConscript(
195         'src/glsl/SConscript',
196         variant_dir = os.path.join(env['build'], 'host'),
197         duplicate = 0, # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
198         exports={'env':host_env},
199     )
200
201 SConscript(
202         'src/SConscript',
203         variant_dir = env['build'],
204         duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
205 )
206
207 SConscript(
208         'progs/SConscript',
209         variant_dir = os.path.join('progs', env['build']),
210         duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
211 )