blob: 1f9cd3d9203485ea45d6e82ee584397e2839281f [file] [log] [blame]
José Fonsecab04aa712008-06-06 14:48:57 +09001"""gallium
2
3Frontend-tool for Gallium3D architecture.
4
5"""
6
José Fonseca381e3482008-07-17 11:23:43 +09007#
José Fonsecab04aa712008-06-06 14:48:57 +09008# Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
9# All Rights Reserved.
José Fonseca381e3482008-07-17 11:23:43 +090010#
José Fonsecab04aa712008-06-06 14:48:57 +090011# 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:
José Fonseca381e3482008-07-17 11:23:43 +090018#
José Fonsecab04aa712008-06-06 14:48:57 +090019# 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.
José Fonseca381e3482008-07-17 11:23:43 +090022#
José Fonsecab04aa712008-06-06 14:48:57 +090023# 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.
José Fonseca381e3482008-07-17 11:23:43 +090030#
José Fonsecab04aa712008-06-06 14:48:57 +090031
32
José Fonseca27d8d6f2008-07-03 12:42:23 +090033import os
José Fonsecab04aa712008-06-06 14:48:57 +090034import os.path
José Fonseca27d8d6f2008-07-03 12:42:23 +090035import re
José Fonsecab04aa712008-06-06 14:48:57 +090036
37import SCons.Action
38import SCons.Builder
José Fonseca27d8d6f2008-07-03 12:42:23 +090039import SCons.Scanner
José Fonsecab04aa712008-06-06 14:48:57 +090040
José Fonseca7325c1e2009-07-14 11:09:23 +010041import fixes
42
José Fonsecab04aa712008-06-06 14:48:57 +090043
44def quietCommandLines(env):
José Fonseca381e3482008-07-17 11:23:43 +090045 # Quiet command lines
46 # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
Michel Dänzer550a2fe2009-06-11 12:11:37 +020047 env['ASCOMSTR'] = " Assembling $SOURCE ..."
48 env['ASPPCOMSTR'] = " Assembling $SOURCE ..."
49 env['CCCOMSTR'] = " Compiling $SOURCE ..."
50 env['SHCCCOMSTR'] = " Compiling $SOURCE ..."
51 env['CXXCOMSTR'] = " Compiling $SOURCE ..."
52 env['SHCXXCOMSTR'] = " Compiling $SOURCE ..."
53 env['ARCOMSTR'] = " Archiving $TARGET ..."
54 env['RANLIBCOMSTR'] = " Indexing $TARGET ..."
55 env['LINKCOMSTR'] = " Linking $TARGET ..."
56 env['SHLINKCOMSTR'] = " Linking $TARGET ..."
57 env['LDMODULECOMSTR'] = " Linking $TARGET ..."
58 env['SWIGCOMSTR'] = " Generating $TARGET ..."
José Fonsecab04aa712008-06-06 14:48:57 +090059
60
61def createConvenienceLibBuilder(env):
62 """This is a utility function that creates the ConvenienceLibrary
63 Builder in an Environment if it is not there already.
64
65 If it is already there, we return the existing one.
José Fonseca381e3482008-07-17 11:23:43 +090066
José Fonsecab04aa712008-06-06 14:48:57 +090067 Based on the stock StaticLibrary and SharedLibrary builders.
68 """
69
70 try:
71 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
72 except KeyError:
73 action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
74 if env.Detect('ranlib'):
75 ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
76 action_list.append(ranlib_action)
77
78 convenience_lib = SCons.Builder.Builder(action = action_list,
79 emitter = '$LIBEMITTER',
80 prefix = '$LIBPREFIX',
81 suffix = '$LIBSUFFIX',
82 src_suffix = '$SHOBJSUFFIX',
83 src_builder = 'SharedObject')
84 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
José Fonsecab04aa712008-06-06 14:48:57 +090085
86 return convenience_lib
87
88
José Fonseca27d8d6f2008-07-03 12:42:23 +090089# TODO: handle import statements with multiple modules
90# TODO: handle from import statements
91import_re = re.compile(r'^import\s+(\S+)$', re.M)
92
93def python_scan(node, env, path):
José Fonseca381e3482008-07-17 11:23:43 +090094 # http://www.scons.org/doc/0.98.5/HTML/scons-user/c2781.html#AEN2789
95 contents = node.get_contents()
96 source_dir = node.get_dir()
97 imports = import_re.findall(contents)
98 results = []
99 for imp in imports:
100 for dir in path:
101 file = os.path.join(str(dir), imp.replace('.', os.sep) + '.py')
102 if os.path.exists(file):
103 results.append(env.File(file))
104 break
105 file = os.path.join(str(dir), imp.replace('.', os.sep), '__init__.py')
106 if os.path.exists(file):
107 results.append(env.File(file))
108 break
109 return results
José Fonseca27d8d6f2008-07-03 12:42:23 +0900110
111python_scanner = SCons.Scanner.Scanner(function = python_scan, skeys = ['.py'])
112
113
114def code_generate(env, script, target, source, command):
José Fonseca381e3482008-07-17 11:23:43 +0900115 """Method to simplify code generation via python scripts.
José Fonseca27d8d6f2008-07-03 12:42:23 +0900116
José Fonseca381e3482008-07-17 11:23:43 +0900117 http://www.scons.org/wiki/UsingCodeGenerators
118 http://www.scons.org/doc/0.98.5/HTML/scons-user/c2768.html
119 """
120
121 # We're generating code using Python scripts, so we have to be
122 # careful with our scons elements. This entry represents
123 # the generator file *in the source directory*.
124 script_src = env.File(script).srcnode()
125
126 # This command creates generated code *in the build directory*.
127 command = command.replace('$SCRIPT', script_src.path)
128 code = env.Command(target, source, command)
129
130 # Explicitly mark that the generated code depends on the generator,
131 # and on implicitly imported python modules
132 path = (script_src.get_dir(),)
133 deps = [script_src]
134 deps += script_src.get_implicit_deps(env, python_scanner, path)
135 env.Depends(code, deps)
136
137 # Running the Python script causes .pyc files to be generated in the
138 # source directory. When we clean up, they should go too. So add side
139 # effects for .pyc files
140 for dep in deps:
141 pyc = env.File(str(dep) + 'c')
142 env.SideEffect(pyc, code)
143
144 return code
José Fonseca27d8d6f2008-07-03 12:42:23 +0900145
146
147def createCodeGenerateMethod(env):
José Fonseca381e3482008-07-17 11:23:43 +0900148 env.Append(SCANNERS = python_scanner)
149 env.AddMethod(code_generate, 'CodeGenerate')
José Fonseca27d8d6f2008-07-03 12:42:23 +0900150
151
José Fonseca52c2dd12008-09-08 07:54:15 +0900152def symlink(target, source, env):
153 target = str(target[0])
154 source = str(source[0])
155 if os.path.islink(target) or os.path.exists(target):
156 os.remove(target)
157 os.symlink(os.path.basename(source), target)
158
José Fonsecab5a408b2009-12-23 15:21:56 +0000159def install_program(env, source):
160 source = str(source[0])
161 target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build'], 'bin')
162 target_name = str(source)
163 env.InstallAs(os.path.join(target_dir, target_name), source)
164
José Fonseca52c2dd12008-09-08 07:54:15 +0900165def install_shared_library(env, source, version = ()):
166 source = str(source[0])
167 version = tuple(map(str, version))
José Fonseca7cfc2942008-09-08 21:50:50 +0900168 target_dir = os.path.join(env.Dir('#.').srcnode().abspath, env['build'], 'lib')
José Fonseca52c2dd12008-09-08 07:54:15 +0900169 target_name = '.'.join((str(source),) + version)
170 last = env.InstallAs(os.path.join(target_dir, target_name), source)
171 while len(version):
172 version = version[:-1]
173 target_name = '.'.join((str(source),) + version)
174 action = SCons.Action.Action(symlink, "$TARGET -> $SOURCE")
José Fonseca52c2dd12008-09-08 07:54:15 +0900175 last = env.Command(os.path.join(target_dir, target_name), last, action)
176
177def createInstallMethods(env):
José Fonsecab5a408b2009-12-23 15:21:56 +0000178 env.AddMethod(install_program, 'InstallProgram')
José Fonseca52c2dd12008-09-08 07:54:15 +0900179 env.AddMethod(install_shared_library, 'InstallSharedLibrary')
180
181
José Fonseca1e8177e2009-02-10 18:11:56 +0000182def num_jobs():
183 try:
184 return int(os.environ['NUMBER_OF_PROCESSORS'])
185 except (ValueError, KeyError):
186 pass
187
188 try:
189 return os.sysconf('SC_NPROCESSORS_ONLN')
190 except (ValueError, OSError, AttributeError):
191 pass
192
193 try:
194 return int(os.popen2("sysctl -n hw.ncpu")[1].read())
195 except ValueError:
196 pass
197
198 return 1
199
200
José Fonsecab04aa712008-06-06 14:48:57 +0900201def generate(env):
José Fonseca381e3482008-07-17 11:23:43 +0900202 """Common environment generation code"""
José Fonsecab04aa712008-06-06 14:48:57 +0900203
José Fonseca0f50c4f2009-06-02 18:23:12 -0700204 if env.get('quiet', True):
205 quietCommandLines(env)
José Fonsecab04aa712008-06-06 14:48:57 +0900206
José Fonseca6cf59e12008-11-18 19:13:32 +0900207 # Toolchain
208 platform = env['platform']
209 if env['toolchain'] == 'default':
210 if platform == 'winddk':
Michal Krol4f3dcf32008-11-19 20:31:38 +0100211 env['toolchain'] = 'winddk'
José Fonseca6cf59e12008-11-18 19:13:32 +0900212 elif platform == 'wince':
Michal Krol4f3dcf32008-11-19 20:31:38 +0100213 env['toolchain'] = 'wcesdk'
José Fonseca6cf59e12008-11-18 19:13:32 +0900214 env.Tool(env['toolchain'])
215
José Fonseca26e27ba2009-03-25 19:24:16 +0000216 env['gcc'] = 'gcc' in os.path.basename(env['CC']).split('-')
217 env['msvc'] = env['CC'] == 'cl'
218
José Fonseca381e3482008-07-17 11:23:43 +0900219 # shortcuts
220 debug = env['debug']
221 machine = env['machine']
222 platform = env['platform']
223 x86 = env['machine'] == 'x86'
Michel Dänzer6b69e3c2008-10-23 10:28:48 +0200224 ppc = env['machine'] == 'ppc'
José Fonseca26e27ba2009-03-25 19:24:16 +0000225 gcc = env['gcc']
226 msvc = env['msvc']
José Fonsecab04aa712008-06-06 14:48:57 +0900227
José Fonseca381e3482008-07-17 11:23:43 +0900228 # Put build output in a separate dir, which depends on the current
229 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
230 build_topdir = 'build'
231 build_subdir = env['platform']
José Fonseca381e3482008-07-17 11:23:43 +0900232 if env['llvm']:
233 build_subdir += "-llvm"
234 if env['machine'] != 'generic':
235 build_subdir += '-' + env['machine']
236 if env['debug']:
237 build_subdir += "-debug"
238 if env['profile']:
239 build_subdir += "-profile"
240 build_dir = os.path.join(build_topdir, build_subdir)
241 # Place the .sconsign file in the build dir too, to avoid issues with
242 # different scons versions building the same source file
243 env['build'] = build_dir
244 env.SConsignFile(os.path.join(build_dir, '.sconsign'))
José Fonseca18170bb2009-01-23 21:01:16 +0000245 env.CacheDir('build/cache')
José Fonseca8b755262009-12-25 17:39:47 +0000246 env['CONFIGUREDIR'] = os.path.join(build_dir, 'conf')
247 env['CONFIGURELOG'] = os.path.join(os.path.abspath(build_dir), 'config.log')
José Fonsecab04aa712008-06-06 14:48:57 +0900248
José Fonseca1e8177e2009-02-10 18:11:56 +0000249 # Parallel build
250 if env.GetOption('num_jobs') <= 1:
251 env.SetOption('num_jobs', num_jobs())
252
José Fonseca381e3482008-07-17 11:23:43 +0900253 # C preprocessor options
254 cppdefines = []
255 if debug:
256 cppdefines += ['DEBUG']
257 else:
258 cppdefines += ['NDEBUG']
259 if env['profile']:
260 cppdefines += ['PROFILE']
261 if platform == 'windows':
262 cppdefines += [
263 'WIN32',
264 '_WINDOWS',
José Fonseca42be0102009-01-22 14:26:30 +0000265 #'_UNICODE',
266 #'UNICODE',
José Fonseca129c6ed2008-12-01 11:53:26 -0800267 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
268 ('WINVER', '0x0501'),
José Fonseca381e3482008-07-17 11:23:43 +0900269 # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
270 'WIN32_LEAN_AND_MEAN',
José Fonseca381e3482008-07-17 11:23:43 +0900271 ]
José Fonseca71793e0f2009-04-14 21:39:54 +0100272 if msvc and env['toolchain'] != 'winddk':
José Fonsecab3e03ed2009-03-25 19:32:54 +0000273 cppdefines += [
274 'VC_EXTRALEAN',
José Fonsecaad0975f2009-10-26 15:11:11 +0000275 '_USE_MATH_DEFINES',
José Fonseca1acd8912009-10-21 17:03:52 +0100276 '_CRT_SECURE_NO_WARNINGS',
José Fonsecab3e03ed2009-03-25 19:32:54 +0000277 '_CRT_SECURE_NO_DEPRECATE',
José Fonseca1acd8912009-10-21 17:03:52 +0100278 '_SCL_SECURE_NO_WARNINGS',
279 '_SCL_SECURE_NO_DEPRECATE',
José Fonsecab3e03ed2009-03-25 19:32:54 +0000280 ]
José Fonseca381e3482008-07-17 11:23:43 +0900281 if debug:
282 cppdefines += ['_DEBUG']
José Fonseca71793e0f2009-04-14 21:39:54 +0100283 if env['toolchain'] == 'winddk':
José Fonseca381e3482008-07-17 11:23:43 +0900284 # Mimic WINDDK's builtin flags. See also:
285 # - WINDDK's bin/makefile.new i386mk.inc for more info.
286 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
287 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
José Fonseca71793e0f2009-04-14 21:39:54 +0100288 if machine == 'x86':
289 cppdefines += ['_X86_', 'i386']
290 if machine == 'x86_64':
291 cppdefines += ['_AMD64_', 'AMD64']
292 if platform == 'winddk':
José Fonseca381e3482008-07-17 11:23:43 +0900293 cppdefines += [
José Fonseca381e3482008-07-17 11:23:43 +0900294 'STD_CALL',
295 ('CONDITION_HANDLING', '1'),
296 ('NT_INST', '0'),
297 ('WIN32', '100'),
298 ('_NT1X_', '100'),
299 ('WINNT', '1'),
300 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
301 ('WINVER', '0x0501'),
302 ('_WIN32_IE', '0x0603'),
303 ('WIN32_LEAN_AND_MEAN', '1'),
304 ('DEVL', '1'),
305 ('__BUILDMACHINE__', 'WinDDK'),
306 ('FPO', '0'),
307 ]
308 if debug:
309 cppdefines += [('DBG', 1)]
310 if platform == 'wince':
311 cppdefines += [
312 '_CRT_SECURE_NO_DEPRECATE',
313 '_USE_32BIT_TIME_T',
314 'UNICODE',
315 '_UNICODE',
316 ('UNDER_CE', '600'),
317 ('_WIN32_WCE', '0x600'),
318 'WINCEOEM',
319 'WINCEINTERNAL',
320 'WIN32',
321 'STRICT',
322 'x86',
323 '_X86_',
324 'INTERNATIONAL',
325 ('INTLMSG_CODEPAGE', '1252'),
326 ]
327 if platform == 'windows':
328 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_USER']
329 if platform == 'winddk':
330 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
331 if platform == 'wince':
332 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE']
José Fonseca40b3bb02008-11-04 10:53:02 +0900333 cppdefines += ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
José Fonseca381e3482008-07-17 11:23:43 +0900334 env.Append(CPPDEFINES = cppdefines)
José Fonsecab04aa712008-06-06 14:48:57 +0900335
José Fonseca381e3482008-07-17 11:23:43 +0900336 # C compiler options
José Fonseca25f6c932009-06-26 19:50:12 +0100337 cflags = [] # C
338 cxxflags = [] # C++
339 ccflags = [] # C & C++
José Fonseca381e3482008-07-17 11:23:43 +0900340 if gcc:
341 if debug:
José Fonseca25f6c932009-06-26 19:50:12 +0100342 ccflags += ['-O0', '-g3']
José Fonsecabb8f3092009-06-28 11:12:22 +0100343 elif env['CCVERSION'].startswith('4.2.'):
344 # gcc 4.2.x optimizer is broken
345 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
346 ccflags += ['-O0', '-g3']
José Fonseca381e3482008-07-17 11:23:43 +0900347 else:
José Fonseca25f6c932009-06-26 19:50:12 +0100348 ccflags += ['-O3', '-g3']
José Fonseca381e3482008-07-17 11:23:43 +0900349 if env['profile']:
José Fonseca1a9eec82009-09-20 18:07:16 +0100350 # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
351 ccflags += [
352 '-fno-omit-frame-pointer',
353 '-fno-optimize-sibling-calls',
354 ]
José Fonseca381e3482008-07-17 11:23:43 +0900355 if env['machine'] == 'x86':
José Fonseca25f6c932009-06-26 19:50:12 +0100356 ccflags += [
José Fonseca381e3482008-07-17 11:23:43 +0900357 '-m32',
358 #'-march=pentium4',
José Fonseca381e3482008-07-17 11:23:43 +0900359 #'-mfpmath=sse',
360 ]
José Fonseca5ba645f2009-10-14 16:16:40 +0100361 if platform != 'windows':
362 # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
363 # for -mincoming-stack-boundary=2. Still enable it on other
364 # platforms for now, but we can't rely on it for cross platform
365 # code. We have to use __attribute__((force_align_arg_pointer))
366 # instead.
367 ccflags += [
368 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
369 '-mstackrealign', # ensure stack is aligned
370 ]
José Fonseca381e3482008-07-17 11:23:43 +0900371 if env['machine'] == 'x86_64':
José Fonseca25f6c932009-06-26 19:50:12 +0100372 ccflags += ['-m64']
José Fonseca102cb5c2009-03-13 16:21:30 +0000373 # See also:
374 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
José Fonseca25f6c932009-06-26 19:50:12 +0100375 ccflags += [
José Fonseca381e3482008-07-17 11:23:43 +0900376 '-Wall',
José Fonseca102cb5c2009-03-13 16:21:30 +0000377 '-Wmissing-field-initializers',
José Fonseca2348f6d2009-11-27 16:01:36 +0000378 '-Werror=pointer-arith',
José Fonseca381e3482008-07-17 11:23:43 +0900379 '-Wno-long-long',
380 '-ffast-math',
José Fonseca381e3482008-07-17 11:23:43 +0900381 '-fmessage-length=0', # be nice to Eclipse
382 ]
José Fonseca25f6c932009-06-26 19:50:12 +0100383 cflags += [
384 '-Werror=declaration-after-statement',
385 '-Wmissing-prototypes',
386 '-std=gnu99',
387 ]
José Fonseca381e3482008-07-17 11:23:43 +0900388 if msvc:
389 # See also:
José Fonsecaa6c72582008-09-01 09:47:40 +0900390 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
José Fonseca381e3482008-07-17 11:23:43 +0900391 # - cl /?
392 if debug:
José Fonseca25f6c932009-06-26 19:50:12 +0100393 ccflags += [
José Fonseca381e3482008-07-17 11:23:43 +0900394 '/Od', # disable optimizations
395 '/Oi', # enable intrinsic functions
396 '/Oy-', # disable frame pointer omission
José Fonseca73ccabc2009-02-12 11:57:45 +0000397 '/GL-', # disable whole program optimization
José Fonseca381e3482008-07-17 11:23:43 +0900398 ]
399 else:
José Fonseca25f6c932009-06-26 19:50:12 +0100400 ccflags += [
José Fonseca78dad272009-06-04 10:34:02 -0700401 '/O2', # optimize for speed
José Fonsecada3bc492009-12-11 15:16:22 +0000402 '/GL', # enable whole program optimization
José Fonseca381e3482008-07-17 11:23:43 +0900403 ]
José Fonseca25f6c932009-06-26 19:50:12 +0100404 ccflags += [
José Fonsecada3bc492009-12-11 15:16:22 +0000405 '/fp:fast', # fast floating point
José Fonseca381e3482008-07-17 11:23:43 +0900406 '/W3', # warning level
407 #'/Wp64', # enable 64 bit porting warnings
408 ]
José Fonsecaa6c72582008-09-01 09:47:40 +0900409 if env['machine'] == 'x86':
José Fonseca25f6c932009-06-26 19:50:12 +0100410 ccflags += [
José Fonsecaa6c72582008-09-01 09:47:40 +0900411 #'/arch:SSE2', # use the SSE2 instructions
412 ]
José Fonseca381e3482008-07-17 11:23:43 +0900413 if platform == 'windows':
José Fonseca25f6c932009-06-26 19:50:12 +0100414 ccflags += [
José Fonseca381e3482008-07-17 11:23:43 +0900415 # TODO
416 ]
417 if platform == 'winddk':
José Fonseca25f6c932009-06-26 19:50:12 +0100418 ccflags += [
José Fonseca381e3482008-07-17 11:23:43 +0900419 '/Zl', # omit default library name in .OBJ
420 '/Zp8', # 8bytes struct member alignment
421 '/Gy', # separate functions for linker
422 '/Gm-', # disable minimal rebuild
423 '/WX', # treat warnings as errors
424 '/Gz', # __stdcall Calling convention
425 '/GX-', # disable C++ EH
426 '/GR-', # disable C++ RTTI
427 '/GF', # enable read-only string pooling
428 '/G6', # optimize for PPro, P-II, P-III
429 '/Ze', # enable extensions
430 '/Gi-', # disable incremental compilation
431 '/QIfdiv-', # disable Pentium FDIV fix
432 '/hotpatch', # prepares an image for hotpatching.
433 #'/Z7', #enable old-style debug info
434 ]
435 if platform == 'wince':
436 # See also C:\WINCE600\public\common\oak\misc\makefile.def
José Fonseca25f6c932009-06-26 19:50:12 +0100437 ccflags += [
José Fonseca381e3482008-07-17 11:23:43 +0900438 '/Zl', # omit default library name in .OBJ
439 '/GF', # enable read-only string pooling
440 '/GR-', # disable C++ RTTI
441 '/GS', # enable security checks
442 # Allow disabling language conformance to maintain backward compat
443 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
444 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
445 #'/wd4867',
446 #'/wd4430',
447 #'/MT',
448 #'/U_MT',
449 ]
450 # Automatic pdb generation
451 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
452 env.EnsureSConsVersion(0, 98, 0)
453 env['PDB'] = '${TARGET.base}.pdb'
José Fonseca25f6c932009-06-26 19:50:12 +0100454 env.Append(CCFLAGS = ccflags)
José Fonseca381e3482008-07-17 11:23:43 +0900455 env.Append(CFLAGS = cflags)
José Fonseca25f6c932009-06-26 19:50:12 +0100456 env.Append(CXXFLAGS = cxxflags)
José Fonsecab04aa712008-06-06 14:48:57 +0900457
José Fonseca1781d7f2009-01-06 16:16:38 +0000458 if env['platform'] == 'windows' and msvc:
459 # Choose the appropriate MSVC CRT
460 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
461 if env['debug']:
462 env.Append(CCFLAGS = ['/MTd'])
463 env.Append(SHCCFLAGS = ['/LDd'])
464 else:
465 env.Append(CCFLAGS = ['/MT'])
466 env.Append(SHCCFLAGS = ['/LD'])
467
José Fonseca381e3482008-07-17 11:23:43 +0900468 # Assembler options
469 if gcc:
470 if env['machine'] == 'x86':
471 env.Append(ASFLAGS = ['-m32'])
472 if env['machine'] == 'x86_64':
473 env.Append(ASFLAGS = ['-m64'])
José Fonseca27d8d6f2008-07-03 12:42:23 +0900474
José Fonseca381e3482008-07-17 11:23:43 +0900475 # Linker options
476 linkflags = []
José Fonseca72ad0392009-06-28 10:54:23 +0100477 shlinkflags = []
José Fonseca381e3482008-07-17 11:23:43 +0900478 if gcc:
479 if env['machine'] == 'x86':
480 linkflags += ['-m32']
481 if env['machine'] == 'x86_64':
482 linkflags += ['-m64']
José Fonseca72ad0392009-06-28 10:54:23 +0100483 shlinkflags += [
484 '-Wl,-Bsymbolic',
485 ]
José Fonseca7b391942009-08-13 16:32:51 +0100486 # Handle circular dependencies in the libraries
487 env['_LIBFLAGS'] = '-Wl,--start-group ' + env['_LIBFLAGS'] + ' -Wl,--end-group'
José Fonsecada3bc492009-12-11 15:16:22 +0000488 if msvc:
489 if not env['debug']:
490 # enable Link-time Code Generation
491 linkflags += ['/LTCG']
492 env.Append(ARFLAGS = ['/LTCG'])
José Fonseca6fe421c2009-02-12 12:59:58 +0000493 if platform == 'windows' and msvc:
José Fonseca381e3482008-07-17 11:23:43 +0900494 # See also:
495 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
496 linkflags += [
José Fonseca73ccabc2009-02-12 11:57:45 +0000497 '/fixed:no',
498 '/incremental:no',
499 ]
500 if platform == 'winddk':
501 linkflags += [
José Fonseca381e3482008-07-17 11:23:43 +0900502 '/merge:_PAGE=PAGE',
503 '/merge:_TEXT=.text',
504 '/section:INIT,d',
505 '/opt:ref',
506 '/opt:icf',
507 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
508 '/incremental:no',
509 '/fullbuild',
510 '/release',
511 '/nodefaultlib',
512 '/wx',
513 '/debug',
514 '/debugtype:cv',
515 '/version:5.1',
516 '/osversion:5.1',
517 '/functionpadmin:5',
518 '/safeseh',
519 '/pdbcompress',
520 '/stack:0x40000,0x1000',
521 '/driver',
522 '/align:0x80',
523 '/subsystem:native,5.01',
524 '/base:0x10000',
525
526 '/entry:DrvEnableDriver',
527 ]
José Fonseca46728032009-02-18 15:05:23 +0000528 if env['debug'] or env['profile']:
José Fonseca381e3482008-07-17 11:23:43 +0900529 linkflags += [
530 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
531 ]
532 if platform == 'wince':
533 linkflags += [
534 '/nodefaultlib',
535 #'/incremental:no',
536 #'/fullbuild',
537 '/entry:_DllMainCRTStartup',
538 ]
539 env.Append(LINKFLAGS = linkflags)
José Fonseca72ad0392009-06-28 10:54:23 +0100540 env.Append(SHLINKFLAGS = shlinkflags)
José Fonseca381e3482008-07-17 11:23:43 +0900541
José Fonsecac76787a2008-07-17 11:25:20 +0900542 # Default libs
543 env.Append(LIBS = [])
544
José Fonseca381e3482008-07-17 11:23:43 +0900545 # Custom builders and methods
546 createConvenienceLibBuilder(env)
547 createCodeGenerateMethod(env)
José Fonseca52c2dd12008-09-08 07:54:15 +0900548 createInstallMethods(env)
José Fonseca381e3482008-07-17 11:23:43 +0900549
550 # for debugging
551 #print env.Dump()
José Fonsecab04aa712008-06-06 14:48:57 +0900552
553
554def exists(env):
José Fonseca381e3482008-07-17 11:23:43 +0900555 return 1