nv40: construct vbo state the same way as the rest
[platform/upstream/mesa.git] / SConstruct
1 #######################################################################
2 # Top-level SConstruct
3
4 import os
5 import os.path
6 import sys
7
8
9 #######################################################################
10 # Configuration options
11 #
12 # For example, invoke scons as 
13 #
14 #   scons debug=1 dri=0 machine=x86
15 #
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
22 #   machine='x86'
23
24 # Invoke
25 #
26 #   scons -h
27 #
28 # to get the full list of options. See scons manpage for more info.
29 #  
30
31 platform_map = {
32         'linux2': 'linux',
33         'win32': 'winddk',
34 }
35
36 platform = platform_map.get(sys.platform, sys.platform)
37
38 # TODO: auto-detect defaults
39 opts = Options('config.py')
40 opts.Add(BoolOption('debug', 'build debug version', False))
41 opts.Add(BoolOption('dri', 'build dri drivers', False))
42 opts.Add(BoolOption('llvm', 'use llvm', False))
43 opts.Add(EnumOption('machine', 'use machine-specific assembly code', 'x86',
44                      allowed_values=('generic', 'x86', 'x86-64')))
45 opts.Add(EnumOption('platform', 'target platform', platform,
46                      allowed_values=('linux', 'cell', 'winddk')))
47
48 env = Environment(
49         options = opts, 
50         ENV = os.environ)
51 Help(opts.GenerateHelpText(env))
52
53 # for debugging
54 #print env.Dump()
55
56 # replicate options values in local variables
57 debug = env['debug']
58 dri = env['dri']
59 llvm = env['llvm']
60 machine = env['machine']
61 platform = env['platform']
62
63 # derived options
64 x86 = machine == 'x86'
65 gcc = platform in ('linux', 'freebsd', 'darwin')
66 msvc = platform in ('win32', 'winddk')
67
68 Export([
69         'debug', 
70         'x86', 
71         'dri', 
72         'llvm',
73         'platform',
74         'gcc',
75         'msvc',
76 ])
77
78
79 #######################################################################
80 # Environment setup
81 #
82 # TODO: put the compiler specific settings in separate files
83 # TODO: auto-detect as much as possible
84
85
86 if platform == 'winddk':
87         import ntpath
88         escape = env['ESCAPE']
89         env.Tool('msvc')
90         if 'BASEDIR' in os.environ:
91                 WINDDK = os.environ['BASEDIR']
92         else:
93                 WINDDK = "C:\\WINDDK\\3790.1830"
94         # NOTE: We need this elaborate construct to get the absolute paths and
95         # forward slashes to msvc unharmed when cross compiling from posix platforms 
96         env.Append(CPPFLAGS = [
97                 escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wxp')),
98                 escape('/I' + ntpath.join(WINDDK, 'inc\\ddk\\wdm\\wxp')),
99                 escape('/I' + ntpath.join(WINDDK, 'inc\\crt')),
100         ])
101         env.Append(CPPDEFINES = [
102                 ('i386', '1'),
103         ])
104         if debug:
105                 env.Append(CPPDEFINES = ['DBG'])
106         
107
108 # Optimization flags
109 if gcc:
110         if debug:
111                 env.Append(CFLAGS = '-O0 -g3')
112                 env.Append(CXXFLAGS = '-O0 -g3')
113         else:
114                 env.Append(CFLAGS = '-O3 -g3')
115                 env.Append(CXXFLAGS = '-O3 -g3')
116
117         env.Append(CFLAGS = '-Wall -Wmissing-prototypes -std=c99 -ffast-math -pedantic')
118         env.Append(CXXFLAGS = '-Wall -pedantic')
119         
120         # Be nice to Eclipse
121         env.Append(CFLAGS = '-fmessage-length=0')
122         env.Append(CXXFLAGS = '-fmessage-length=0')
123
124
125 # Defines
126 if debug:
127         env.Append(CPPDEFINES = ['DEBUG'])
128 else:
129         env.Append(CPPDEFINES = ['NDEBUG'])
130
131
132 # Includes
133 env.Append(CPPPATH = [
134         '#/include',
135         '#/src/gallium/include',
136         '#/src/gallium/auxiliary',
137         '#/src/gallium/drivers',
138 ])
139
140
141 # x86 assembly
142 if x86:
143         env.Append(CPPDEFINES = [
144                 'USE_X86_ASM', 
145                 'USE_MMX_ASM',
146                 'USE_3DNOW_ASM',
147                 'USE_SSE_ASM',
148         ])
149         if gcc: 
150                 env.Append(CFLAGS = '-m32')
151                 env.Append(CXXFLAGS = '-m32')
152
153
154 # Posix
155 if platform in ('posix', 'linux', 'freebsd', 'darwin'):
156         env.Append(CPPDEFINES = [
157                 '_POSIX_SOURCE',
158                 ('_POSIX_C_SOURCE', '199309L'), 
159                 '_SVID_SOURCE',
160                 '_BSD_SOURCE', 
161                 '_GNU_SOURCE',
162                 
163                 'PTHREADS',
164                 'HAVE_POSIX_MEMALIGN',
165         ])
166         env.Append(CPPPATH = ['/usr/X11R6/include'])
167         env.Append(LIBPATH = ['/usr/X11R6/lib'])
168         env.Append(LIBS = [
169                 'm',
170                 'pthread',
171                 'expat',
172                 'dl',
173         ])
174
175
176 # DRI
177 if dri:
178         env.ParseConfig('pkg-config --cflags --libs libdrm')
179         env.Append(CPPDEFINES = [
180                 ('USE_EXTERNAL_DXTN_LIB', '1'), 
181                 'IN_DRI_DRIVER',
182                 'GLX_DIRECT_RENDERING',
183                 'GLX_INDIRECT_RENDERING',
184         ])
185
186 # LLVM
187 if llvm:
188         # See also http://www.scons.org/wiki/UsingPkgConfig
189         env.ParseConfig('llvm-config --cflags --ldflags --libs')
190         env.Append(CPPDEFINES = ['MESA_LLVM'])
191         env.Append(CXXFLAGS = ['-Wno-long-long'])
192         
193
194 # libGL
195 if 1:
196         env.Append(LIBS = [
197                 'X11',
198                 'Xext',
199                 'Xxf86vm',
200                 'Xdamage',
201                 'Xfixes',
202         ])
203
204 Export('env')
205
206
207 #######################################################################
208 # Convenience Library Builder
209 # based on the stock StaticLibrary and SharedLibrary builders
210
211 def createConvenienceLibBuilder(env):
212     """This is a utility function that creates the ConvenienceLibrary
213     Builder in an Environment if it is not there already.
214
215     If it is already there, we return the existing one.
216     """
217
218     try:
219         convenience_lib = env['BUILDERS']['ConvenienceLibrary']
220     except KeyError:
221         action_list = [ Action("$ARCOM", "$ARCOMSTR") ]
222         if env.Detect('ranlib'):
223             ranlib_action = Action("$RANLIBCOM", "$RANLIBCOMSTR")
224             action_list.append(ranlib_action)
225
226         convenience_lib = Builder(action = action_list,
227                                   emitter = '$LIBEMITTER',
228                                   prefix = '$LIBPREFIX',
229                                   suffix = '$LIBSUFFIX',
230                                   src_suffix = '$SHOBJSUFFIX',
231                                   src_builder = 'SharedObject')
232         env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
233         env['BUILDERS']['Library'] = convenience_lib
234
235     return convenience_lib
236
237 createConvenienceLibBuilder(env)
238
239
240 #######################################################################
241 # Invoke SConscripts
242
243 # Put build output in a separate dir, which depends on the current configuration
244 # See also http://www.scons.org/wiki/AdvancedBuildExample
245 build_topdir = 'build'
246 build_subdir = platform
247 if dri:
248         build_subdir += "-dri"
249 if llvm:
250         build_subdir += "-llvm"
251 if x86:
252         build_subdir += "-x86"
253 if debug:
254         build_subdir += "-debug"
255 build_dir = os.path.join(build_topdir, build_subdir)
256
257 # TODO: Build several variants at the same time?
258 # http://www.scons.org/wiki/SimultaneousVariantBuilds
259
260 SConscript(
261         'src/SConscript',
262         build_dir = build_dir,
263         duplicate = 0 # http://www.scons.org/doc/0.97/HTML/scons-user/x2261.html
264 )