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
43 def symlink(target
, source
, env
):
44 target
= str(target
[0])
45 source
= str(source
[0])
46 if os
.path
.islink(target
) or os
.path
.exists(target
):
48 os
.symlink(os
.path
.basename(source
), target
)
50 def install(env
, source
, subdir
):
51 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], subdir
)
52 env
.Install(target_dir
, source
)
54 def install_program(env
, source
):
55 install(env
, source
, 'bin')
57 def install_shared_library(env
, sources
, version
= ()):
58 install_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'])
59 version
= tuple(map(str, version
))
60 if env
['SHLIBSUFFIX'] == '.dll':
61 dlls
= env
.FindIxes(sources
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
62 install(env
, dlls
, 'bin')
63 libs
= env
.FindIxes(sources
, 'LIBPREFIX', 'LIBSUFFIX')
64 install(env
, libs
, 'lib')
66 for source
in sources
:
67 target_dir
= os
.path
.join(install_dir
, 'lib')
68 target_name
= '.'.join((str(source
),) + version
)
69 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
71 version
= version
[:-1]
72 target_name
= '.'.join((str(source
),) + version
)
73 action
= SCons
.Action
.Action(symlink
, "$TARGET -> $SOURCE")
74 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
76 def createInstallMethods(env
):
77 env
.AddMethod(install_program
, 'InstallProgram')
78 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
83 return int(os
.environ
['NUMBER_OF_PROCESSORS'])
84 except (ValueError, KeyError):
88 return os
.sysconf('SC_NPROCESSORS_ONLN')
89 except (ValueError, OSError, AttributeError):
93 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
101 """Common environment generation code"""
104 platform
= env
['platform']
105 if env
['toolchain'] == 'default':
106 if platform
== 'winddk':
107 env
['toolchain'] = 'winddk'
108 elif platform
== 'wince':
109 env
['toolchain'] = 'wcesdk'
110 env
.Tool(env
['toolchain'])
112 env
['gcc'] = 'gcc' in os
.path
.basename(env
['CC']).split('-')
113 env
['msvc'] = env
['CC'] == 'cl'
117 machine
= env
['machine']
118 platform
= env
['platform']
119 x86
= env
['machine'] == 'x86'
120 ppc
= env
['machine'] == 'ppc'
124 # Put build output in a separate dir, which depends on the current
125 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
126 build_topdir
= 'build'
127 build_subdir
= env
['platform']
129 build_subdir
+= "-llvm"
130 if env
['machine'] != 'generic':
131 build_subdir
+= '-' + env
['machine']
133 build_subdir
+= "-debug"
135 build_subdir
+= "-profile"
136 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
137 # Place the .sconsign file in the build dir too, to avoid issues with
138 # different scons versions building the same source file
139 env
['build'] = build_dir
140 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
141 env
.CacheDir('build/cache')
142 env
['CONFIGUREDIR'] = os
.path
.join(build_dir
, 'conf')
143 env
['CONFIGURELOG'] = os
.path
.join(os
.path
.abspath(build_dir
), 'config.log')
146 if env
.GetOption('num_jobs') <= 1:
147 env
.SetOption('num_jobs', num_jobs())
149 # C preprocessor options
152 cppdefines
+= ['DEBUG']
154 cppdefines
+= ['NDEBUG']
156 cppdefines
+= ['PROFILE']
157 if platform
== 'windows':
163 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
164 ('WINVER', '0x0501'),
166 if msvc
and env
['toolchain'] != 'winddk':
170 '_CRT_SECURE_NO_WARNINGS',
171 '_CRT_SECURE_NO_DEPRECATE',
172 '_SCL_SECURE_NO_WARNINGS',
173 '_SCL_SECURE_NO_DEPRECATE',
176 cppdefines
+= ['_DEBUG']
177 if env
['toolchain'] == 'winddk':
178 # Mimic WINDDK's builtin flags. See also:
179 # - WINDDK's bin/makefile.new i386mk.inc for more info.
180 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
181 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
183 cppdefines
+= ['_X86_', 'i386']
184 if machine
== 'x86_64':
185 cppdefines
+= ['_AMD64_', 'AMD64']
186 if platform
== 'winddk':
189 ('CONDITION_HANDLING', '1'),
194 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
195 ('WINVER', '0x0501'),
196 ('_WIN32_IE', '0x0603'),
197 ('WIN32_LEAN_AND_MEAN', '1'),
199 ('__BUILDMACHINE__', 'WinDDK'),
203 cppdefines
+= [('DBG', 1)]
204 if platform
== 'wince':
206 '_CRT_SECURE_NO_DEPRECATE',
211 ('_WIN32_WCE', '0x600'),
219 ('INTLMSG_CODEPAGE', '1252'),
221 if platform
== 'windows':
222 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
223 if platform
== 'winddk':
224 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
225 if platform
== 'wince':
226 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE']
227 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
228 env
.Append(CPPDEFINES
= cppdefines
)
233 ccflags
= [] # C & C++
236 ccflags
+= ['-O0', '-g3']
237 elif env
['CCVERSION'].startswith('4.2.'):
238 # gcc 4.2.x optimizer is broken
239 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
240 ccflags
+= ['-O0', '-g3']
242 ccflags
+= ['-O3', '-g3']
244 # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
246 '-fno-omit-frame-pointer',
247 '-fno-optimize-sibling-calls',
249 if env
['machine'] == 'x86':
255 if platform
!= 'windows':
256 # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
257 # for -mincoming-stack-boundary=2. Still enable it on other
258 # platforms for now, but we can't rely on it for cross platform
259 # code. We have to use __attribute__((force_align_arg_pointer))
262 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
263 '-mstackrealign', # ensure stack is aligned
265 if env
['machine'] == 'x86_64':
268 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
271 '-Wmissing-field-initializers',
274 '-fmessage-length=0', # be nice to Eclipse
277 '-Wmissing-prototypes',
280 if distutils
.version
.LooseVersion(env
['CCVERSION']) >= distutils
.version
.LooseVersion('4.2'):
282 '-Werror=pointer-arith',
285 '-Werror=declaration-after-statement',
289 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
293 '/Od', # disable optimizations
294 '/Oi', # enable intrinsic functions
295 '/Oy-', # disable frame pointer omission
296 '/GL-', # disable whole program optimization
300 '/O2', # optimize for speed
301 '/GL', # enable whole program optimization
304 '/fp:fast', # fast floating point
305 '/W3', # warning level
306 #'/Wp64', # enable 64 bit porting warnings
308 if env
['machine'] == 'x86':
310 #'/arch:SSE2', # use the SSE2 instructions
312 if platform
== 'windows':
316 if platform
== 'winddk':
318 '/Zl', # omit default library name in .OBJ
319 '/Zp8', # 8bytes struct member alignment
320 '/Gy', # separate functions for linker
321 '/Gm-', # disable minimal rebuild
322 '/WX', # treat warnings as errors
323 '/Gz', # __stdcall Calling convention
324 '/GX-', # disable C++ EH
325 '/GR-', # disable C++ RTTI
326 '/GF', # enable read-only string pooling
327 '/G6', # optimize for PPro, P-II, P-III
328 '/Ze', # enable extensions
329 '/Gi-', # disable incremental compilation
330 '/QIfdiv-', # disable Pentium FDIV fix
331 '/hotpatch', # prepares an image for hotpatching.
332 #'/Z7', #enable old-style debug info
334 if platform
== 'wince':
335 # See also C:\WINCE600\public\common\oak\misc\makefile.def
337 '/Zl', # omit default library name in .OBJ
338 '/GF', # enable read-only string pooling
339 '/GR-', # disable C++ RTTI
340 '/GS', # enable security checks
341 # Allow disabling language conformance to maintain backward compat
342 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
343 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
349 # Automatic pdb generation
350 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
351 env
.EnsureSConsVersion(0, 98, 0)
352 env
['PDB'] = '${TARGET.base}.pdb'
353 env
.Append(CCFLAGS
= ccflags
)
354 env
.Append(CFLAGS
= cflags
)
355 env
.Append(CXXFLAGS
= cxxflags
)
357 if env
['platform'] == 'windows' and msvc
:
358 # Choose the appropriate MSVC CRT
359 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
361 env
.Append(CCFLAGS
= ['/MTd'])
362 env
.Append(SHCCFLAGS
= ['/LDd'])
364 env
.Append(CCFLAGS
= ['/MT'])
365 env
.Append(SHCCFLAGS
= ['/LD'])
369 if env
['machine'] == 'x86':
370 env
.Append(ASFLAGS
= ['-m32'])
371 if env
['machine'] == 'x86_64':
372 env
.Append(ASFLAGS
= ['-m64'])
378 if env
['machine'] == 'x86':
379 linkflags
+= ['-m32']
380 if env
['machine'] == 'x86_64':
381 linkflags
+= ['-m64']
385 # Handle circular dependencies in the libraries
386 if env
['platform'] in ('darwin'):
389 env
['_LIBFLAGS'] = '-Wl,--start-group ' + env
['_LIBFLAGS'] + ' -Wl,--end-group'
392 # enable Link-time Code Generation
393 linkflags
+= ['/LTCG']
394 env
.Append(ARFLAGS
= ['/LTCG'])
395 if platform
== 'windows' and msvc
:
397 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
402 if platform
== 'winddk':
405 '/merge:_TEXT=.text',
409 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
422 '/stack:0x40000,0x1000',
425 '/subsystem:native,5.01',
428 '/entry:DrvEnableDriver',
430 if env
['debug'] or env
['profile']:
432 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
434 if platform
== 'wince':
439 '/entry:_DllMainCRTStartup',
441 env
.Append(LINKFLAGS
= linkflags
)
442 env
.Append(SHLINKFLAGS
= shlinkflags
)
445 env
.Append(LIBS
= [])
447 # Custom builders and methods
449 createInstallMethods(env
)