149256c3db67b8d6c17e4dac682034663c13a404
3 Generic tool that provides a commmon ground for all platforms.
8 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
19 # The above copyright notice and this permission notice (including the
20 # next paragraph) shall be included in all copies or substantial portions
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.
36 import platform
as _platform
44 def symlink(target
, source
, env
):
45 target
= str(target
[0])
46 source
= str(source
[0])
47 if os
.path
.islink(target
) or os
.path
.exists(target
):
49 os
.symlink(os
.path
.basename(source
), target
)
51 def install_shared_library(env
, source
, version
= ()):
52 source
= str(source
[0])
53 version
= tuple(map(str, version
))
54 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], 'lib')
55 target_name
= '.'.join((str(source
),) + version
)
56 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
58 version
= version
[:-1]
59 target_name
= '.'.join((str(source
),) + version
)
60 action
= SCons
.Action
.Action(symlink
, "$TARGET -> $SOURCE")
61 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
63 def createInstallMethods(env
):
64 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
110 return int(os
.environ
['NUMBER_OF_PROCESSORS'])
111 except (ValueError, KeyError):
115 return os
.sysconf('SC_NPROCESSORS_ONLN')
116 except (ValueError, OSError, AttributeError):
120 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
128 """Common environment generation code"""
130 from SCons
.Script
import ARGUMENTS
132 # FIXME: this is already too late
133 #if env.get('quiet', False):
134 # quietCommandLines(env)
139 env
['platform'] = ARGUMENTS
['platform']
141 env
['platform'] = _platform_map
.get(sys
.platform
, sys
.platform
)
145 env
['machine'] = ARGUMENTS
['machine']
147 env
['machine'] = _machine_map
.get(os
.environ
.get('PROCESSOR_ARCHITECTURE', _platform
.machine()), 'generic')
151 env
['toolchain'] = ARGUMENTS
['toolchain']
153 if env
['platform'] in ('windows', 'winddk', 'wince') and sys
.platform
!= 'win32':
154 env
['toolchain'] = 'crossmingw'
156 env
['toolchain'] = _toolchain_map
.get(env
['platform'], 'default')
157 if env
['toolchain'] == 'crossmingw' and env
['machine'] not in ('generic', 'x86'):
158 env
['machine'] = 'x86'
161 env
['MSVS_VERSION'] = ARGUMENTS
['MSVS_VERSION']
166 env
['debug'] = _bool_map
[ARGUMENTS
.get('debug', 'no')]
167 env
['profile'] = _bool_map
[ARGUMENTS
.get('profile', 'no')]
169 # Put build output in a separate dir, which depends on the current
170 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
172 env
['build'] = ARGUMENTS
['build']
174 build_topdir
= 'build'
175 build_subdir
= env
['platform']
176 if env
['machine'] != 'generic':
177 build_subdir
+= '-' + env
['machine']
179 build_subdir
+= "-debug"
181 build_subdir
+= "-profile"
182 env
['build'] = os
.path
.join(build_topdir
, build_subdir
)
183 # Place the .sconsign file in the build dir too, to avoid issues with
184 # different scons versions building the same source file
185 env
.SConsignFile(os
.path
.join(env
['build'], '.sconsign'))
188 if env
.GetOption('num_jobs') <= 1:
189 env
.SetOption('num_jobs', num_jobs())
193 print ' platform=%s' % env
['platform']
194 print ' machine=%s' % env
['machine']
195 print ' toolchain=%s' % env
['toolchain']
196 print ' debug=%s' % ['no', 'yes'][env
['debug']]
197 print ' profile=%s' % ['no', 'yes'][env
['profile']]
198 print ' build=%s' % env
['build']
199 print ' %s jobs' % env
.GetOption('num_jobs')
203 env
.Tool(env
['toolchain'])
205 env
['gcc'] = 'gcc' in os
.path
.basename(env
['CC']).split('-')
206 env
['msvc'] = env
['CC'] == 'cl'
210 machine
= env
['machine']
211 platform
= env
['platform']
212 x86
= env
['machine'] == 'x86'
213 ppc
= env
['machine'] == 'ppc'
217 # C preprocessor options
220 cppdefines
+= ['DEBUG']
222 cppdefines
+= ['NDEBUG']
224 cppdefines
+= ['PROFILE']
225 if platform
== 'windows':
236 '_CRT_SECURE_NO_WARNINGS',
237 '_CRT_SECURE_NO_DEPRECATE',
238 '_SCL_SECURE_NO_WARNINGS',
239 '_SCL_SECURE_NO_DEPRECATE',
242 cppdefines
+= ['_DEBUG']
243 if platform
== 'winddk':
244 # Mimic WINDDK's builtin flags. See also:
245 # - WINDDK's bin/makefile.new i386mk.inc for more info.
246 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
247 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
252 ('CONDITION_HANDLING', '1'),
257 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
258 ('WINVER', '0x0501'),
259 ('_WIN32_IE', '0x0603'),
260 ('WIN32_LEAN_AND_MEAN', '1'),
262 ('__BUILDMACHINE__', 'WinDDK'),
266 cppdefines
+= [('DBG', 1)]
267 if platform
== 'wince':
269 '_CRT_SECURE_NO_DEPRECATE',
274 ('_WIN32_WCE', '0x600'),
282 ('INTLMSG_CODEPAGE', '1252'),
284 env
.Append(CPPDEFINES
= cppdefines
)
286 # C preprocessor includes
287 if platform
== 'winddk':
288 env
.Append(CPPPATH
= [
298 ccflags
= [] # C & C++
301 ccflags
+= ['-O0', '-g3']
302 elif env
['toolchain'] == 'crossmingw':
303 ccflags
+= ['-O0', '-g3'] # mingw 4.2.1 optimizer is broken
305 ccflags
+= ['-O3', '-g0']
306 if env
['machine'] == 'x86':
310 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
313 if env
['machine'] == 'x86_64':
316 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
319 '-Wmissing-field-initializers',
323 '-fmessage-length=0', # be nice to Eclipse
326 '-Werror=declaration-after-statement',
327 '-Wmissing-prototypes',
332 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
336 '/Od', # disable optimizations
337 '/Oi', # enable intrinsic functions
338 '/Oy-', # disable frame pointer omission
339 '/GL-', # disable whole program optimization
343 '/Ox', # maximum optimizations
344 '/Oi', # enable intrinsic functions
345 '/Ot', # favor code speed
346 #'/fp:fast', # fast floating point
349 '/W3', # warning level
350 #'/Wp64', # enable 64 bit porting warnings
352 if env
['machine'] == 'x86':
354 #'/QIfist', # Suppress _ftol
355 #'/arch:SSE2', # use the SSE2 instructions
357 if platform
== 'windows':
361 if platform
== 'winddk':
363 '/Zl', # omit default library name in .OBJ
364 '/Zp8', # 8bytes struct member alignment
365 '/Gy', # separate functions for linker
366 '/Gm-', # disable minimal rebuild
367 '/WX', # treat warnings as errors
368 '/Gz', # __stdcall Calling convention
369 '/GX-', # disable C++ EH
370 '/GR-', # disable C++ RTTI
371 '/GF', # enable read-only string pooling
372 '/G6', # optimize for PPro, P-II, P-III
373 '/Ze', # enable extensions
374 '/Gi-', # disable incremental compilation
375 '/QIfdiv-', # disable Pentium FDIV fix
376 '/hotpatch', # prepares an image for hotpatching.
377 #'/Z7', #enable old-style debug info
379 if platform
== 'wince':
380 # See also C:\WINCE600\public\common\oak\misc\makefile.def
382 '/Zl', # omit default library name in .OBJ
383 '/GF', # enable read-only string pooling
384 '/GR-', # disable C++ RTTI
385 '/GS', # enable security checks
386 # Allow disabling language conformance to maintain backward compat
387 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
388 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
394 # Automatic pdb generation
395 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
396 env
.EnsureSConsVersion(0, 98, 0)
397 env
['PDB'] = '${TARGET.base}.pdb'
398 env
.Append(CCFLAGS
= ccflags
)
399 env
.Append(CFLAGS
= cflags
)
400 env
.Append(CXXFLAGS
= cxxflags
)
402 if env
['platform'] == 'windows' and msvc
:
403 # Choose the appropriate MSVC CRT
404 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
406 env
.Append(CCFLAGS
= ['/MTd'])
407 env
.Append(SHCCFLAGS
= ['/LDd'])
409 env
.Append(CCFLAGS
= ['/MT'])
410 env
.Append(SHCCFLAGS
= ['/LD'])
414 if env
['machine'] == 'x86':
415 env
.Append(ASFLAGS
= ['-m32'])
416 if env
['machine'] == 'x86_64':
417 env
.Append(ASFLAGS
= ['-m64'])
422 if env
['machine'] == 'x86':
423 linkflags
+= ['-m32']
424 if env
['machine'] == 'x86_64':
425 linkflags
+= ['-m64']
426 if platform
== 'windows' and msvc
:
428 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
433 if platform
== 'winddk':
436 '/merge:_TEXT=.text',
440 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
453 '/stack:0x40000,0x1000',
456 '/subsystem:native,5.01',
459 '/entry:DrvEnableDriver',
461 if env
['debug'] or env
['profile']:
463 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
465 if platform
== 'wince':
470 '/entry:_DllMainCRTStartup',
472 env
.Append(LINKFLAGS
= linkflags
)
475 env
.Append(LIBS
= [])
477 # Custom builders and methods
479 createInstallMethods(env
)