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