Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / scons / gallium.py
1 """gallium
2
3 Frontend-tool for Gallium3D architecture.
4
5 """
6
7 #
8 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
9 # All Rights Reserved.
10 #
11 # Permission is hereby granted, free of charge, to any person obtaining a
12 # copy of this software and associated documentation files (the
13 # "Software"), to deal in the Software without restriction, including
14 # without limitation the rights to use, copy, modify, merge, publish,
15 # distribute, sub license, and/or sell copies of the Software, and to
16 # permit persons to whom the Software is furnished to do so, subject to
17 # the following conditions:
18 #
19 # The above copyright notice and this permission notice (including the
20 # next paragraph) shall be included in all copies or substantial portions
21 # of the Software.
22 #
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
26 # IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
27 # ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #
31
32
33 import os.path
34
35 import SCons.Action
36 import SCons.Builder
37
38
39 def quietCommandLines(env):
40 # Quiet command lines
41 # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
42 env['CCCOMSTR'] = "Compiling $SOURCE ..."
43 env['CXXCOMSTR'] = "Compiling $SOURCE ..."
44 env['ARCOMSTR'] = "Archiving $TARGET ..."
45 env['RANLIBCOMSTR'] = ""
46 env['LINKCOMSTR'] = "Linking $TARGET ..."
47
48
49 def createConvenienceLibBuilder(env):
50 """This is a utility function that creates the ConvenienceLibrary
51 Builder in an Environment if it is not there already.
52
53 If it is already there, we return the existing one.
54
55 Based on the stock StaticLibrary and SharedLibrary builders.
56 """
57
58 try:
59 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
60 except KeyError:
61 action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
62 if env.Detect('ranlib'):
63 ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
64 action_list.append(ranlib_action)
65
66 convenience_lib = SCons.Builder.Builder(action = action_list,
67 emitter = '$LIBEMITTER',
68 prefix = '$LIBPREFIX',
69 suffix = '$LIBSUFFIX',
70 src_suffix = '$SHOBJSUFFIX',
71 src_builder = 'SharedObject')
72 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
73 env['BUILDERS']['Library'] = convenience_lib
74
75 return convenience_lib
76
77
78 def generate(env):
79 """Common environment generation code"""
80
81 # FIXME: this is already too late
82 #if env.get('quiet', False):
83 # quietCommandLines(env)
84
85 # shortcuts
86 debug = env['debug']
87 machine = env['machine']
88 platform = env['platform']
89 x86 = env['machine'] == 'x86'
90 gcc = env['platform'] in ('linux', 'freebsd', 'darwin')
91 msvc = env['platform'] in ('windows', 'winddk', 'wince')
92
93 # Tool
94 if platform == 'winddk':
95 env.Tool('winddk')
96 elif platform == 'wince':
97 env.Tool('evc')
98 else:
99 env.Tool('default')
100
101 # Put build output in a separate dir, which depends on the current
102 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
103 build_topdir = 'build'
104 build_subdir = env['platform']
105 if env['dri']:
106 build_subdir += "-dri"
107 if env['llvm']:
108 build_subdir += "-llvm"
109 if env['machine'] != 'generic':
110 build_subdir += '-' + env['machine']
111 if env['debug']:
112 build_subdir += "-debug"
113 if env['profile']:
114 build_subdir += "-profile"
115 build_dir = os.path.join(build_topdir, build_subdir)
116 # Place the .sconsign file in the build dir too, to avoid issues with
117 # different scons versions building the same source file
118 env['build'] = build_dir
119 env.SConsignFile(os.path.join(build_dir, '.sconsign'))
120
121 # C preprocessor options
122 cppdefines = []
123 if debug:
124 cppdefines += ['DEBUG']
125 else:
126 cppdefines += ['NDEBUG']
127 if env['profile']:
128 cppdefines += ['PROFILE']
129 if platform == 'windows':
130 cppdefines += [
131 'WIN32',
132 '_WINDOWS',
133 '_UNICODE',
134 'UNICODE',
135 # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
136 'WIN32_LEAN_AND_MEAN',
137 'VC_EXTRALEAN',
138 '_CRT_SECURE_NO_DEPRECATE',
139 ]
140 if debug:
141 cppdefines += ['_DEBUG']
142 if platform == 'winddk':
143 # Mimic WINDDK's builtin flags. See also:
144 # - WINDDK's bin/makefile.new i386mk.inc for more info.
145 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
146 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
147 cppdefines += [
148 ('_X86_', '1'),
149 ('i386', '1'),
150 'STD_CALL',
151 ('CONDITION_HANDLING', '1'),
152 ('NT_INST', '0'),
153 ('WIN32', '100'),
154 ('_NT1X_', '100'),
155 ('WINNT', '1'),
156 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
157 ('WINVER', '0x0501'),
158 ('_WIN32_IE', '0x0603'),
159 ('WIN32_LEAN_AND_MEAN', '1'),
160 ('DEVL', '1'),
161 ('__BUILDMACHINE__', 'WinDDK'),
162 ('FPO', '0'),
163 ]
164 if debug:
165 cppdefines += [('DBG', 1)]
166 if platform == 'wince':
167 cppdefines += [
168 ('_WIN32_WCE', '500'),
169 'WCE_PLATFORM_STANDARDSDK_500',
170 '_i386_',
171 ('UNDER_CE', '500'),
172 'UNICODE',
173 '_UNICODE',
174 '_X86_',
175 'x86',
176 '_USRDLL',
177 'TEST_EXPORTS' ,
178 ]
179 if platform == 'windows':
180 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
181 if platform == 'winddk':
182 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
183 if platform == 'wince':
184 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
185 env.Append(CPPDEFINES = cppdefines)
186
187 # C preprocessor includes
188 if platform == 'winddk':
189 env.Append(CPPPATH = [
190 env['SDK_INC_PATH'],
191 env['DDK_INC_PATH'],
192 env['WDM_INC_PATH'],
193 env['CRT_INC_PATH'],
194 ])
195
196 # C compiler options
197 cflags = []
198 if gcc:
199 if debug:
200 cflags += ['-O0', '-g3']
201 else:
202 cflags += ['-O3', '-g3']
203 if env['profile']:
204 cflags += ['-pg']
205 if env['machine'] == 'x86':
206 cflags += ['-m32']
207 if env['machine'] == 'x86_64':
208 cflags += ['-m64']
209 cflags += [
210 '-Wall',
211 '-Wmissing-prototypes',
212 '-Wno-long-long',
213 '-ffast-math',
214 '-pedantic',
215 '-fmessage-length=0', # be nice to Eclipse
216 ]
217 if msvc:
218 # See also:
219 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
220 # - cl /?
221 if debug:
222 cflags += [
223 '/Od', # disable optimizations
224 '/Oi', # enable intrinsic functions
225 '/Oy-', # disable frame pointer omission
226 ]
227 else:
228 cflags += [
229 '/Ox', # maximum optimizations
230 '/Oi', # enable intrinsic functions
231 '/Os', # favor code space
232 ]
233 if env['profile']:
234 cflags += [
235 '/Gh', # enable _penter hook function
236 '/GH', # enable _pexit hook function
237 ]
238 cflags += [
239 '/W3', # warning level
240 #'/Wp64', # enable 64 bit porting warnings
241 ]
242 if platform == 'windows':
243 cflags += [
244 # TODO
245 ]
246 if platform == 'winddk':
247 cflags += [
248 '/Zl', # omit default library name in .OBJ
249 '/Zp8', # 8bytes struct member alignment
250 '/Gy', # separate functions for linker
251 '/Gm-', # disable minimal rebuild
252 '/WX', # treat warnings as errors
253 '/Gz', # __stdcall Calling convention
254 '/GX-', # disable C++ EH
255 '/GR-', # disable C++ RTTI
256 '/GF', # enable read-only string pooling
257 '/G6', # optimize for PPro, P-II, P-III
258 '/Ze', # enable extensions
259 '/Gi-', # disable incremental compilation
260 '/QIfdiv-', # disable Pentium FDIV fix
261 '/hotpatch', # prepares an image for hotpatching.
262 #'/Z7', #enable old-style debug info
263 ]
264 if platform == 'wince':
265 cflags += [
266 '/Gs8192',
267 '/GF', # enable read-only string pooling
268 ]
269 # Automatic pdb generation
270 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
271 env.EnsureSConsVersion(0, 98, 0)
272 env['PDB'] = '${TARGET.base}.pdb'
273 env.Append(CFLAGS = cflags)
274 env.Append(CXXFLAGS = cflags)
275
276 # Linker options
277 linkflags = []
278 if gcc:
279 if env['machine'] == 'x86':
280 linkflags += ['-m32']
281 if env['machine'] == 'x86_64':
282 linkflags += ['-m64']
283 if platform == 'winddk':
284 # See also:
285 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
286 linkflags += [
287 '/merge:_PAGE=PAGE',
288 '/merge:_TEXT=.text',
289 '/section:INIT,d',
290 '/opt:ref',
291 '/opt:icf',
292 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
293 '/incremental:no',
294 '/fullbuild',
295 '/release',
296 '/nodefaultlib',
297 '/wx',
298 '/debug',
299 '/debugtype:cv',
300 '/version:5.1',
301 '/osversion:5.1',
302 '/functionpadmin:5',
303 '/safeseh',
304 '/pdbcompress',
305 '/stack:0x40000,0x1000',
306 '/driver',
307 '/align:0x80',
308 '/subsystem:native,5.01',
309 '/base:0x10000',
310
311 '/entry:DrvEnableDriver',
312 ]
313 env.Append(LINKFLAGS = linkflags)
314
315 # Convenience Library Builder
316 createConvenienceLibBuilder(env)
317
318 # for debugging
319 #print env.Dump()
320
321
322 def exists(env):
323 return 1