blob: db6161ed5191c945ac8f23025db7cc00df139db6 [file] [log] [blame]
José Fonsecac42e6252008-01-31 13:14:35 +09001#######################################################################
2# Top-level SConstruct
3
4import os
5import sys
6
7
8#######################################################################
9# Configuration options
10#
11# For example, invoke scons as
12#
13# scons debug=1 dri=0 x86=1
14#
15# to set configuration variables. Or you can write those options to a file
16# named config.py:
17#
18# # config.py
19# debug=1
20# dri=0
21# x86=1
22#
23# Invoke
24#
25# scons -h
26#
27# to get the full list of options. See scons manpage for more info.
28#
29
30# TODO: auto-detect defaults
31opts = Options('config.py')
32opts.Add(BoolOption('debug', 'build debug version', False))
33opts.Add(BoolOption('dri', 'build dri drivers', False))
34opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
35 allowed_values=('generic', 'x86', 'x86-64')))
36
37env = Environment(options = opts)
38Help(opts.GenerateHelpText(env))
39
40# for debugging
41#print env.Dump()
42
43if 1:
44 # platform will be typically 'posix' or 'win32'
45 platform = env['PLATFORM']
46else:
47 # platform will be one of 'linux', 'freebsd', 'win32', 'darwin', etc.
48 platform = sys.platform
49 if platform == 'linux2':
50 platform = 'linux'
51
52# replicate options values in local variables
53debug = env['debug']
54dri = env['dri']
55machine = env['machine']
56
57# derived options
58x86 = machine == 'x86'
59gcc = platform == 'posix'
60msvc = platform == 'win32'
61
62Export([
63 'debug',
64 'x86',
65 'dri',
66 'platform',
67 'gcc',
68 'msvc',
69])
70
71
72#######################################################################
73# Environment setup
74#
75# TODO: put the compiler specific settings in seperate files
76# TODO: auto-detect as much as possible
77
78
79# Optimization flags
80if gcc:
81 if debug:
82 env.Append(CFLAGS = '-O0 -g3')
83 env.Append(CXXFLAGS = '-O0 -g3')
84 else:
85 env.Append(CFLAGS = '-O3 -g3')
86 env.Append(CXXFLAGS = '-O3 -g3')
87
88 env.Append(CFLAGS = '-Wall -Wmissing-prototypes -std=c99 -ffast-math -pedantic')
89 env.Append(CXXFLAGS = '-Wall -pedantic')
90
91 # Be nice to Eclipse
92 env.Append(CFLAGS = '-fmessage-length=0')
93 env.Append(CXXFLAGS = '-fmessage-length=0')
94
95# Defines
96env.Append(CPPDEFINES = [
97 '_POSIX_SOURCE',
98 ('_POSIX_C_SOURCE', '199309L'),
99 '_SVID_SOURCE',
100 '_BSD_SOURCE',
101 '_GNU_SOURCE',
102
103 'PTHREADS',
104 'HAVE_ALIAS',
105 'HAVE_POSIX_MEMALIGN',
106])
107
108if debug:
109 env.Append(CPPDEFINES = ['DEBUG'])
110else:
111 env.Append(CPPDEFINES = ['NDEBUG'])
112
113
114# Includes
115env.Append(CPPPATH = [
116 '#/include',
117 '#/src/mesa',
118 '#/src/mesa/main',
119 '#/src/mesa/pipe',
120
121 '/usr/X11R6/include',
122])
123
124
125# x86 assembly
126if x86:
127 env.Append(CPPDEFINES = [
128 'USE_X86_ASM',
129 'USE_MMX_ASM',
130 'USE_3DNOW_ASM',
131 'USE_SSE_ASM',
132 ])
133 if gcc:
134 env.Append(CFLAGS = '-m32')
135 env.Append(CXXFLAGS = '-m32')
136
137env.Append(LIBPATH = ['/usr/X11R6/lib'])
138
139env.Append(LIBS = [
140 'm',
141 'pthread',
142 'expat',
143 'dl',
144])
145
146# DRI
147if dri:
148 env.ParseConfig('pkg-config --cflags --libs libdrm')
149 env.Append(CPPDEFINES = [
150 ('USE_EXTERNAL_DXTN_LIB', '1'),
151 'IN_DRI_DRIVER',
152 'GLX_DIRECT_RENDERING',
153 'GLX_INDIRECT_RENDERING',
154 ])
155
156# libGL
157if 1:
158 env.Append(LIBS = [
159 'X11',
160 'Xext',
161 'Xxf86vm',
162 'Xdamage',
163 'Xfixes',
164 ])
165
166Export('env')
167
168
169#######################################################################
170# Convenience Library Builder
171# based on the stock StaticLibrary and SharedLibrary builders
172
173def createConvenienceLibBuilder(env):
174 """This is a utility function that creates the ConvenienceLibrary
175 Builder in an Environment if it is not there already.
176
177 If it is already there, we return the existing one.
178 """
179
180 try:
181 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
182 except KeyError:
183 action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
184 if env.Detect('ranlib'):
185 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
186 action_list.append(ranlib_action)
187
188 convenience_lib = Builder(action = action_list,
189 emitter = '$LIBEMITTER',
190 prefix = '$LIBPREFIX',
191 suffix = '$LIBSUFFIX',
192 src_suffix = '$SHOBJSUFFIX',
193 src_builder = 'SharedObject')
194 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
195 env['BUILDERS']['Library'] = convenience_lib
196
197 return convenience_lib
198
199createConvenienceLibBuilder(env)
200
201
202#######################################################################
203# Invoke SConscripts
204
205# Put build output in a separate dir
206# TODO: make build_dir depend on platform and build type (check
207# http://www.scons.org/wiki/AdvancedBuildExample for an example)
208build_dir = 'build'
209
210SConscript(
211 'src/mesa/SConscript',
212 build_dir = build_dir,
213 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
214)