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 env
.Append(CPPDEFINES
= cppdefines
)
237 ccflags
= [] # C & C++
240 pipe
= SCons
.Action
._subproc
(env
, [env
['CC'], '--version'],
243 stdout
= subprocess
.PIPE
)
245 line
= pipe
.stdout
.readline()
246 match
= re
.search(r
'[0-9]+(\.[0-9]+)+', line
)
248 ccversion
= match
.group(0)
250 ccflags
+= ['-O0', '-g3']
251 elif ccversion
.startswith('4.2.'):
252 # gcc 4.2.x optimizer is broken
253 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
254 ccflags
+= ['-O0', '-g3']
256 ccflags
+= ['-O3', '-g3']
258 # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
260 '-fno-omit-frame-pointer',
261 '-fno-optimize-sibling-calls',
263 if env
['machine'] == 'x86':
269 if platform
!= 'windows':
270 # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
271 # for -mincoming-stack-boundary=2. Still enable it on other
272 # platforms for now, but we can't rely on it for cross platform
273 # code. We have to use __attribute__((force_align_arg_pointer))
276 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
277 '-mstackrealign', # ensure stack is aligned
279 if env
['machine'] == 'x86_64':
282 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
285 '-Wmissing-field-initializers',
288 '-fmessage-length=0', # be nice to Eclipse
291 '-Wmissing-prototypes',
294 if distutils
.version
.LooseVersion(ccversion
) >= distutils
.version
.LooseVersion('4.2'):
296 '-Werror=pointer-arith',
299 '-Werror=declaration-after-statement',
303 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
307 '/Od', # disable optimizations
308 '/Oi', # enable intrinsic functions
309 '/Oy-', # disable frame pointer omission
310 '/GL-', # disable whole program optimization
314 '/O2', # optimize for speed
315 '/GL', # enable whole program optimization
318 '/fp:fast', # fast floating point
319 '/W3', # warning level
320 #'/Wp64', # enable 64 bit porting warnings
322 if env
['machine'] == 'x86':
324 #'/arch:SSE2', # use the SSE2 instructions
326 if platform
== 'windows':
330 if platform
== 'winddk':
332 '/Zl', # omit default library name in .OBJ
333 '/Zp8', # 8bytes struct member alignment
334 '/Gy', # separate functions for linker
335 '/Gm-', # disable minimal rebuild
336 '/WX', # treat warnings as errors
337 '/Gz', # __stdcall Calling convention
338 '/GX-', # disable C++ EH
339 '/GR-', # disable C++ RTTI
340 '/GF', # enable read-only string pooling
341 '/G6', # optimize for PPro, P-II, P-III
342 '/Ze', # enable extensions
343 '/Gi-', # disable incremental compilation
344 '/QIfdiv-', # disable Pentium FDIV fix
345 '/hotpatch', # prepares an image for hotpatching.
346 #'/Z7', #enable old-style debug info
348 if platform
== 'wince':
349 # See also C:\WINCE600\public\common\oak\misc\makefile.def
351 '/Zl', # omit default library name in .OBJ
352 '/GF', # enable read-only string pooling
353 '/GR-', # disable C++ RTTI
354 '/GS', # enable security checks
355 # Allow disabling language conformance to maintain backward compat
356 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
357 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
363 # Automatic pdb generation
364 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
365 env
.EnsureSConsVersion(0, 98, 0)
366 env
['PDB'] = '${TARGET.base}.pdb'
367 env
.Append(CCFLAGS
= ccflags
)
368 env
.Append(CFLAGS
= cflags
)
369 env
.Append(CXXFLAGS
= cxxflags
)
371 if env
['platform'] == 'windows' and msvc
:
372 # Choose the appropriate MSVC CRT
373 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
375 env
.Append(CCFLAGS
= ['/MTd'])
376 env
.Append(SHCCFLAGS
= ['/LDd'])
378 env
.Append(CCFLAGS
= ['/MT'])
379 env
.Append(SHCCFLAGS
= ['/LD'])
383 if env
['machine'] == 'x86':
384 env
.Append(ASFLAGS
= ['-m32'])
385 if env
['machine'] == 'x86_64':
386 env
.Append(ASFLAGS
= ['-m64'])
392 if env
['machine'] == 'x86':
393 linkflags
+= ['-m32']
394 if env
['machine'] == 'x86_64':
395 linkflags
+= ['-m64']
396 if env
['platform'] not in ('darwin'):
400 # Handle circular dependencies in the libraries
401 if env
['platform'] in ('darwin'):
404 env
['_LIBFLAGS'] = '-Wl,--start-group ' + env
['_LIBFLAGS'] + ' -Wl,--end-group'
407 # enable Link-time Code Generation
408 linkflags
+= ['/LTCG']
409 env
.Append(ARFLAGS
= ['/LTCG'])
410 if platform
== 'windows' and msvc
:
412 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
417 if platform
== 'winddk':
420 '/merge:_TEXT=.text',
424 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
437 '/stack:0x40000,0x1000',
440 '/subsystem:native,5.01',
443 '/entry:DrvEnableDriver',
445 if env
['debug'] or env
['profile']:
447 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
449 if platform
== 'wince':
454 '/entry:_DllMainCRTStartup',
456 env
.Append(LINKFLAGS
= linkflags
)
457 env
.Append(SHLINKFLAGS
= shlinkflags
)
460 env
.Append(LIBS
= [])
462 # Custom builders and methods
464 createInstallMethods(env
)