3 Frontend-tool for Gallium3D architecture.
8 # Copyright 2008 VMware, Inc.
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 VMWARE 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
38 import platform
as _platform
45 def symlink(target
, source
, env
):
46 target
= str(target
[0])
47 source
= str(source
[0])
48 if os
.path
.islink(target
) or os
.path
.exists(target
):
50 os
.symlink(os
.path
.basename(source
), target
)
52 def install(env
, source
, subdir
):
53 target_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build_dir'], subdir
)
54 return env
.Install(target_dir
, source
)
56 def install_program(env
, source
):
57 return install(env
, source
, 'bin')
59 def install_shared_library(env
, sources
, version
= ()):
61 install_dir
= os
.path
.join(env
.Dir('#.').srcnode().abspath
, env
['build_dir'])
62 version
= tuple(map(str, version
))
63 if env
['SHLIBSUFFIX'] == '.dll':
64 dlls
= env
.FindIxes(sources
, 'SHLIBPREFIX', 'SHLIBSUFFIX')
65 targets
+= install(env
, dlls
, 'bin')
66 libs
= env
.FindIxes(sources
, 'LIBPREFIX', 'LIBSUFFIX')
67 targets
+= install(env
, libs
, 'lib')
69 for source
in sources
:
70 target_dir
= os
.path
.join(install_dir
, 'lib')
71 target_name
= '.'.join((str(source
),) + version
)
72 last
= env
.InstallAs(os
.path
.join(target_dir
, target_name
), source
)
75 version
= version
[:-1]
76 target_name
= '.'.join((str(source
),) + version
)
77 action
= SCons
.Action
.Action(symlink
, " Symlinking $TARGET ...")
78 last
= env
.Command(os
.path
.join(target_dir
, target_name
), last
, action
)
83 def createInstallMethods(env
):
84 env
.AddMethod(install_program
, 'InstallProgram')
85 env
.AddMethod(install_shared_library
, 'InstallSharedLibrary')
90 return int(os
.environ
['NUMBER_OF_PROCESSORS'])
91 except (ValueError, KeyError):
95 return os
.sysconf('SC_NPROCESSORS_ONLN')
96 except (ValueError, OSError, AttributeError):
100 return int(os
.popen2("sysctl -n hw.ncpu")[1].read())
107 def get_cc_version(env
):
108 # Get the first line of `$CC --version`
109 pipe
= SCons
.Action
._subproc
(env
, [env
['CC'], '--version'],
112 stdout
= subprocess
.PIPE
)
116 line
= pipe
.stdout
.readline()
121 """Common environment generation code"""
123 # Tell tools which machine to compile for
124 env
['TARGET_ARCH'] = env
['machine']
125 env
['MSVS_ARCH'] = env
['machine']
128 platform
= env
['platform']
129 env
.Tool(env
['toolchain'])
131 # Allow override compiler and specify additional flags from environment
132 if os
.environ
.has_key('CC'):
133 env
['CC'] = os
.environ
['CC']
134 # Update CCVERSION to match
135 line
= get_cc_version(env
)
137 match
= re
.search(r
'[0-9]+(\.[0-9]+)+', line
)
139 env
['CCVERSION'] = match
.group(0)
140 if os
.environ
.has_key('CFLAGS'):
141 env
['CCFLAGS'] += SCons
.Util
.CLVar(os
.environ
['CFLAGS'])
142 if os
.environ
.has_key('CXX'):
143 env
['CXX'] = os
.environ
['CXX']
144 if os
.environ
.has_key('CXXFLAGS'):
145 env
['CXXFLAGS'] += SCons
.Util
.CLVar(os
.environ
['CXXFLAGS'])
146 if os
.environ
.has_key('LDFLAGS'):
147 env
['LINKFLAGS'] += SCons
.Util
.CLVar(os
.environ
['LDFLAGS'])
149 # Detect gcc/clang not by executable name, but through `--version` option,
150 # to avoid drawing wrong conclusions when using tools that overrice CC/CXX
152 cc_version
= get_cc_version(env
)
153 cc_version_words
= cc_version
.split()
155 env
['gcc'] = 'gcc' in cc_version_words
156 env
['msvc'] = env
['CC'] == 'cl'
157 env
['suncc'] = env
['platform'] == 'sunos' and os
.path
.basename(env
['CC']) == 'cc'
158 env
['clang'] = 'clang' in cc_version_words
159 env
['icc'] = 'icc' == os
.path
.basename(env
['CC'])
161 if env
['msvc'] and env
['toolchain'] == 'default' and env
['machine'] == 'x86_64':
162 # MSVC x64 support is broken in earlier versions of scons
163 env
.EnsurePythonVersion(2, 0)
166 machine
= env
['machine']
167 platform
= env
['platform']
168 x86
= env
['machine'] == 'x86'
169 ppc
= env
['machine'] == 'ppc'
170 gcc_compat
= env
['gcc'] or env
['clang']
175 # Determine whether we are cross compiling; in particular, whether we need
176 # to compile code generators with a different compiler as the target code.
177 host_platform
= _platform
.system().lower()
178 if host_platform
.startswith('cygwin'):
179 host_platform
= 'cygwin'
180 host_machine
= os
.environ
.get('PROCESSOR_ARCHITEW6432', os
.environ
.get('PROCESSOR_ARCHITECTURE', _platform
.machine()))
190 }.get(host_machine
, 'generic')
191 env
['crosscompile'] = platform
!= host_platform
192 if machine
== 'x86_64' and host_machine
!= 'x86_64':
193 env
['crosscompile'] = True
194 env
['hostonly'] = False
196 # Backwards compatability with the debug= profile= options
197 if env
['build'] == 'debug':
199 print 'scons: warning: debug option is deprecated and will be removed eventually; use instead'
201 print ' scons build=release'
203 env
['build'] = 'release'
205 print 'scons: warning: profile option is deprecated and will be removed eventually; use instead'
207 print ' scons build=profile'
209 env
['build'] = 'profile'
211 # Enforce SConscripts to use the new build variable
213 env
.popitem('profile')
215 # Backwards portability with older sconscripts
216 if env
['build'] in ('debug', 'checked'):
218 env
['profile'] = False
219 if env
['build'] == 'profile':
221 env
['profile'] = True
222 if env
['build'] == 'release':
224 env
['profile'] = False
226 # Put build output in a separate dir, which depends on the current
227 # configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
228 build_topdir
= 'build'
229 build_subdir
= env
['platform']
231 build_subdir
= 'embedded-' + build_subdir
232 if env
['machine'] != 'generic':
233 build_subdir
+= '-' + env
['machine']
234 if env
['build'] != 'release':
235 build_subdir
+= '-' + env
['build']
236 build_dir
= os
.path
.join(build_topdir
, build_subdir
)
237 # Place the .sconsign file in the build dir too, to avoid issues with
238 # different scons versions building the same source file
239 env
['build_dir'] = build_dir
240 env
.SConsignFile(os
.path
.join(build_dir
, '.sconsign'))
241 if 'SCONS_CACHE_DIR' in os
.environ
:
242 print 'scons: Using build cache in %s.' % (os
.environ
['SCONS_CACHE_DIR'],)
243 env
.CacheDir(os
.environ
['SCONS_CACHE_DIR'])
244 env
['CONFIGUREDIR'] = os
.path
.join(build_dir
, 'conf')
245 env
['CONFIGURELOG'] = os
.path
.join(os
.path
.abspath(build_dir
), 'config.log')
248 if env
.GetOption('num_jobs') <= 1:
249 env
.SetOption('num_jobs', num_jobs())
251 env
.Decider('MD5-timestamp')
252 env
.SetOption('max_drift', 60)
254 # C preprocessor options
256 if env
['build'] in ('debug', 'checked'):
257 cppdefines
+= ['DEBUG']
259 cppdefines
+= ['NDEBUG']
260 if env
['build'] == 'profile':
261 cppdefines
+= ['PROFILE']
262 if env
['platform'] in ('posix', 'linux', 'freebsd', 'darwin'):
265 ('_POSIX_C_SOURCE', '199309L'),
270 'HAVE_POSIX_MEMALIGN',
272 if env
['platform'] == 'darwin':
276 'GLX_DIRECT_RENDERING',
280 'GLX_DIRECT_RENDERING',
281 'GLX_INDIRECT_RENDERING',
283 if env
['platform'] in ('linux', 'freebsd'):
284 cppdefines
+= ['HAVE_ALIAS']
286 cppdefines
+= ['GLX_ALIAS_UNSUPPORTED']
287 if env
['platform'] == 'haiku':
290 'HAVE_POSIX_MEMALIGN'
292 if platform
== 'windows':
298 # http://msdn.microsoft.com/en-us/library/aa383745.aspx
299 ('_WIN32_WINNT', '0x0601'),
300 ('WINVER', '0x0601'),
303 cppdefines
+= [('__MSVCRT_VERSION__', '0x0700')]
308 '_CRT_SECURE_NO_WARNINGS',
309 '_CRT_SECURE_NO_DEPRECATE',
310 '_SCL_SECURE_NO_WARNINGS',
311 '_SCL_SECURE_NO_DEPRECATE',
312 '_ALLOW_KEYWORD_MACROS',
314 if env
['build'] in ('debug', 'checked'):
315 cppdefines
+= ['_DEBUG']
316 if platform
== 'windows':
317 cppdefines
+= ['PIPE_SUBSYSTEM_WINDOWS_USER']
319 cppdefines
+= ['PIPE_SUBSYSTEM_EMBEDDED']
320 if env
['texture_float']:
321 print 'warning: Floating-point textures enabled.'
322 print 'warning: Please consult docs/patents.txt with your lawyer before building Mesa.'
323 cppdefines
+= ['TEXTURE_FLOAT_ENABLED']
324 env
.Append(CPPDEFINES
= cppdefines
)
329 ccflags
= [] # C & C++
331 ccversion
= env
['CCVERSION']
332 if env
['build'] == 'debug':
334 elif env
['gcc'] and ccversion
.startswith('4.2.'):
335 # gcc 4.2.x optimizer is broken
336 print "warning: gcc 4.2.x optimizer is broken -- disabling optimizations"
341 # gcc's builtin memcmp is slower than glibc's
342 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
343 ccflags
+= ['-fno-builtin-memcmp']
344 # Work around aliasing bugs - developers should comment this out
345 ccflags
+= ['-fno-strict-aliasing']
347 if env
['build'] in ('checked', 'profile'):
348 # See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
350 '-fno-omit-frame-pointer',
353 ccflags
+= ['-fno-optimize-sibling-calls']
354 if env
['machine'] == 'x86':
359 if distutils
.version
.LooseVersion(ccversion
) >= distutils
.version
.LooseVersion('4.2') \
360 and (platform
!= 'windows' or env
['build'] == 'debug' or True) \
361 and platform
!= 'haiku':
362 # NOTE: We need to ensure stack is realigned given that we
363 # produce shared objects, and have no control over the stack
364 # alignment policy of the application. Therefore we need
365 # -mstackrealign ore -mincoming-stack-boundary=2.
367 # XXX: -O and -mstackrealign causes stack corruption on MinGW
369 # XXX: We could have SSE without -mstackrealign if we always used
370 # __attribute__((force_align_arg_pointer)), but that's not
373 '-mstackrealign', # ensure stack is aligned
374 '-mmmx', '-msse', '-msse2', # enable SIMD intrinsics
377 if platform
in ['windows', 'darwin']:
378 # Workaround http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216
379 ccflags
+= ['-fno-common']
380 if platform
in ['haiku']:
381 # Make optimizations compatible with Pentium or higher on Haiku
383 '-mstackrealign', # ensure stack is aligned
384 '-march=i586', # Haiku target is Pentium
385 '-mtune=i686' # use i686 where we can
387 if env
['machine'] == 'x86_64':
389 if platform
== 'darwin':
390 ccflags
+= ['-fno-common']
391 if env
['platform'] not in ('cygwin', 'haiku', 'windows'):
392 ccflags
+= ['-fvisibility=hidden']
394 # - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
398 '-fmessage-length=0', # be nice to Eclipse
401 '-Wmissing-prototypes',
404 if distutils
.version
.LooseVersion(ccversion
) >= distutils
.version
.LooseVersion('4.2'):
409 '-Wdeclaration-after-statement',
417 # - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
419 if env
['build'] == 'debug':
421 '/Od', # disable optimizations
422 '/Oi', # enable intrinsic functions
425 if 'MSVC_VERSION' in env
and distutils
.version
.LooseVersion(env
['MSVC_VERSION']) < distutils
.version
.LooseVersion('11.0'):
426 print 'scons: warning: Visual Studio versions prior to 2012 are known to produce incorrect code when optimizations are enabled ( https://bugs.freedesktop.org/show_bug.cgi?id=58718 )'
428 '/O2', # optimize for speed
430 if env
['build'] == 'release':
432 '/GL', # enable whole program optimization
436 '/Oy-', # disable frame pointer omission
437 '/GL-', # disable whole program optimization
440 '/W3', # warning level
441 #'/Wp64', # enable 64 bit porting warnings
442 '/wd4996', # disable deprecated POSIX name warnings
444 if env
['machine'] == 'x86':
446 #'/arch:SSE2', # use the SSE2 instructions
448 if platform
== 'windows':
452 # Automatic pdb generation
453 # See http://scons.tigris.org/issues/show_bug.cgi?id=1656
454 env
.EnsureSConsVersion(0, 98, 0)
455 env
['PDB'] = '${TARGET.base}.pdb'
456 env
.Append(CCFLAGS
= ccflags
)
457 env
.Append(CFLAGS
= cflags
)
458 env
.Append(CXXFLAGS
= cxxflags
)
460 if env
['platform'] == 'windows' and msvc
:
461 # Choose the appropriate MSVC CRT
462 # http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
463 if env
['build'] in ('debug', 'checked'):
464 env
.Append(CCFLAGS
= ['/MTd'])
465 env
.Append(SHCCFLAGS
= ['/LDd'])
467 env
.Append(CCFLAGS
= ['/MT'])
468 env
.Append(SHCCFLAGS
= ['/LD'])
472 if env
['machine'] == 'x86':
473 env
.Append(ASFLAGS
= ['-m32'])
474 if env
['machine'] == 'x86_64':
475 env
.Append(ASFLAGS
= ['-m64'])
481 if env
['machine'] == 'x86':
482 linkflags
+= ['-m32']
483 if env
['machine'] == 'x86_64':
484 linkflags
+= ['-m64']
485 if env
['platform'] not in ('darwin'):
489 # Handle circular dependencies in the libraries
490 if env
['platform'] in ('darwin'):
493 env
['_LIBFLAGS'] = '-Wl,--start-group ' + env
['_LIBFLAGS'] + ' -Wl,--end-group'
494 if env
['platform'] == 'windows':
495 # Avoid depending on gcc runtime DLLs
496 linkflags
+= ['-static-libgcc']
497 if 'w64' in env
['CC'].split('-'):
498 linkflags
+= ['-static-libstdc++']
499 # Handle the @xx symbol munging of DLL exports
500 shlinkflags
+= ['-Wl,--enable-stdcall-fixup']
501 #shlinkflags += ['-Wl,--kill-at']
503 if env
['build'] == 'release':
504 # enable Link-time Code Generation
505 linkflags
+= ['/LTCG']
506 env
.Append(ARFLAGS
= ['/LTCG'])
507 if platform
== 'windows' and msvc
:
509 # - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
514 env
.Append(LINKFLAGS
= linkflags
)
515 env
.Append(SHLINKFLAGS
= shlinkflags
)
517 # We have C++ in several libraries, so always link with the C++ compiler
519 env
['LINK'] = env
['CXX']
523 if env
['platform'] in ('darwin', 'freebsd', 'linux', 'posix', 'sunos'):
524 libs
+= ['m', 'pthread', 'dl']
525 if env
['platform'] in ('linux',):
527 if env
['platform'] in ('haiku'):
528 libs
+= ['root', 'be', 'network', 'translation']
529 env
.Append(LIBS
= libs
)
534 env
.Append(CCFLAGS
= ['/openmp'])
535 # When building openmp release VS2008 link.exe crashes with LNK1103 error.
536 # Workaround: overwrite PDB flags with empty value as it isn't required anyways
537 if env
['build'] == 'release':
540 env
.Append(CCFLAGS
= ['-fopenmp'])
541 env
.Append(LIBS
= ['gomp'])
549 # Custom builders and methods
551 createInstallMethods(env
)
553 env
.PkgCheckModules('X11', ['x11', 'xext', 'xdamage', 'xfixes'])
554 env
.PkgCheckModules('XCB', ['x11-xcb', 'xcb-glx >= 1.8.1'])
555 env
.PkgCheckModules('XF86VIDMODE', ['xxf86vm'])
556 env
.PkgCheckModules('DRM', ['libdrm >= 2.4.38'])
557 env
.PkgCheckModules('DRM_INTEL', ['libdrm_intel >= 2.4.52'])
558 env
.PkgCheckModules('UDEV', ['libudev >= 151'])
560 env
['dri'] = env
['x11'] and env
['drm']