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
['CCCOMSTR'] = "Compiling $SOURCE ..."
46 env
['CXXCOMSTR'] = "Compiling $SOURCE ..."
47 env
['ARCOMSTR'] = "Archiving $TARGET ..."
48 env
['RANLIBCOMSTR'] = ""
49 env
['LINKCOMSTR'] = "Linking $TARGET ..."
52 def createConvenienceLibBuilder(env
):
53 """This is a utility function that creates the ConvenienceLibrary
54 Builder in an Environment if it is not there already.
56 If it is already there, we return the existing one.
58 Based on the stock StaticLibrary and SharedLibrary builders.
62 convenience_lib
= env
['BUILDERS']['ConvenienceLibrary']
64 action_list
= [ SCons
.Action
.Action("$ARCOM", "$ARCOMSTR") ]
65 if env
.Detect('ranlib'):
66 ranlib_action
= SCons
.Action
.Action("$RANLIBCOM", "$RANLIBCOMSTR")
67 action_list
.append(ranlib_action
)
69 convenience_lib
= SCons
.Builder
.Builder(action
= action_list
,
70 emitter
= '$LIBEMITTER',
71 prefix
= '$LIBPREFIX',
72 suffix
= '$LIBSUFFIX',
73 src_suffix
= '$SHOBJSUFFIX',
74 src_builder
= 'SharedObject')
75 env
['BUILDERS']['ConvenienceLibrary'] = convenience_lib
77 return convenience_lib
80 # TODO: handle import statements with multiple modules
81 # TODO: handle from import statements
82 import_re
= re
.compile(r
'^import\s+(\S+)$', re
.M
)
84 def python_scan(node
, env
, path
):
85 # http://www.scons.org/doc/0.98.5/HTML/scons-user/c2781.html#AEN2789
86 contents
= node
.get_contents()
87 source_dir
= node
.get_dir()
88 imports
= import_re
.findall(contents
)
92 file = os
.path
.join(str(dir), imp
.replace('.', os
.sep
) + '.py')
93 if os
.path
.exists(file):
94 results
.append(env
.File(file))
96 file = os
.path
.join(str(dir), imp
.replace('.', os
.sep
), '__init__.py')
97 if os
.path
.exists(file):
98 results
.append(env
.File(file))
102 python_scanner
= SCons
.Scanner
.Scanner(function
= python_scan
, skeys
= ['.py'])
105 def code_generate(env
, script
, target
, source
, command
):
106 """Method to simplify code generation via python scripts.
108 http://www.scons.org/wiki/UsingCodeGenerators
109 http://www.scons.org/doc/0.98.5/HTML/scons-user/c2768.html
112 # We're generating code using Python scripts, so we have to be
113 # careful with our scons elements. This entry represents
114 # the generator file *in the source directory*.
115 script_src
= env
.File(script
).srcnode()
117 # This command creates generated code *in the build directory*.
118 command
= command
.replace('$SCRIPT', script_src
.path
)
119 code
= env
.Command(target
, source
, command
)
121 # Explicitly mark that the generated code depends on the generator,
122 # and on implicitly imported python modules
123 path
= (script_src
.get_dir(),)
125 deps
+= script_src
.get_implicit_deps(env
, python_scanner
, path
)
126 env
.Depends(code
, deps
)
128 # Running the Python script causes .pyc files to be generated in the
129 # source directory. When we clean up, they should go too. So add side
130 # effects for .pyc files
132 pyc
= env
.File(str(dep
) + 'c')
133 env
.SideEffect(pyc
, code
)
138 def createCodeGenerateMethod(env
):
139 env
.Append(SCANNERS
= python_scanner
)
140 env
.AddMethod(code_generate
, 'CodeGenerate')
143 def symlink(target
, source
, env
):
144 target
= str(target
[0])
145 source
= str(source
[0])
146 if os
.path
.islink(target
) or os
.path
.exists(target
):
148 os
.symlink(os
.path
.basename(source
), target
)
150 def install_shared_library(env
, source
, version
= ()):
151 source
= str(source
[0])
152 version
= tuple(map(str, version
))
153 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build'], 'lib')
154 target_name
= '.'.join((str(source
),) + version
)
155 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
157 version
= version
[:-1]
158 target_name
= '.'.join((str(source
),) + version
)
159 action
= SCons
.Action
.Action(symlink
, "$TARGET -> $SOURCE")
160 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
162 def createInstallMethods(env
):
163 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
167 """Common environment generation code"""
169 # FIXME: this is already too late
170 #if env.get('quiet', False):
171 # quietCommandLines(env)
174 platform
= env
['platform']
175 if env
['toolchain'] == 'default':
176 if platform
== 'winddk':
177 env
['toolchain'] = 'winddk'
178 elif platform
== 'wince':
179 env
['toolchain'] = 'wcesdk'
180 env
.Tool(env
['toolchain'])
184 machine
= env
['machine']
185 platform
= env
['platform']
186 x86
= env
['machine'] == 'x86'
187 ppc
= env
['machine'] == 'ppc'
188 gcc
= env
['platform'] in ('linux', 'freebsd', 'darwin') or env
['toolchain'] == 'crossmingw'
189 msvc
= env
['platform'] in ('windows', 'winddk', 'wince') and env
['toolchain'] != 'crossmingw'
191 # Put build output in a separate dir, which depends on the current
192 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
193 build_topdir
= 'build'
194 build_subdir
= env
['platform']
196 build_subdir
+= "-dri"
198 build_subdir
+= "-llvm"
199 if env
['machine'] != 'generic':
200 build_subdir
+= '-' + env
['machine']
202 build_subdir
+= "-debug"
204 build_subdir
+= "-profile"
205 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
206 # Place the .sconsign file in the build dir too, to avoid issues with
207 # different scons versions building the same source file
208 env
['build'] = build_dir
209 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
211 # C preprocessor options
214 cppdefines
+= ['DEBUG']
216 cppdefines
+= ['NDEBUG']
218 cppdefines
+= ['PROFILE']
219 if platform
== 'windows':
225 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
226 ('WINVER', '0x0501'),
227 # http://msdn2.microsoft.com/en-us/library/6dwk3a1z.aspx,
228 'WIN32_LEAN_AND_MEAN',
230 '_CRT_SECURE_NO_DEPRECATE',
233 cppdefines
+= ['_DEBUG']
234 if platform
== 'winddk':
235 # Mimic WINDDK's builtin flags. See also:
236 # - WINDDK's bin/makefile.new i386mk.inc for more info.
237 # - buildchk_wxp_x86.log files, generated by the WINDDK's build
238 # - http://alter.org.ua/docs/nt_kernel/vc8_proj/
243 ('CONDITION_HANDLING', '1'),
248 ('_WIN32_WINNT', '0x0501'), # minimum required OS version
249 ('WINVER', '0x0501'),
250 ('_WIN32_IE', '0x0603'),
251 ('WIN32_LEAN_AND_MEAN', '1'),
253 ('__BUILDMACHINE__', 'WinDDK'),
257 cppdefines
+= [('DBG', 1)]
258 if platform
== 'wince':
260 '_CRT_SECURE_NO_DEPRECATE',
265 ('_WIN32_WCE', '0x600'),
273 ('INTLMSG_CODEPAGE', '1252'),
275 if platform
== 'windows':
276 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
277 if platform
== 'winddk':
278 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_DISPLAY']
279 if platform
== 'wince':
280 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE']
281 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_CE_OGL']
282 env
.Append(CPPDEFINES
= cppdefines
)
284 # C preprocessor includes
285 if platform
== 'winddk':
286 env
.Append(CPPPATH
= [
297 cflags
+= ['-O0', '-g3']
299 cflags
+= ['-O3', '-g3']
302 if env
['machine'] == 'x86':
306 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
309 if env
['machine'] == 'x86_64':
313 '-Wmissing-prototypes',
318 '-fmessage-length=0', # be nice to Eclipse
322 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
326 '/Od', # disable optimizations
327 '/Oi', # enable intrinsic functions
328 '/Oy-', # disable frame pointer omission
332 '/Ox', # maximum optimizations
333 '/Oi', # enable intrinsic functions
334 '/Ot', # favor code speed
335 #'/fp:fast', # fast floating point
339 '/Gh', # enable _penter hook function
340 '/GH', # enable _pexit hook function
343 '/W3', # warning level
344 #'/Wp64', # enable 64 bit porting warnings
346 if env
['machine'] == 'x86':
348 #'/QIfist', # Suppress _ftol
349 #'/arch:SSE2', # use the SSE2 instructions
351 if platform
== 'windows':
355 if platform
== 'winddk':
357 '/Zl', # omit default library name in .OBJ
358 '/Zp8', # 8bytes struct member alignment
359 '/Gy', # separate functions for linker
360 '/Gm-', # disable minimal rebuild
361 '/WX', # treat warnings as errors
362 '/Gz', # __stdcall Calling convention
363 '/GX-', # disable C++ EH
364 '/GR-', # disable C++ RTTI
365 '/GF', # enable read-only string pooling
366 '/G6', # optimize for PPro, P-II, P-III
367 '/Ze', # enable extensions
368 '/Gi-', # disable incremental compilation
369 '/QIfdiv-', # disable Pentium FDIV fix
370 '/hotpatch', # prepares an image for hotpatching.
371 #'/Z7', #enable old-style debug info
373 if platform
== 'wince':
374 # See also C:\WINCE600\public\common\oak\misc\makefile.def
376 '/Zl', # omit default library name in .OBJ
377 '/GF', # enable read-only string pooling
378 '/GR-', # disable C++ RTTI
379 '/GS', # enable security checks
380 # Allow disabling language conformance to maintain backward compat
381 #'/Zc:wchar_t-', # don't force wchar_t as native type, instead of typedef
382 #'/Zc:forScope-', # don't enforce Standard C++ for scoping rules
388 # Automatic pdb generation
389 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
390 env
.EnsureSConsVersion(0, 98, 0)
391 env
['PDB'] = '${TARGET.base}.pdb'
392 env
.Append(CFLAGS
= cflags
)
393 env
.Append(CXXFLAGS
= cflags
)
397 if env
['machine'] == 'x86':
398 env
.Append(ASFLAGS
= ['-m32'])
399 if env
['machine'] == 'x86_64':
400 env
.Append(ASFLAGS
= ['-m64'])
405 if env
['machine'] == 'x86':
406 linkflags
+= ['-m32']
407 if env
['machine'] == 'x86_64':
408 linkflags
+= ['-m64']
409 if platform
== 'winddk':
411 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
414 '/merge:_TEXT=.text',
418 '/ignore:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221',
431 '/stack:0x40000,0x1000',
434 '/subsystem:native,5.01',
437 '/entry:DrvEnableDriver',
441 '/MAP', # http://msdn.microsoft.com/en-us/library/k7xkk3e2.aspx
443 if platform
== 'wince':
448 '/entry:_DllMainCRTStartup',
450 env
.Append(LINKFLAGS
= linkflags
)
453 env
.Append(LIBS
= [])
455 # Custom builders and methods
456 createConvenienceLibBuilder(env
)
457 createCodeGenerateMethod(env
)
458 createInstallMethods(env
)