blob: 1126aff21b5776703a4141139f102972c6f58a11 [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',
José Fonseca33ceb672008-02-18 10:52:44 +0000111 '#/src/gallium/include/pipe',
112 '#/src/gallium/include',
113 '#/src/gallium/auxiliary',
114 '#/src/gallium/drivers',
José Fonsecac42e6252008-01-31 13:14:35 +0900115])
116
117
118# x86 assembly
119if x86:
120 env.Append(CPPDEFINES = [
121 'USE_X86_ASM',
122 'USE_MMX_ASM',
123 'USE_3DNOW_ASM',
124 'USE_SSE_ASM',
125 ])
126 if gcc:
127 env.Append(CFLAGS = '-m32')
128 env.Append(CXXFLAGS = '-m32')
129
José Fonsecac42e6252008-01-31 13:14:35 +0900130
José Fonseca00137962008-02-07 19:59:17 +0900131# Posix
132if platform in ('posix', 'linux', 'freebsd', 'darwin'):
133 env.Append(CPPDEFINES = [
134 '_POSIX_SOURCE',
135 ('_POSIX_C_SOURCE', '199309L'),
136 '_SVID_SOURCE',
137 '_BSD_SOURCE',
138 '_GNU_SOURCE',
139
140 'PTHREADS',
141 'HAVE_POSIX_MEMALIGN',
142 ])
143 env.Append(CPPPATH = ['/usr/X11R6/include'])
144 env.Append(LIBPATH = ['/usr/X11R6/lib'])
145 env.Append(LIBS = [
146 'm',
147 'pthread',
148 'expat',
149 'dl',
150 ])
151
José Fonsecac42e6252008-01-31 13:14:35 +0900152
153# DRI
154if dri:
155 env.ParseConfig('pkg-config --cflags --libs libdrm')
156 env.Append(CPPDEFINES = [
157 ('USE_EXTERNAL_DXTN_LIB', '1'),
158 'IN_DRI_DRIVER',
159 'GLX_DIRECT_RENDERING',
160 'GLX_INDIRECT_RENDERING',
161 ])
162
163# libGL
164if 1:
165 env.Append(LIBS = [
166 'X11',
167 'Xext',
168 'Xxf86vm',
169 'Xdamage',
170 'Xfixes',
171 ])
172
173Export('env')
174
175
176#######################################################################
177# Convenience Library Builder
178# based on the stock StaticLibrary and SharedLibrary builders
179
180def createConvenienceLibBuilder(env):
181 """This is a utility function that creates the ConvenienceLibrary
182 Builder in an Environment if it is not there already.
183
184 If it is already there, we return the existing one.
185 """
186
187 try:
188 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
189 except KeyError:
190 action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
191 if env.Detect('ranlib'):
192 ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
193 action_list.append(ranlib_action)
194
195 convenience_lib = Builder(action = action_list,
196 emitter = '$LIBEMITTER',
197 prefix = '$LIBPREFIX',
198 suffix = '$LIBSUFFIX',
199 src_suffix = '$SHOBJSUFFIX',
200 src_builder = 'SharedObject')
201 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
202 env['BUILDERS']['Library'] = convenience_lib
203
204 return convenience_lib
205
206createConvenienceLibBuilder(env)
207
208
209#######################################################################
210# Invoke SConscripts
211
José Fonsecaf4192cb42008-01-31 14:21:49 +0900212# Put build output in a separate dir, which depends on the current configuration
213# See also http://www.scons.org/wiki/AdvancedBuildExample
214build_topdir = 'build'
215build_subdir = platform
216if dri:
217 build_subdir += "-dri"
218if x86:
219 build_subdir += "-x86"
220if debug:
221 build_subdir += "-debug"
222build_dir = os.path.join(build_topdir, build_subdir)
223
224# TODO: Build several variants at the same time?
225# http://www.scons.org/wiki/SimultaneousVariantBuilds
José Fonsecac42e6252008-01-31 13:14:35 +0900226
227SConscript(
José Fonseca33ceb672008-02-18 10:52:44 +0000228 'src/SConscript',
José Fonsecac42e6252008-01-31 13:14:35 +0900229 build_dir = build_dir,
230 duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
231)