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.
42 def symlink(target
, source
, env
):
43 target
= str(target
[0])
44 source
= str(source
[0])
45 if os
.path
.islink(target
) or os
.path
.exists(target
):
47 os
.symlink(os
.path
.basename(source
), target
)
49 def install(env
, source
, subdir
):
50 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], subdir
)
51 env
.Install(target_dir
, source
)
53 def install_program(env
, source
):
54 install(env
, source
, 'bin')
56 def install_shared_library(env
, sources
, version
= ()):
57 install_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'])
58 version
= tuple(map(str, version
))
59 if env
['SHLIBSUFFIX'] == '.dll':
60 dlls
= env
.FindIxes(sources
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
61 install(env
, dlls
, 'bin')
62 libs
= env
.FindIxes(sources
, 'LIBPREFIX', 'LIBSUFFIX')
63 install(env
, libs
, 'lib')
65 for source
in sources
:
66 target_dir
= os
.path
.join(install_dir
, 'lib')
67 target_name
= '.'.join((str(source
),) + version
)
68 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
70 version
= version
[:-1]
71 target_name
= '.'.join((str(source
),) + version
)
72 action
= SCons
.Action
.Action(symlink
, "$TARGET -> $SOURCE")
73 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
75 def createInstallMethods(env
):
76 env
.AddMethod(install_program
, 'InstallProgram')
77 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
82 return int(os
.environ
['NUMBER_OF_PROCESSORS'])
83 except (ValueError, KeyError):
87 return os
.sysconf('SC_NPROCESSORS_ONLN')
88 except (ValueError, OSError, AttributeError):
92 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
100 """Common environment generation code"""
103 platform
= env
['platform']
104 if env
['toolchain'] == 'default':
105 if platform
== 'winddk':
106 env
['toolchain'] = 'winddk'
107 elif platform
== 'wince':
108 env
['toolchain'] = 'wcesdk'
109 env
.Tool(env
['toolchain'])
111 env
['gcc'] = 'gcc' in os
.path
.basename(env
['CC']).split('-')
112 env
['msvc'] = env
['CC'] == 'cl'
116 machine
= env
['machine']
117 platform
= env
['platform']
118 x86
= env
['machine'] == 'x86'
119 ppc
= env
['machine'] == 'ppc'
123 # Put build output in a separate dir, which depends on the current
124 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
125 build_topdir
= 'build'
126 build_subdir
= env
['platform']
128 build_subdir
+= "-llvm"
129 if env
['machine'] != 'generic':
130 build_subdir
+= '-' + env
['machine']
132 build_subdir
+= "-debug"
134 build_subdir
+= "-profile"
135 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
136 # Place the .sconsign file in the build dir too, to avoid issues with
137 # different scons versions building the same source file
138 env
['build'] = build_dir
139 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
140 env
.CacheDir('build/cache')
141 env
['CONFIGUREDIR'] = os
.path
.join(build_dir
, 'conf')
142 env
['CONFIGURELOG'] = os
.path
.join(os
.path
.abspath(build_dir
), 'config.log')
145 if env
.GetOption('num_jobs') <= 1:
146 env
.SetOption('num_jobs', num_jobs())
148 # C preprocessor options
151 cppdefines
+= ['DEBUG']
153 cppdefines
+= ['NDEBUG']
155 cppdefines
+= ['PROFILE']
156 if platform
== 'windows':
162 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
163 ('WINVER', '0x0501'),
165 if msvc
and env
['toolchain'] != 'winddk':
169 '_CRT_SECURE_NO_WARNINGS',
170 '_CRT_SECURE_NO_DEPRECATE',
171 '_SCL_SECURE_NO_WARNINGS',
172 '_SCL_SECURE_NO_DEPRECATE',
175 cppdefines
+= ['_DEBUG']
176 if env
['toolchain'] == 'winddk':
177 # Mimic WINDDK's builtin flags. See also:
178 # - WINDDK's bin/makefile.new i386mk.inc for more info.
179 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
180 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
182 cppdefines
+= ['_X86_', 'i386']
183 if machine
== 'x86_64':
184 cppdefines
+= ['_AMD64_', 'AMD64']
185 if platform
== 'winddk':
188 ('CONDITION_HANDLING', '1'),
193 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
194 ('WINVER', '0x0501'),
195 ('_WIN32_IE', '0x0603'),
196 ('WIN32_LEAN_AND_MEAN', '1'),
198 ('__BUILDMACHINE__', 'WinDDK'),
202 cppdefines
+= [('DBG', 1)]
203 if platform
== 'wince':
205 '_CRT_SECURE_NO_DEPRECATE',
210 ('_WIN32_WCE', '0x600'),
218 ('INTLMSG_CODEPAGE', '1252'),
220 if platform
== 'windows':
221 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
222 if platform
== 'winddk':
223 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
224 if platform
== 'wince':
225 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE']
226 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
227 env
.Append(CPPDEFINES
= cppdefines
)
232 ccflags
= [] # C & C++
235 ccflags
+= ['-O0', '-g3']
236 elif env
['CCVERSION'].startswith('4.2.'):
237 # gcc 4.2.x optimizer is broken
238 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
239 ccflags
+= ['-O0', '-g3']
241 ccflags
+= ['-O3', '-g3']
243 # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
245 '-fno-omit-frame-pointer',
246 '-fno-optimize-sibling-calls',
248 if env
['machine'] == 'x86':
254 if platform
!= 'windows':
255 # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
256 # for -mincoming-stack-boundary=2. Still enable it on other
257 # platforms for now, but we can't rely on it for cross platform
258 # code. We have to use __attribute__((force_align_arg_pointer))
261 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
262 '-mstackrealign', # ensure stack is aligned
264 if env
['machine'] == 'x86_64':
267 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
270 '-Wmissing-field-initializers',
271 '-Werror=pointer-arith',
274 '-fmessage-length=0', # be nice to Eclipse
277 '-Werror=declaration-after-statement',
278 '-Wmissing-prototypes',
283 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
287 '/Od', # disable optimizations
288 '/Oi', # enable intrinsic functions
289 '/Oy-', # disable frame pointer omission
290 '/GL-', # disable whole program optimization
294 '/O2', # optimize for speed
295 '/GL', # enable whole program optimization
298 '/fp:fast', # fast floating point
299 '/W3', # warning level
300 #'/Wp64', # enable 64 bit porting warnings
302 if env
['machine'] == 'x86':
304 #'/arch:SSE2', # use the SSE2 instructions
306 if platform
== 'windows':
310 if platform
== 'winddk':
312 '/Zl', # omit default library name in .OBJ
313 '/Zp8', # 8bytes struct member alignment
314 '/Gy', # separate functions for linker
315 '/Gm-', # disable minimal rebuild
316 '/WX', # treat warnings as errors
317 '/Gz', # __stdcall Calling convention
318 '/GX-', # disable C++ EH
319 '/GR-', # disable C++ RTTI
320 '/GF', # enable read-only string pooling
321 '/G6', # optimize for PPro, P-II, P-III
322 '/Ze', # enable extensions
323 '/Gi-', # disable incremental compilation
324 '/QIfdiv-', # disable Pentium FDIV fix
325 '/hotpatch', # prepares an image for hotpatching.
326 #'/Z7', #enable old-style debug info
328 if platform
== 'wince':
329 # See also C:\WINCE600\public\common\oak\misc\makefile.def
331 '/Zl', # omit default library name in .OBJ
332 '/GF', # enable read-only string pooling
333 '/GR-', # disable C++ RTTI
334 '/GS', # enable security checks
335 # Allow disabling language conformance to maintain backward compat
336 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
337 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
343 # Automatic pdb generation
344 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
345 env
.EnsureSConsVersion(0, 98, 0)
346 env
['PDB'] = '${TARGET.base}.pdb'
347 env
.Append(CCFLAGS
= ccflags
)
348 env
.Append(CFLAGS
= cflags
)
349 env
.Append(CXXFLAGS
= cxxflags
)
351 if env
['platform'] == 'windows' and msvc
:
352 # Choose the appropriate MSVC CRT
353 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
355 env
.Append(CCFLAGS
= ['/MTd'])
356 env
.Append(SHCCFLAGS
= ['/LDd'])
358 env
.Append(CCFLAGS
= ['/MT'])
359 env
.Append(SHCCFLAGS
= ['/LD'])
363 if env
['machine'] == 'x86':
364 env
.Append(ASFLAGS
= ['-m32'])
365 if env
['machine'] == 'x86_64':
366 env
.Append(ASFLAGS
= ['-m64'])
372 if env
['machine'] == 'x86':
373 linkflags
+= ['-m32']
374 if env
['machine'] == 'x86_64':
375 linkflags
+= ['-m64']
379 # Handle circular dependencies in the libraries
380 env
['_LIBFLAGS'] = '-Wl,--start-group ' + env
['_LIBFLAGS'] + ' -Wl,--end-group'
383 # enable Link-time Code Generation
384 linkflags
+= ['/LTCG']
385 env
.Append(ARFLAGS
= ['/LTCG'])
386 if platform
== 'windows' and msvc
:
388 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
393 if platform
== 'winddk':
396 '/merge:_TEXT=.text',
400 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
413 '/stack:0x40000,0x1000',
416 '/subsystem:native,5.01',
419 '/entry:DrvEnableDriver',
421 if env
['debug'] or env
['profile']:
423 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
425 if platform
== 'wince':
430 '/entry:_DllMainCRTStartup',
432 env
.Append(LINKFLAGS
= linkflags
)
433 env
.Append(SHLINKFLAGS
= shlinkflags
)
436 env
.Append(LIBS
= [])
438 # Custom builders and methods
440 createInstallMethods(env
)