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 quietCommandLines(env
):
44 # See also http://www.scons.org/wiki/HidingCommandLinesInOutput
45 env
['ASCOMSTR'] = " Assembling $SOURCE ..."
46 env
['ASPPCOMSTR'] = " Assembling $SOURCE ..."
47 env
['CCCOMSTR'] = " Compiling $SOURCE ..."
48 env
['SHCCCOMSTR'] = " Compiling $SOURCE ..."
49 env
['CXXCOMSTR'] = " Compiling $SOURCE ..."
50 env
['SHCXXCOMSTR'] = " Compiling $SOURCE ..."
51 env
['ARCOMSTR'] = " Archiving $TARGET ..."
52 env
['RANLIBCOMSTR'] = " Indexing $TARGET ..."
53 env
['LINKCOMSTR'] = " Linking $TARGET ..."
54 env
['SHLINKCOMSTR'] = " Linking $TARGET ..."
55 env
['LDMODULECOMSTR'] = " Linking $TARGET ..."
56 env
['SWIGCOMSTR'] = " Generating $TARGET ..."
59 def createConvenienceLibBuilder(env
):
60 """This is a utility function that creates the ConvenienceLibrary
61 Builder in an Environment if it is not there already.
63 If it is already there, we return the existing one.
65 Based on the stock StaticLibrary and SharedLibrary builders.
69 convenience_lib
= env
['BUILDERS']['ConvenienceLibrary']
71 action_list
= [ SCons
.Action
.Action("$ARCOM", "$ARCOMSTR") ]
72 if env
.Detect('ranlib'):
73 ranlib_action
= SCons
.Action
.Action("$RANLIBCOM", "$RANLIBCOMSTR")
74 action_list
.append(ranlib_action
)
76 convenience_lib
= SCons
.Builder
.Builder(action
= action_list
,
77 emitter
= '$LIBEMITTER',
78 prefix
= '$LIBPREFIX',
79 suffix
= '$LIBSUFFIX',
80 src_suffix
= '$SHOBJSUFFIX',
81 src_builder
= 'SharedObject')
82 env
['BUILDERS']['ConvenienceLibrary'] = convenience_lib
84 return convenience_lib
87 # TODO: handle import statements with multiple modules
88 # TODO: handle from import statements
89 import_re
= re
.compile(r
'^import\s+(\S+)$', re
.M
)
91 def python_scan(node
, env
, path
):
92 # http://www.scons.org/doc/0.98.5/HTML/scons-user/c2781.html#AEN2789
93 contents
= node
.get_contents()
94 source_dir
= node
.get_dir()
95 imports
= import_re
.findall(contents
)
99 file = os
.path
.join(str(dir), imp
.replace('.', os
.sep
) + '.py')
100 if os
.path
.exists(file):
101 results
.append(env
.File(file))
103 file = os
.path
.join(str(dir), imp
.replace('.', os
.sep
), '__init__.py')
104 if os
.path
.exists(file):
105 results
.append(env
.File(file))
109 python_scanner
= SCons
.Scanner
.Scanner(function
= python_scan
, skeys
= ['.py'])
112 def code_generate(env
, script
, target
, source
, command
):
113 """Method to simplify code generation via python scripts.
115 http://www.scons.org/wiki/UsingCodeGenerators
116 http://www.scons.org/doc/0.98.5/HTML/scons-user/c2768.html
119 # We're generating code using Python scripts, so we have to be
120 # careful with our scons elements. This entry represents
121 # the generator file *in the source directory*.
122 script_src
= env
.File(script
).srcnode()
124 # This command creates generated code *in the build directory*.
125 command
= command
.replace('$SCRIPT', script_src
.path
)
126 code
= env
.Command(target
, source
, command
)
128 # Explicitly mark that the generated code depends on the generator,
129 # and on implicitly imported python modules
130 path
= (script_src
.get_dir(),)
132 deps
+= script_src
.get_implicit_deps(env
, python_scanner
, path
)
133 env
.Depends(code
, deps
)
135 # Running the Python script causes .pyc files to be generated in the
136 # source directory. When we clean up, they should go too. So add side
137 # effects for .pyc files
139 pyc
= env
.File(str(dep
) + 'c')
140 env
.SideEffect(pyc
, code
)
145 def createCodeGenerateMethod(env
):
146 env
.Append(SCANNERS
= python_scanner
)
147 env
.AddMethod(code_generate
, 'CodeGenerate')
150 def symlink(target
, source
, env
):
151 target
= str(target
[0])
152 source
= str(source
[0])
153 if os
.path
.islink(target
) or os
.path
.exists(target
):
155 os
.symlink(os
.path
.basename(source
), target
)
157 def install_shared_library(env
, source
, version
= ()):
158 source
= str(source
[0])
159 version
= tuple(map(str, version
))
160 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], 'lib')
161 target_name
= '.'.join((str(source
),) + version
)
162 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
164 version
= version
[:-1]
165 target_name
= '.'.join((str(source
),) + version
)
166 action
= SCons
.Action
.Action(symlink
, "$TARGET -> $SOURCE")
167 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
169 def createInstallMethods(env
):
170 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
175 return int(os
.environ
['NUMBER_OF_PROCESSORS'])
176 except (ValueError, KeyError):
180 return os
.sysconf('SC_NPROCESSORS_ONLN')
181 except (ValueError, OSError, AttributeError):
185 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
193 """Common environment generation code"""
195 if env
.get('quiet', True):
196 quietCommandLines(env
)
199 platform
= env
['platform']
200 if env
['toolchain'] == 'default':
201 if platform
== 'winddk':
202 env
['toolchain'] = 'winddk'
203 elif platform
== 'wince':
204 env
['toolchain'] = 'wcesdk'
205 env
.Tool(env
['toolchain'])
207 env
['gcc'] = 'gcc' in os
.path
.basename(env
['CC']).split('-')
208 env
['msvc'] = env
['CC'] == 'cl'
212 machine
= env
['machine']
213 platform
= env
['platform']
214 x86
= env
['machine'] == 'x86'
215 ppc
= env
['machine'] == 'ppc'
219 # Put build output in a separate dir, which depends on the current
220 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
221 build_topdir
= 'build'
222 build_subdir
= env
['platform']
224 build_subdir
+= "-llvm"
225 if env
['machine'] != 'generic':
226 build_subdir
+= '-' + env
['machine']
228 build_subdir
+= "-debug"
230 build_subdir
+= "-profile"
231 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
232 # Place the .sconsign file in the build dir too, to avoid issues with
233 # different scons versions building the same source file
234 env
['build'] = build_dir
235 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
236 env
.CacheDir('build/cache')
239 if env
.GetOption('num_jobs') <= 1:
240 env
.SetOption('num_jobs', num_jobs())
242 # C preprocessor options
245 cppdefines
+= ['DEBUG']
247 cppdefines
+= ['NDEBUG']
249 cppdefines
+= ['PROFILE']
250 if platform
== 'windows':
256 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
257 ('WINVER', '0x0501'),
258 # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
259 'WIN32_LEAN_AND_MEAN',
261 if msvc
and env
['toolchain'] != 'winddk':
264 '_CRT_SECURE_NO_DEPRECATE',
267 cppdefines
+= ['_DEBUG']
268 if env
['toolchain'] == 'winddk':
269 # Mimic WINDDK's builtin flags. See also:
270 # - WINDDK's bin/makefile.new i386mk.inc for more info.
271 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
272 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
274 cppdefines
+= ['_X86_', 'i386']
275 if machine
== 'x86_64':
276 cppdefines
+= ['_AMD64_', 'AMD64']
277 if platform
== 'winddk':
280 ('CONDITION_HANDLING', '1'),
285 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
286 ('WINVER', '0x0501'),
287 ('_WIN32_IE', '0x0603'),
288 ('WIN32_LEAN_AND_MEAN', '1'),
290 ('__BUILDMACHINE__', 'WinDDK'),
294 cppdefines
+= [('DBG', 1)]
295 if platform
== 'wince':
297 '_CRT_SECURE_NO_DEPRECATE',
302 ('_WIN32_WCE', '0x600'),
310 ('INTLMSG_CODEPAGE', '1252'),
312 if platform
== 'windows':
313 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
314 if platform
== 'winddk':
315 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
316 if platform
== 'wince':
317 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE']
318 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
319 env
.Append(CPPDEFINES
= cppdefines
)
324 ccflags
= [] # C & C++
327 ccflags
+= ['-O0', '-g3']
328 elif env
['CCVERSION'].startswith('4.2.'):
329 # gcc 4.2.x optimizer is broken
330 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
331 ccflags
+= ['-O0', '-g3']
333 ccflags
+= ['-O3', '-g3']
336 if env
['machine'] == 'x86':
340 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
343 if env
['machine'] == 'x86_64':
346 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
349 '-Wmissing-field-initializers',
353 '-fmessage-length=0', # be nice to Eclipse
356 '-Werror=declaration-after-statement',
357 '-Wmissing-prototypes',
362 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
366 '/Od', # disable optimizations
367 '/Oi', # enable intrinsic functions
368 '/Oy-', # disable frame pointer omission
369 '/GL-', # disable whole program optimization
373 '/O2', # optimize for speed
374 #'/fp:fast', # fast floating point
378 '/Gh', # enable _penter hook function
379 '/GH', # enable _pexit hook function
382 '/W3', # warning level
383 #'/Wp64', # enable 64 bit porting warnings
385 if env
['machine'] == 'x86':
387 #'/QIfist', # Suppress _ftol
388 #'/arch:SSE2', # use the SSE2 instructions
390 if platform
== 'windows':
394 if platform
== 'winddk':
396 '/Zl', # omit default library name in .OBJ
397 '/Zp8', # 8bytes struct member alignment
398 '/Gy', # separate functions for linker
399 '/Gm-', # disable minimal rebuild
400 '/WX', # treat warnings as errors
401 '/Gz', # __stdcall Calling convention
402 '/GX-', # disable C++ EH
403 '/GR-', # disable C++ RTTI
404 '/GF', # enable read-only string pooling
405 '/G6', # optimize for PPro, P-II, P-III
406 '/Ze', # enable extensions
407 '/Gi-', # disable incremental compilation
408 '/QIfdiv-', # disable Pentium FDIV fix
409 '/hotpatch', # prepares an image for hotpatching.
410 #'/Z7', #enable old-style debug info
412 if platform
== 'wince':
413 # See also C:\WINCE600\public\common\oak\misc\makefile.def
415 '/Zl', # omit default library name in .OBJ
416 '/GF', # enable read-only string pooling
417 '/GR-', # disable C++ RTTI
418 '/GS', # enable security checks
419 # Allow disabling language conformance to maintain backward compat
420 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
421 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
427 # Automatic pdb generation
428 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
429 env
.EnsureSConsVersion(0, 98, 0)
430 env
['PDB'] = '${TARGET.base}.pdb'
431 env
.Append(CCFLAGS
= ccflags
)
432 env
.Append(CFLAGS
= cflags
)
433 env
.Append(CXXFLAGS
= cxxflags
)
435 if env
['platform'] == 'windows' and msvc
:
436 # Choose the appropriate MSVC CRT
437 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
439 env
.Append(CCFLAGS
= ['/MTd'])
440 env
.Append(SHCCFLAGS
= ['/LDd'])
442 env
.Append(CCFLAGS
= ['/MT'])
443 env
.Append(SHCCFLAGS
= ['/LD'])
447 if env
['machine'] == 'x86':
448 env
.Append(ASFLAGS
= ['-m32'])
449 if env
['machine'] == 'x86_64':
450 env
.Append(ASFLAGS
= ['-m64'])
456 if env
['machine'] == 'x86':
457 linkflags
+= ['-m32']
458 if env
['machine'] == 'x86_64':
459 linkflags
+= ['-m64']
463 if platform
== 'windows' and msvc
:
465 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
470 if platform
== 'winddk':
473 '/merge:_TEXT=.text',
477 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
490 '/stack:0x40000,0x1000',
493 '/subsystem:native,5.01',
496 '/entry:DrvEnableDriver',
498 if env
['debug'] or env
['profile']:
500 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
502 if platform
== 'wince':
507 '/entry:_DllMainCRTStartup',
509 env
.Append(LINKFLAGS
= linkflags
)
510 env
.Append(SHLINKFLAGS
= shlinkflags
)
513 env
.Append(LIBS
= [])
515 # Custom builders and methods
516 createConvenienceLibBuilder(env
)
517 createCodeGenerateMethod(env
)
518 createInstallMethods(env
)