3 Frontend-tool for Gallium3D architecture.
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.
33 import distutils
.version
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(env
, source
, subdir
):
52 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], subdir
)
53 env
.Install(target_dir
, source
)
55 def install_program(env
, source
):
56 install(env
, source
, 'bin')
58 def install_shared_library(env
, sources
, version
= ()):
59 install_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'])
60 version
= tuple(map(str, version
))
61 if env
['SHLIBSUFFIX'] == '.dll':
62 dlls
= env
.FindIxes(sources
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
63 install(env
, dlls
, 'bin')
64 libs
= env
.FindIxes(sources
, 'LIBPREFIX', 'LIBSUFFIX')
65 install(env
, libs
, 'lib')
67 for source
in sources
:
68 target_dir
= os
.path
.join(install_dir
, 'lib')
69 target_name
= '.'.join((str(source
),) + version
)
70 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
72 version
= version
[:-1]
73 target_name
= '.'.join((str(source
),) + version
)
74 action
= SCons
.Action
.Action(symlink
, "$TARGET -> $SOURCE")
75 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
77 def createInstallMethods(env
):
78 env
.AddMethod(install_program
, 'InstallProgram')
79 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
84 return int(os
.environ
['NUMBER_OF_PROCESSORS'])
85 except (ValueError, KeyError):
89 return os
.sysconf('SC_NPROCESSORS_ONLN')
90 except (ValueError, OSError, AttributeError):
94 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
102 """Common environment generation code"""
105 platform
= env
['platform']
106 if env
['toolchain'] == 'default':
107 if platform
== 'winddk':
108 env
['toolchain'] = 'winddk'
109 elif platform
== 'wince':
110 env
['toolchain'] = 'wcesdk'
111 env
.Tool(env
['toolchain'])
113 if os
.environ
.has_key('CC'):
114 env
['CC'] = os
.environ
['CC']
116 env
['gcc'] = 'gcc' in os
.path
.basename(env
['CC']).split('-')
117 env
['msvc'] = env
['CC'] == 'cl'
121 machine
= env
['machine']
122 platform
= env
['platform']
123 x86
= env
['machine'] == 'x86'
124 ppc
= env
['machine'] == 'ppc'
128 # Put build output in a separate dir, which depends on the current
129 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
130 build_topdir
= 'build'
131 build_subdir
= env
['platform']
133 build_subdir
+= "-llvm"
134 if env
['machine'] != 'generic':
135 build_subdir
+= '-' + env
['machine']
137 build_subdir
+= "-debug"
139 build_subdir
+= "-profile"
140 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
141 # Place the .sconsign file in the build dir too, to avoid issues with
142 # different scons versions building the same source file
143 env
['build'] = build_dir
144 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
145 env
.CacheDir('build/cache')
146 env
['CONFIGUREDIR'] = os
.path
.join(build_dir
, 'conf')
147 env
['CONFIGURELOG'] = os
.path
.join(os
.path
.abspath(build_dir
), 'config.log')
150 if env
.GetOption('num_jobs') <= 1:
151 env
.SetOption('num_jobs', num_jobs())
153 # C preprocessor options
156 cppdefines
+= ['DEBUG']
158 cppdefines
+= ['NDEBUG']
160 cppdefines
+= ['PROFILE']
161 if platform
== 'windows':
167 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
168 ('WINVER', '0x0501'),
170 if msvc
and env
['toolchain'] != 'winddk':
174 '_CRT_SECURE_NO_WARNINGS',
175 '_CRT_SECURE_NO_DEPRECATE',
176 '_SCL_SECURE_NO_WARNINGS',
177 '_SCL_SECURE_NO_DEPRECATE',
180 cppdefines
+= ['_DEBUG']
181 if env
['toolchain'] == 'winddk':
182 # Mimic WINDDK's builtin flags. See also:
183 # - WINDDK's bin/makefile.new i386mk.inc for more info.
184 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
185 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
187 cppdefines
+= ['_X86_', 'i386']
188 if machine
== 'x86_64':
189 cppdefines
+= ['_AMD64_', 'AMD64']
190 if platform
== 'winddk':
193 ('CONDITION_HANDLING', '1'),
198 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
199 ('WINVER', '0x0501'),
200 ('_WIN32_IE', '0x0603'),
201 ('WIN32_LEAN_AND_MEAN', '1'),
203 ('__BUILDMACHINE__', 'WinDDK'),
207 cppdefines
+= [('DBG', 1)]
208 if platform
== 'wince':
210 '_CRT_SECURE_NO_DEPRECATE',
215 ('_WIN32_WCE', '0x600'),
223 ('INTLMSG_CODEPAGE', '1252'),
225 if platform
== 'windows':
226 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
227 if platform
== 'winddk':
228 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
229 if platform
== 'wince':
230 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE']
231 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
232 if platform
== 'embedded':
233 cppdefines
+= ['PIPE_SUBSYSTEM_EMBEDDED']
234 env
.Append(CPPDEFINES
= cppdefines
)
239 ccflags
= [] # C & C++
242 pipe
= SCons
.Action
._subproc
(env
, [env
['CC'], '--version'],
245 stdout
= subprocess
.PIPE
)
247 line
= pipe
.stdout
.readline()
248 match
= re
.search(r
'[0-9]+(\.[0-9]+)+', line
)
250 ccversion
= match
.group(0)
252 ccflags
+= ['-O0', '-g3']
253 elif ccversion
.startswith('4.2.'):
254 # gcc 4.2.x optimizer is broken
255 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
256 ccflags
+= ['-O0', '-g3']
258 ccflags
+= ['-O3', '-g3']
260 # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
262 '-fno-omit-frame-pointer',
263 '-fno-optimize-sibling-calls',
265 if env
['machine'] == 'x86':
271 if platform
!= 'windows':
272 # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
273 # for -mincoming-stack-boundary=2. Still enable it on other
274 # platforms for now, but we can't rely on it for cross platform
275 # code. We have to use __attribute__((force_align_arg_pointer))
278 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
280 if distutils
.version
.LooseVersion(ccversion
) >= distutils
.version
.LooseVersion('4.2'):
282 '-mstackrealign', # ensure stack is aligned
284 if env
['machine'] == 'x86_64':
287 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
290 '-Wmissing-field-initializers',
293 '-fmessage-length=0', # be nice to Eclipse
296 '-Wmissing-prototypes',
299 if distutils
.version
.LooseVersion(ccversion
) >= distutils
.version
.LooseVersion('4.2'):
301 '-Werror=pointer-arith',
304 '-Werror=declaration-after-statement',
308 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
312 '/Od', # disable optimizations
313 '/Oi', # enable intrinsic functions
314 '/Oy-', # disable frame pointer omission
315 '/GL-', # disable whole program optimization
319 '/O2', # optimize for speed
320 '/GL', # enable whole program optimization
323 '/fp:fast', # fast floating point
324 '/W3', # warning level
325 #'/Wp64', # enable 64 bit porting warnings
327 if env
['machine'] == 'x86':
329 #'/arch:SSE2', # use the SSE2 instructions
331 if platform
== 'windows':
335 if platform
== 'winddk':
337 '/Zl', # omit default library name in .OBJ
338 '/Zp8', # 8bytes struct member alignment
339 '/Gy', # separate functions for linker
340 '/Gm-', # disable minimal rebuild
341 '/WX', # treat warnings as errors
342 '/Gz', # __stdcall Calling convention
343 '/GX-', # disable C++ EH
344 '/GR-', # disable C++ RTTI
345 '/GF', # enable read-only string pooling
346 '/G6', # optimize for PPro, P-II, P-III
347 '/Ze', # enable extensions
348 '/Gi-', # disable incremental compilation
349 '/QIfdiv-', # disable Pentium FDIV fix
350 '/hotpatch', # prepares an image for hotpatching.
351 #'/Z7', #enable old-style debug info
353 if platform
== 'wince':
354 # See also C:\WINCE600\public\common\oak\misc\makefile.def
356 '/Zl', # omit default library name in .OBJ
357 '/GF', # enable read-only string pooling
358 '/GR-', # disable C++ RTTI
359 '/GS', # enable security checks
360 # Allow disabling language conformance to maintain backward compat
361 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
362 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
368 # Automatic pdb generation
369 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
370 env
.EnsureSConsVersion(0, 98, 0)
371 env
['PDB'] = '${TARGET.base}.pdb'
372 env
.Append(CCFLAGS
= ccflags
)
373 env
.Append(CFLAGS
= cflags
)
374 env
.Append(CXXFLAGS
= cxxflags
)
376 if env
['platform'] == 'windows' and msvc
:
377 # Choose the appropriate MSVC CRT
378 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
380 env
.Append(CCFLAGS
= ['/MTd'])
381 env
.Append(SHCCFLAGS
= ['/LDd'])
383 env
.Append(CCFLAGS
= ['/MT'])
384 env
.Append(SHCCFLAGS
= ['/LD'])
388 if env
['machine'] == 'x86':
389 env
.Append(ASFLAGS
= ['-m32'])
390 if env
['machine'] == 'x86_64':
391 env
.Append(ASFLAGS
= ['-m64'])
397 if env
['machine'] == 'x86':
398 linkflags
+= ['-m32']
399 if env
['machine'] == 'x86_64':
400 linkflags
+= ['-m64']
401 if env
['platform'] not in ('darwin'):
405 # Handle circular dependencies in the libraries
406 if env
['platform'] in ('darwin'):
409 env
['_LIBFLAGS'] = '-Wl,--start-group ' + env
['_LIBFLAGS'] + ' -Wl,--end-group'
412 # enable Link-time Code Generation
413 linkflags
+= ['/LTCG']
414 env
.Append(ARFLAGS
= ['/LTCG'])
415 if platform
== 'windows' and msvc
:
417 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
422 if platform
== 'winddk':
425 '/merge:_TEXT=.text',
429 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
442 '/stack:0x40000,0x1000',
445 '/subsystem:native,5.01',
448 '/entry:DrvEnableDriver',
450 if env
['debug'] or env
['profile']:
452 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
454 if platform
== 'wince':
459 '/entry:_DllMainCRTStartup',
461 env
.Append(LINKFLAGS
= linkflags
)
462 env
.Append(SHLINKFLAGS
= shlinkflags
)
465 env
.Append(LIBS
= [])
467 # Custom builders and methods
469 createInstallMethods(env
)