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_program(env
, source
):
50 source
= str(source
[0])
51 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], 'bin')
52 target_name
= str(source
)
53 env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
55 def install_shared_library(env
, source
, version
= ()):
56 source
= str(source
[0])
57 version
= tuple(map(str, version
))
58 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], 'lib')
59 if env
['SHLIBSUFFIX'] == '.so':
60 target_name
= '.'.join((str(source
),) + version
)
61 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
63 version
= version
[:-1]
64 target_name
= '.'.join((str(source
),) + version
)
65 action
= SCons
.Action
.Action(symlink
, "$TARGET -> $SOURCE")
66 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
68 target_name
= str(source
)
69 env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
71 def createInstallMethods(env
):
72 env
.AddMethod(install_program
, 'InstallProgram')
73 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
78 return int(os
.environ
['NUMBER_OF_PROCESSORS'])
79 except (ValueError, KeyError):
83 return os
.sysconf('SC_NPROCESSORS_ONLN')
84 except (ValueError, OSError, AttributeError):
88 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
96 """Common environment generation code"""
99 platform
= env
['platform']
100 if env
['toolchain'] == 'default':
101 if platform
== 'winddk':
102 env
['toolchain'] = 'winddk'
103 elif platform
== 'wince':
104 env
['toolchain'] = 'wcesdk'
105 env
.Tool(env
['toolchain'])
107 env
['gcc'] = 'gcc' in os
.path
.basename(env
['CC']).split('-')
108 env
['msvc'] = env
['CC'] == 'cl'
112 machine
= env
['machine']
113 platform
= env
['platform']
114 x86
= env
['machine'] == 'x86'
115 ppc
= env
['machine'] == 'ppc'
119 # Put build output in a separate dir, which depends on the current
120 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
121 build_topdir
= 'build'
122 build_subdir
= env
['platform']
124 build_subdir
+= "-llvm"
125 if env
['machine'] != 'generic':
126 build_subdir
+= '-' + env
['machine']
128 build_subdir
+= "-debug"
130 build_subdir
+= "-profile"
131 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
132 # Place the .sconsign file in the build dir too, to avoid issues with
133 # different scons versions building the same source file
134 env
['build'] = build_dir
135 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
136 env
.CacheDir('build/cache')
137 env
['CONFIGUREDIR'] = os
.path
.join(build_dir
, 'conf')
138 env
['CONFIGURELOG'] = os
.path
.join(os
.path
.abspath(build_dir
), 'config.log')
141 if env
.GetOption('num_jobs') <= 1:
142 env
.SetOption('num_jobs', num_jobs())
144 # C preprocessor options
147 cppdefines
+= ['DEBUG']
149 cppdefines
+= ['NDEBUG']
151 cppdefines
+= ['PROFILE']
152 if platform
== 'windows':
158 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
159 ('WINVER', '0x0501'),
161 if msvc
and env
['toolchain'] != 'winddk':
165 '_CRT_SECURE_NO_WARNINGS',
166 '_CRT_SECURE_NO_DEPRECATE',
167 '_SCL_SECURE_NO_WARNINGS',
168 '_SCL_SECURE_NO_DEPRECATE',
171 cppdefines
+= ['_DEBUG']
172 if env
['toolchain'] == 'winddk':
173 # Mimic WINDDK's builtin flags. See also:
174 # - WINDDK's bin/makefile.new i386mk.inc for more info.
175 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
176 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
178 cppdefines
+= ['_X86_', 'i386']
179 if machine
== 'x86_64':
180 cppdefines
+= ['_AMD64_', 'AMD64']
181 if platform
== 'winddk':
184 ('CONDITION_HANDLING', '1'),
189 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
190 ('WINVER', '0x0501'),
191 ('_WIN32_IE', '0x0603'),
192 ('WIN32_LEAN_AND_MEAN', '1'),
194 ('__BUILDMACHINE__', 'WinDDK'),
198 cppdefines
+= [('DBG', 1)]
199 if platform
== 'wince':
201 '_CRT_SECURE_NO_DEPRECATE',
206 ('_WIN32_WCE', '0x600'),
214 ('INTLMSG_CODEPAGE', '1252'),
216 if platform
== 'windows':
217 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
218 if platform
== 'winddk':
219 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
220 if platform
== 'wince':
221 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE']
222 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
223 env
.Append(CPPDEFINES
= cppdefines
)
228 ccflags
= [] # C & C++
231 ccflags
+= ['-O0', '-g3']
232 elif env
['CCVERSION'].startswith('4.2.'):
233 # gcc 4.2.x optimizer is broken
234 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
235 ccflags
+= ['-O0', '-g3']
237 ccflags
+= ['-O3', '-g3']
239 # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
241 '-fno-omit-frame-pointer',
242 '-fno-optimize-sibling-calls',
244 if env
['machine'] == 'x86':
250 if platform
!= 'windows':
251 # XXX: -mstackrealign causes stack corruption on MinGW. Ditto
252 # for -mincoming-stack-boundary=2. Still enable it on other
253 # platforms for now, but we can't rely on it for cross platform
254 # code. We have to use __attribute__((force_align_arg_pointer))
257 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
258 '-mstackrealign', # ensure stack is aligned
260 if env
['machine'] == 'x86_64':
263 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
266 '-Wmissing-field-initializers',
267 '-Werror=pointer-arith',
270 '-fmessage-length=0', # be nice to Eclipse
273 '-Werror=declaration-after-statement',
274 '-Wmissing-prototypes',
279 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
283 '/Od', # disable optimizations
284 '/Oi', # enable intrinsic functions
285 '/Oy-', # disable frame pointer omission
286 '/GL-', # disable whole program optimization
290 '/O2', # optimize for speed
291 '/GL', # enable whole program optimization
294 '/fp:fast', # fast floating point
295 '/W3', # warning level
296 #'/Wp64', # enable 64 bit porting warnings
298 if env
['machine'] == 'x86':
300 #'/arch:SSE2', # use the SSE2 instructions
302 if platform
== 'windows':
306 if platform
== 'winddk':
308 '/Zl', # omit default library name in .OBJ
309 '/Zp8', # 8bytes struct member alignment
310 '/Gy', # separate functions for linker
311 '/Gm-', # disable minimal rebuild
312 '/WX', # treat warnings as errors
313 '/Gz', # __stdcall Calling convention
314 '/GX-', # disable C++ EH
315 '/GR-', # disable C++ RTTI
316 '/GF', # enable read-only string pooling
317 '/G6', # optimize for PPro, P-II, P-III
318 '/Ze', # enable extensions
319 '/Gi-', # disable incremental compilation
320 '/QIfdiv-', # disable Pentium FDIV fix
321 '/hotpatch', # prepares an image for hotpatching.
322 #'/Z7', #enable old-style debug info
324 if platform
== 'wince':
325 # See also C:\WINCE600\public\common\oak\misc\makefile.def
327 '/Zl', # omit default library name in .OBJ
328 '/GF', # enable read-only string pooling
329 '/GR-', # disable C++ RTTI
330 '/GS', # enable security checks
331 # Allow disabling language conformance to maintain backward compat
332 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
333 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
339 # Automatic pdb generation
340 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
341 env
.EnsureSConsVersion(0, 98, 0)
342 env
['PDB'] = '${TARGET.base}.pdb'
343 env
.Append(CCFLAGS
= ccflags
)
344 env
.Append(CFLAGS
= cflags
)
345 env
.Append(CXXFLAGS
= cxxflags
)
347 if env
['platform'] == 'windows' and msvc
:
348 # Choose the appropriate MSVC CRT
349 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
351 env
.Append(CCFLAGS
= ['/MTd'])
352 env
.Append(SHCCFLAGS
= ['/LDd'])
354 env
.Append(CCFLAGS
= ['/MT'])
355 env
.Append(SHCCFLAGS
= ['/LD'])
359 if env
['machine'] == 'x86':
360 env
.Append(ASFLAGS
= ['-m32'])
361 if env
['machine'] == 'x86_64':
362 env
.Append(ASFLAGS
= ['-m64'])
368 if env
['machine'] == 'x86':
369 linkflags
+= ['-m32']
370 if env
['machine'] == 'x86_64':
371 linkflags
+= ['-m64']
375 # Handle circular dependencies in the libraries
376 env
['_LIBFLAGS'] = '-Wl,--start-group ' + env
['_LIBFLAGS'] + ' -Wl,--end-group'
379 # enable Link-time Code Generation
380 linkflags
+= ['/LTCG']
381 env
.Append(ARFLAGS
= ['/LTCG'])
382 if platform
== 'windows' and msvc
:
384 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
389 if platform
== 'winddk':
392 '/merge:_TEXT=.text',
396 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
409 '/stack:0x40000,0x1000',
412 '/subsystem:native,5.01',
415 '/entry:DrvEnableDriver',
417 if env
['debug'] or env
['profile']:
419 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
421 if platform
== 'wince':
426 '/entry:_DllMainCRTStartup',
428 env
.Append(LINKFLAGS
= linkflags
)
429 env
.Append(SHLINKFLAGS
= shlinkflags
)
432 env
.Append(LIBS
= [])
434 # Custom builders and methods
436 createInstallMethods(env
)