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