2008-06-06 06:48:57 +01:00
""" gallium
Frontend - tool for Gallium3D architecture .
"""
2008-07-17 03:23:43 +01:00
#
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
# Copyright 2008 VMware, Inc.
2008-06-06 06:48:57 +01:00
# All Rights Reserved.
2008-07-17 03:23:43 +01:00
#
2008-06-06 06:48:57 +01:00
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sub license, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
2008-07-17 03:23:43 +01:00
#
2008-06-06 06:48:57 +01:00
# The above copyright notice and this permission notice (including the
# next paragraph) shall be included in all copies or substantial portions
# of the Software.
2008-07-17 03:23:43 +01:00
#
2008-06-06 06:48:57 +01:00
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
# IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
2008-06-06 06:48:57 +01:00
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2008-07-17 03:23:43 +01:00
#
2008-06-06 06:48:57 +01:00
2010-01-27 06:56:58 +00:00
import distutils . version
2008-07-03 04:42:23 +01:00
import os
2008-06-06 06:48:57 +01:00
import os . path
2008-07-03 04:42:23 +01:00
import re
2010-01-27 12:46:46 +00:00
import subprocess
2015-03-19 13:30:19 +00:00
import platform as host_platform
2014-04-16 17:26:05 +01:00
import sys
import tempfile
2008-06-06 06:48:57 +01:00
import SCons . Action
import SCons . Builder
2008-07-03 04:42:23 +01:00
import SCons . Scanner
2008-06-06 06:48:57 +01:00
2008-07-03 04:42:23 +01:00
2008-09-07 23:54:15 +01:00
def symlink ( target , source , env ) :
target = str ( target [ 0 ] )
source = str ( source [ 0 ] )
if os . path . islink ( target ) or os . path . exists ( target ) :
os . remove ( target )
os . symlink ( os . path . basename ( source ) , target )
2010-01-01 22:35:28 +00:00
def install ( env , source , subdir ) :
2010-09-29 14:08:53 +01:00
target_dir = os . path . join ( env . Dir ( ' #. ' ) . srcnode ( ) . abspath , env [ ' build_dir ' ] , subdir )
2010-11-02 14:20:12 +00:00
return env . Install ( target_dir , source )
2010-01-01 22:35:28 +00:00
2009-12-23 15:21:56 +00:00
def install_program ( env , source ) :
2010-11-02 14:20:12 +00:00
return install ( env , source , ' bin ' )
2009-12-23 15:21:56 +00:00
2010-01-01 22:35:28 +00:00
def install_shared_library ( env , sources , version = ( ) ) :
2010-11-02 14:20:12 +00:00
targets = [ ]
2010-09-29 14:08:53 +01:00
install_dir = os . path . join ( env . Dir ( ' #. ' ) . srcnode ( ) . abspath , env [ ' build_dir ' ] )
2008-09-07 23:54:15 +01:00
version = tuple ( map ( str , version ) )
2010-01-01 22:35:28 +00:00
if env [ ' SHLIBSUFFIX ' ] == ' .dll ' :
dlls = env . FindIxes ( sources , ' SHLIBPREFIX ' , ' SHLIBSUFFIX ' )
2010-11-02 14:20:12 +00:00
targets + = install ( env , dlls , ' bin ' )
2010-01-01 22:35:28 +00:00
libs = env . FindIxes ( sources , ' LIBPREFIX ' , ' LIBSUFFIX ' )
2010-11-02 14:20:12 +00:00
targets + = install ( env , libs , ' lib ' )
2010-01-01 21:54:51 +00:00
else :
2010-01-01 22:35:28 +00:00
for source in sources :
target_dir = os . path . join ( install_dir , ' lib ' )
target_name = ' . ' . join ( ( str ( source ) , ) + version )
last = env . InstallAs ( os . path . join ( target_dir , target_name ) , source )
2010-11-02 14:20:12 +00:00
targets + = last
2010-01-01 22:35:28 +00:00
while len ( version ) :
version = version [ : - 1 ]
target_name = ' . ' . join ( ( str ( source ) , ) + version )
2011-05-04 14:10:24 +01:00
action = SCons . Action . Action ( symlink , " Symlinking $TARGET ... " )
2010-01-01 22:35:28 +00:00
last = env . Command ( os . path . join ( target_dir , target_name ) , last , action )
2010-11-02 14:20:12 +00:00
targets + = last
return targets
2008-09-07 23:54:15 +01:00
def createInstallMethods ( env ) :
2009-12-23 15:21:56 +00:00
env . AddMethod ( install_program , ' InstallProgram ' )
2008-09-07 23:54:15 +01:00
env . AddMethod ( install_shared_library , ' InstallSharedLibrary ' )
2015-03-04 14:23:52 +00:00
def msvc2013_compat ( env ) :
if env [ ' gcc ' ] :
env . Append ( CCFLAGS = [
' -Werror=vla ' ,
' -Werror=pointer-arith ' ,
] )
def msvc2008_compat ( env ) :
msvc2013_compat ( env )
if env [ ' gcc ' ] :
env . Append ( CFLAGS = [
' -Werror=declaration-after-statement ' ,
] )
def createMSVCCompatMethods ( env ) :
env . AddMethod ( msvc2013_compat , ' MSVC2013Compat ' )
env . AddMethod ( msvc2008_compat , ' MSVC2008Compat ' )
2009-02-10 18:11:56 +00:00
def num_jobs ( ) :
try :
return int ( os . environ [ ' NUMBER_OF_PROCESSORS ' ] )
except ( ValueError , KeyError ) :
pass
try :
return os . sysconf ( ' SC_NPROCESSORS_ONLN ' )
except ( ValueError , OSError , AttributeError ) :
pass
try :
return int ( os . popen2 ( " sysctl -n hw.ncpu " ) [ 1 ] . read ( ) )
except ValueError :
pass
return 1
2014-04-16 17:26:05 +01:00
def check_cc ( env , cc , expr , cpp_opt = ' -E ' ) :
# Invoke C-preprocessor to determine whether the specified expression is
# true or not.
sys . stdout . write ( ' Checking for %s ... ' % cc )
source = tempfile . NamedTemporaryFile ( suffix = ' .c ' , delete = False )
source . write ( ' #if !( %s ) \n #error \n #endif \n ' % expr )
source . close ( )
pipe = SCons . Action . _subproc ( env , [ env [ ' CC ' ] , cpp_opt , source . name ] ,
stdin = ' devnull ' ,
stderr = ' devnull ' ,
stdout = ' devnull ' )
result = pipe . wait ( ) == 0
os . unlink ( source . name )
sys . stdout . write ( ' %s \n ' % [ ' no ' , ' yes ' ] [ int ( bool ( result ) ) ] )
return result
2015-03-19 13:30:19 +00:00
def check_prog ( env , prog ) :
""" Check whether this program exists. """
sys . stdout . write ( ' Checking for %s ... ' % prog )
result = env . Detect ( prog )
sys . stdout . write ( ' %s \n ' % [ ' no ' , ' yes ' ] [ int ( bool ( result ) ) ] )
return result
2008-06-06 06:48:57 +01:00
def generate ( env ) :
2008-07-17 03:23:43 +01:00
""" Common environment generation code """
2011-02-11 16:29:01 +00:00
# Tell tools which machine to compile for
env [ ' TARGET_ARCH ' ] = env [ ' machine ' ]
env [ ' MSVS_ARCH ' ] = env [ ' machine ' ]
2008-11-18 10:13:32 +00:00
# Toolchain
platform = env [ ' platform ' ]
env . Tool ( env [ ' toolchain ' ] )
2010-11-01 13:30:22 +00:00
# Allow override compiler and specify additional flags from environment
if os . environ . has_key ( ' CC ' ) :
env [ ' CC ' ] = os . environ [ ' CC ' ]
# Update CCVERSION to match
2014-04-16 13:13:48 +01:00
pipe = SCons . Action . _subproc ( env , [ env [ ' CC ' ] , ' --version ' ] ,
stdin = ' devnull ' ,
stderr = ' devnull ' ,
stdout = subprocess . PIPE )
if pipe . wait ( ) == 0 :
line = pipe . stdout . readline ( )
2010-11-01 13:30:22 +00:00
match = re . search ( r ' [0-9]+( \ .[0-9]+)+ ' , line )
if match :
env [ ' CCVERSION ' ] = match . group ( 0 )
if os . environ . has_key ( ' CFLAGS ' ) :
env [ ' CCFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' CFLAGS ' ] )
if os . environ . has_key ( ' CXX ' ) :
env [ ' CXX ' ] = os . environ [ ' CXX ' ]
if os . environ . has_key ( ' CXXFLAGS ' ) :
env [ ' CXXFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' CXXFLAGS ' ] )
if os . environ . has_key ( ' LDFLAGS ' ) :
env [ ' LINKFLAGS ' ] + = SCons . Util . CLVar ( os . environ [ ' LDFLAGS ' ] )
2010-01-27 12:46:46 +00:00
2014-04-16 17:26:05 +01:00
# Detect gcc/clang not by executable name, but through pre-defined macros
# as autoconf does, to avoid drawing wrong conclusions when using tools
# that overrice CC/CXX like scan-build.
env [ ' gcc ' ] = 0
env [ ' clang ' ] = 0
env [ ' msvc ' ] = 0
2015-03-19 13:30:19 +00:00
if host_platform . system ( ) == ' Windows ' :
2014-04-16 17:26:05 +01:00
env [ ' msvc ' ] = check_cc ( env , ' MSVC ' , ' defined(_MSC_VER) ' , ' /E ' )
if not env [ ' msvc ' ] :
env [ ' gcc ' ] = check_cc ( env , ' GCC ' , ' defined(__GNUC__) && !defined(__clang__) ' )
env [ ' clang ' ] = check_cc ( env , ' Clang ' , ' __clang__ ' )
2012-06-16 18:55:20 +01:00
env [ ' suncc ' ] = env [ ' platform ' ] == ' sunos ' and os . path . basename ( env [ ' CC ' ] ) == ' cc '
2012-08-01 06:55:39 +01:00
env [ ' icc ' ] = ' icc ' == os . path . basename ( env [ ' CC ' ] )
2009-03-25 19:24:16 +00:00
2011-02-11 16:29:01 +00:00
if env [ ' msvc ' ] and env [ ' toolchain ' ] == ' default ' and env [ ' machine ' ] == ' x86_64 ' :
# MSVC x64 support is broken in earlier versions of scons
env . EnsurePythonVersion ( 2 , 0 )
2008-07-17 03:23:43 +01:00
# shortcuts
machine = env [ ' machine ' ]
platform = env [ ' platform ' ]
x86 = env [ ' machine ' ] == ' x86 '
2008-10-23 09:28:48 +01:00
ppc = env [ ' machine ' ] == ' ppc '
2013-04-24 22:02:18 +01:00
gcc_compat = env [ ' gcc ' ] or env [ ' clang ' ]
2009-03-25 19:24:16 +00:00
msvc = env [ ' msvc ' ]
2012-06-16 18:55:20 +01:00
suncc = env [ ' suncc ' ]
2012-08-01 06:55:39 +01:00
icc = env [ ' icc ' ]
2008-07-17 03:23:43 +01:00
2011-02-11 16:44:13 +00:00
# Determine whether we are cross compiling; in particular, whether we need
# to compile code generators with a different compiler as the target code.
2015-03-19 13:30:19 +00:00
hosthost_platform = host_platform . system ( ) . lower ( )
if hosthost_platform . startswith ( ' cygwin ' ) :
hosthost_platform = ' cygwin '
host_machine = os . environ . get ( ' PROCESSOR_ARCHITEW6432 ' , os . environ . get ( ' PROCESSOR_ARCHITECTURE ' , host_platform . machine ( ) ) )
2011-02-11 16:44:13 +00:00
host_machine = {
' x86 ' : ' x86 ' ,
' i386 ' : ' x86 ' ,
' i486 ' : ' x86 ' ,
' i586 ' : ' x86 ' ,
' i686 ' : ' x86 ' ,
' ppc ' : ' ppc ' ,
2011-02-15 17:31:31 +00:00
' AMD64 ' : ' x86_64 ' ,
2011-02-11 16:44:13 +00:00
' x86_64 ' : ' x86_64 ' ,
} . get ( host_machine , ' generic ' )
2015-03-19 13:30:19 +00:00
env [ ' crosscompile ' ] = platform != hosthost_platform
2011-02-11 16:44:13 +00:00
if machine == ' x86_64 ' and host_machine != ' x86_64 ' :
env [ ' crosscompile ' ] = True
2011-02-11 17:38:54 +00:00
env [ ' hostonly ' ] = False
2011-02-11 16:44:13 +00:00
2010-09-29 14:08:53 +01:00
# Backwards compatability with the debug= profile= options
if env [ ' build ' ] == ' debug ' :
if not env [ ' debug ' ] :
2010-11-01 13:30:22 +00:00
print ' scons: warning: debug option is deprecated and will be removed eventually; use instead '
print
print ' scons build=release '
print
2010-09-29 14:08:53 +01:00
env [ ' build ' ] = ' release '
if env [ ' profile ' ] :
2010-11-01 13:30:22 +00:00
print ' scons: warning: profile option is deprecated and will be removed eventually; use instead '
print
print ' scons build=profile '
print
2010-09-29 14:08:53 +01:00
env [ ' build ' ] = ' profile '
if False :
# Enforce SConscripts to use the new build variable
env . popitem ( ' debug ' )
env . popitem ( ' profile ' )
else :
# Backwards portability with older sconscripts
if env [ ' build ' ] in ( ' debug ' , ' checked ' ) :
env [ ' debug ' ] = True
env [ ' profile ' ] = False
if env [ ' build ' ] == ' profile ' :
env [ ' debug ' ] = False
env [ ' profile ' ] = True
if env [ ' build ' ] == ' release ' :
env [ ' debug ' ] = False
env [ ' profile ' ] = False
2008-07-17 03:23:43 +01:00
# Put build output in a separate dir, which depends on the current
# configuration. See also http://www.scons.org/wiki/AdvancedBuildExample
build_topdir = ' build '
build_subdir = env [ ' platform ' ]
2011-06-17 14:48:28 +01:00
if env [ ' embedded ' ] :
build_subdir = ' embedded- ' + build_subdir
2008-07-17 03:23:43 +01:00
if env [ ' machine ' ] != ' generic ' :
build_subdir + = ' - ' + env [ ' machine ' ]
2010-09-29 14:08:53 +01:00
if env [ ' build ' ] != ' release ' :
build_subdir + = ' - ' + env [ ' build ' ]
2008-07-17 03:23:43 +01:00
build_dir = os . path . join ( build_topdir , build_subdir )
# Place the .sconsign file in the build dir too, to avoid issues with
# different scons versions building the same source file
2010-09-29 14:08:53 +01:00
env [ ' build_dir ' ] = build_dir
2008-07-17 03:23:43 +01:00
env . SConsignFile ( os . path . join ( build_dir , ' .sconsign ' ) )
2010-02-14 15:34:39 +00:00
if ' SCONS_CACHE_DIR ' in os . environ :
print ' scons: Using build cache in %s . ' % ( os . environ [ ' SCONS_CACHE_DIR ' ] , )
env . CacheDir ( os . environ [ ' SCONS_CACHE_DIR ' ] )
2009-12-25 17:39:47 +00:00
env [ ' CONFIGUREDIR ' ] = os . path . join ( build_dir , ' conf ' )
env [ ' CONFIGURELOG ' ] = os . path . join ( os . path . abspath ( build_dir ) , ' config.log ' )
2008-07-17 03:23:43 +01:00
2009-02-10 18:11:56 +00:00
# Parallel build
if env . GetOption ( ' num_jobs ' ) < = 1 :
env . SetOption ( ' num_jobs ' , num_jobs ( ) )
2010-11-01 13:30:22 +00:00
env . Decider ( ' MD5-timestamp ' )
env . SetOption ( ' max_drift ' , 60 )
2008-07-17 03:23:43 +01:00
# C preprocessor options
cppdefines = [ ]
2010-09-29 14:08:53 +01:00
if env [ ' build ' ] in ( ' debug ' , ' checked ' ) :
2008-07-17 03:23:43 +01:00
cppdefines + = [ ' DEBUG ' ]
else :
cppdefines + = [ ' NDEBUG ' ]
2010-09-29 14:08:53 +01:00
if env [ ' build ' ] == ' profile ' :
2008-07-17 03:23:43 +01:00
cppdefines + = [ ' PROFILE ' ]
2011-06-17 16:28:27 +01:00
if env [ ' platform ' ] in ( ' posix ' , ' linux ' , ' freebsd ' , ' darwin ' ) :
cppdefines + = [
' _POSIX_SOURCE ' ,
( ' _POSIX_C_SOURCE ' , ' 199309L ' ) ,
' _SVID_SOURCE ' ,
' _BSD_SOURCE ' ,
' _GNU_SOURCE ' ,
2015-03-01 08:41:48 +00:00
' _DEFAULT_SOURCE ' ,
2012-09-19 06:09:26 +01:00
' HAVE_PTHREAD ' ,
2011-06-17 16:28:27 +01:00
' HAVE_POSIX_MEMALIGN ' ,
]
2011-06-17 20:12:18 +01:00
if env [ ' platform ' ] == ' darwin ' :
cppdefines + = [
' _DARWIN_C_SOURCE ' ,
' GLX_USE_APPLEGL ' ,
' GLX_DIRECT_RENDERING ' ,
]
else :
cppdefines + = [
' GLX_DIRECT_RENDERING ' ,
' GLX_INDIRECT_RENDERING ' ,
]
if env [ ' platform ' ] in ( ' linux ' , ' freebsd ' ) :
cppdefines + = [ ' HAVE_ALIAS ' ]
else :
cppdefines + = [ ' GLX_ALIAS_UNSUPPORTED ' ]
2014-08-20 07:40:23 +01:00
if env [ ' platform ' ] in ( ' linux ' , ' darwin ' ) :
cppdefines + = [ ' HAVE_XLOCALE_H ' ]
2014-03-19 00:58:01 +00:00
if env [ ' platform ' ] == ' haiku ' :
cppdefines + = [
' HAVE_PTHREAD ' ,
' HAVE_POSIX_MEMALIGN '
]
2008-07-17 03:23:43 +01:00
if platform == ' windows ' :
cppdefines + = [
' WIN32 ' ,
' _WINDOWS ' ,
2009-01-22 14:26:30 +00:00
#'_UNICODE',
#'UNICODE',
2010-02-12 13:22:59 +00:00
# http://msdn.microsoft.com/en-us/library/aa383745.aspx
( ' _WIN32_WINNT ' , ' 0x0601 ' ) ,
( ' WINVER ' , ' 0x0601 ' ) ,
2008-07-17 03:23:43 +01:00
]
2013-04-24 22:02:18 +01:00
if gcc_compat :
2011-09-06 13:13:32 +01:00
cppdefines + = [ ( ' __MSVCRT_VERSION__ ' , ' 0x0700 ' ) ]
2011-11-09 07:05:52 +00:00
if msvc :
2009-03-25 19:32:54 +00:00
cppdefines + = [
' VC_EXTRALEAN ' ,
2009-10-26 15:11:11 +00:00
' _USE_MATH_DEFINES ' ,
2009-10-21 17:03:52 +01:00
' _CRT_SECURE_NO_WARNINGS ' ,
2009-03-25 19:32:54 +00:00
' _CRT_SECURE_NO_DEPRECATE ' ,
2009-10-21 17:03:52 +01:00
' _SCL_SECURE_NO_WARNINGS ' ,
' _SCL_SECURE_NO_DEPRECATE ' ,
2013-03-14 17:40:14 +00:00
' _ALLOW_KEYWORD_MACROS ' ,
2015-03-20 06:27:59 +00:00
' _HAS_EXCEPTIONS=0 ' , # Tell C++ STL to not use exceptions
2009-03-25 19:32:54 +00:00
]
2010-09-29 14:08:53 +01:00
if env [ ' build ' ] in ( ' debug ' , ' checked ' ) :
2008-07-17 03:23:43 +01:00
cppdefines + = [ ' _DEBUG ' ]
if platform == ' windows ' :
cppdefines + = [ ' PIPE_SUBSYSTEM_WINDOWS_USER ' ]
2011-06-17 14:48:28 +01:00
if env [ ' embedded ' ] :
cppdefines + = [ ' PIPE_SUBSYSTEM_EMBEDDED ' ]
2012-08-12 08:02:32 +01:00
if env [ ' texture_float ' ] :
print ' warning: Floating-point textures enabled. '
print ' warning: Please consult docs/patents.txt with your lawyer before building Mesa. '
cppdefines + = [ ' TEXTURE_FLOAT_ENABLED ' ]
2015-02-27 15:42:23 +00:00
if gcc_compat :
ccversion = env [ ' CCVERSION ' ]
cppdefines + = [
' HAVE___BUILTIN_EXPECT ' ,
' HAVE___BUILTIN_FFS ' ,
' HAVE___BUILTIN_FFSLL ' ,
' HAVE_FUNC_ATTRIBUTE_FLATTEN ' ,
2015-03-07 22:07:10 +00:00
' HAVE_FUNC_ATTRIBUTE_UNUSED ' ,
2015-03-04 13:56:35 +00:00
# GCC 3.0
' HAVE_FUNC_ATTRIBUTE_FORMAT ' ,
' HAVE_FUNC_ATTRIBUTE_PACKED ' ,
# GCC 3.4
' HAVE___BUILTIN_CTZ ' ,
' HAVE___BUILTIN_POPCOUNT ' ,
' HAVE___BUILTIN_POPCOUNTLL ' ,
' HAVE___BUILTIN_CLZ ' ,
' HAVE___BUILTIN_CLZLL ' ,
2015-02-27 15:42:23 +00:00
]
if distutils . version . LooseVersion ( ccversion ) > = distutils . version . LooseVersion ( ' 4.5 ' ) :
cppdefines + = [ ' HAVE___BUILTIN_UNREACHABLE ' ]
2008-07-17 03:23:43 +01:00
env . Append ( CPPDEFINES = cppdefines )
# C compiler options
2009-06-26 19:50:12 +01:00
cflags = [ ] # C
cxxflags = [ ] # C++
ccflags = [ ] # C & C++
2013-04-24 22:02:18 +01:00
if gcc_compat :
2010-02-04 19:37:30 +00:00
ccversion = env [ ' CCVERSION ' ]
2010-09-29 14:08:53 +01:00
if env [ ' build ' ] == ' debug ' :
ccflags + = [ ' -O0 ' ]
2013-04-24 22:02:18 +01:00
elif env [ ' gcc ' ] and ccversion . startswith ( ' 4.2. ' ) :
2009-06-28 11:12:22 +01:00
# gcc 4.2.x optimizer is broken
print " warning: gcc 4.2.x optimizer is broken -- disabling optimizations "
2010-09-29 14:08:53 +01:00
ccflags + = [ ' -O0 ' ]
2008-07-17 03:23:43 +01:00
else :
2010-09-29 14:08:53 +01:00
ccflags + = [ ' -O3 ' ]
2013-04-24 22:02:18 +01:00
if env [ ' gcc ' ] :
# gcc's builtin memcmp is slower than glibc's
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
ccflags + = [ ' -fno-builtin-memcmp ' ]
2011-06-17 20:12:18 +01:00
# Work around aliasing bugs - developers should comment this out
ccflags + = [ ' -fno-strict-aliasing ' ]
2011-09-08 09:59:01 +01:00
ccflags + = [ ' -g ' ]
2010-09-29 14:08:53 +01:00
if env [ ' build ' ] in ( ' checked ' , ' profile ' ) :
2009-09-20 18:07:16 +01:00
# See http://code.google.com/p/jrfonseca/wiki/Gprof2Dot#Which_options_should_I_pass_to_gcc_when_compiling_for_profiling?
ccflags + = [
' -fno-omit-frame-pointer ' ,
]
2013-04-24 22:02:18 +01:00
if env [ ' gcc ' ] :
ccflags + = [ ' -fno-optimize-sibling-calls ' ]
2008-07-17 03:23:43 +01:00
if env [ ' machine ' ] == ' x86 ' :
2009-06-26 19:50:12 +01:00
ccflags + = [
2008-07-17 03:23:43 +01:00
' -m32 ' ,
#'-march=pentium4',
]
2015-03-04 13:56:35 +00:00
if platform != ' haiku ' :
2010-09-02 13:44:29 +01:00
# NOTE: We need to ensure stack is realigned given that we
# produce shared objects, and have no control over the stack
# alignment policy of the application. Therefore we need
# -mstackrealign ore -mincoming-stack-boundary=2.
#
# XXX: We could have SSE without -mstackrealign if we always used
# __attribute__((force_align_arg_pointer)), but that's not
# always the case.
2009-10-14 16:16:40 +01:00
ccflags + = [
2010-09-02 13:44:29 +01:00
' -mstackrealign ' , # ensure stack is aligned
2014-11-25 22:11:42 +00:00
' -msse ' , ' -msse2 ' , # enable SIMD intrinsics
2014-11-25 22:15:40 +00:00
' -mfpmath=sse ' , # generate SSE floating-point arithmetic
2009-10-14 16:16:40 +01:00
]
2010-07-19 19:31:44 +01:00
if platform in [ ' windows ' , ' darwin ' ] :
2010-07-16 21:26:43 +01:00
# Workaround http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216
ccflags + = [ ' -fno-common ' ]
2012-06-14 16:08:07 +01:00
if platform in [ ' haiku ' ] :
# Make optimizations compatible with Pentium or higher on Haiku
ccflags + = [
' -mstackrealign ' , # ensure stack is aligned
' -march=i586 ' , # Haiku target is Pentium
2013-01-06 22:09:35 +00:00
' -mtune=i686 ' # use i686 where we can
2012-06-14 16:08:07 +01:00
]
2008-07-17 03:23:43 +01:00
if env [ ' machine ' ] == ' x86_64 ' :
2009-06-26 19:50:12 +01:00
ccflags + = [ ' -m64 ' ]
2010-08-17 08:20:58 +01:00
if platform == ' darwin ' :
ccflags + = [ ' -fno-common ' ]
2012-10-20 03:33:11 +01:00
if env [ ' platform ' ] not in ( ' cygwin ' , ' haiku ' , ' windows ' ) :
2011-06-17 16:28:27 +01:00
ccflags + = [ ' -fvisibility=hidden ' ]
2009-03-13 16:21:30 +00:00
# See also:
# - http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
2009-06-26 19:50:12 +01:00
ccflags + = [
2008-07-17 03:23:43 +01:00
' -Wall ' ,
' -Wno-long-long ' ,
' -fmessage-length=0 ' , # be nice to Eclipse
]
2009-06-26 19:50:12 +01:00
cflags + = [
' -Wmissing-prototypes ' ,
' -std=gnu99 ' ,
]
2012-08-01 06:55:39 +01:00
if icc :
cflags + = [
' -std=gnu99 ' ,
]
2008-07-17 03:23:43 +01:00
if msvc :
# See also:
2008-09-01 01:47:40 +01:00
# - http://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
2008-07-17 03:23:43 +01:00
# - cl /?
2014-05-01 14:19:13 +01:00
if ' MSVC_VERSION ' not in env or distutils . version . LooseVersion ( env [ ' MSVC_VERSION ' ] ) < distutils . version . LooseVersion ( ' 12.0 ' ) :
# Use bundled stdbool.h and stdint.h headers for older MSVC
# versions. stdint.h was introduced in MSVC 2010, but stdbool.h
# was only introduced in MSVC 2013.
top_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , ' .. ' ) )
env . Append ( CPPPATH = [ os . path . join ( top_dir , ' include/c99 ' ) ] )
2010-09-29 14:08:53 +01:00
if env [ ' build ' ] == ' debug ' :
2009-06-26 19:50:12 +01:00
ccflags + = [
2008-07-17 03:23:43 +01:00
' /Od ' , # disable optimizations
' /Oi ' , # enable intrinsic functions
]
else :
2013-03-20 15:41:52 +00:00
if ' MSVC_VERSION ' in env and distutils . version . LooseVersion ( env [ ' MSVC_VERSION ' ] ) < distutils . version . LooseVersion ( ' 11.0 ' ) :
2013-03-15 15:23:54 +00:00
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 ) '
2009-06-26 19:50:12 +01:00
ccflags + = [
2009-06-04 18:34:02 +01:00
' /O2 ' , # optimize for speed
2011-02-08 10:26:17 +00:00
]
if env [ ' build ' ] == ' release ' :
ccflags + = [
2009-12-11 15:16:22 +00:00
' /GL ' , # enable whole program optimization
2008-07-17 03:23:43 +01:00
]
2011-02-08 10:26:17 +00:00
else :
ccflags + = [
2011-03-08 13:18:56 +00:00
' /Oy- ' , # disable frame pointer omission
2011-02-08 10:26:17 +00:00
' /GL- ' , # disable whole program optimization
]
2009-06-26 19:50:12 +01:00
ccflags + = [
2008-07-17 03:23:43 +01:00
' /W3 ' , # warning level
2014-11-25 22:27:04 +00:00
' /wd4018 ' , # signed/unsigned mismatch
2015-03-18 14:18:28 +00:00
' /wd4056 ' , # overflow in floating-point constant arithmetic
2014-05-01 15:40:43 +01:00
' /wd4244 ' , # conversion from 'type1' to 'type2', possible loss of data
2015-03-20 12:01:23 +00:00
' /wd4267 ' , # 'var' : conversion from 'size_t' to 'type', possible loss of data
2014-05-01 15:40:43 +01:00
' /wd4305 ' , # truncation from 'type1' to 'type2'
2015-03-19 22:22:26 +00:00
' /wd4351 ' , # new behavior: elements of array 'array' will be default initialized
2015-03-18 14:18:28 +00:00
' /wd4756 ' , # overflow in constant arithmetic
2014-05-01 15:40:43 +01:00
' /wd4800 ' , # forcing value to bool 'true' or 'false' (performance warning)
2011-11-09 10:33:21 +00:00
' /wd4996 ' , # disable deprecated POSIX name warnings
2008-07-17 03:23:43 +01:00
]
2008-09-01 01:47:40 +01:00
if env [ ' machine ' ] == ' x86 ' :
2009-06-26 19:50:12 +01:00
ccflags + = [
2014-11-25 22:15:40 +00:00
' /arch:SSE2 ' , # use the SSE2 instructions (default since MSVC 2012)
2008-09-01 01:47:40 +01:00
]
2008-07-17 03:23:43 +01:00
if platform == ' windows ' :
2009-06-26 19:50:12 +01:00
ccflags + = [
2008-07-17 03:23:43 +01:00
# TODO
]
# Automatic pdb generation
# See http://scons.tigris.org/issues/show_bug.cgi?id=1656
env . EnsureSConsVersion ( 0 , 98 , 0 )
env [ ' PDB ' ] = ' $ {TARGET.base} .pdb '
2009-06-26 19:50:12 +01:00
env . Append ( CCFLAGS = ccflags )
2008-07-17 03:23:43 +01:00
env . Append ( CFLAGS = cflags )
2009-06-26 19:50:12 +01:00
env . Append ( CXXFLAGS = cxxflags )
2008-07-17 03:23:43 +01:00
2009-01-06 16:16:38 +00:00
if env [ ' platform ' ] == ' windows ' and msvc :
# Choose the appropriate MSVC CRT
# http://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
2010-09-29 14:24:52 +01:00
if env [ ' build ' ] in ( ' debug ' , ' checked ' ) :
2009-01-06 16:16:38 +00:00
env . Append ( CCFLAGS = [ ' /MTd ' ] )
env . Append ( SHCCFLAGS = [ ' /LDd ' ] )
else :
env . Append ( CCFLAGS = [ ' /MT ' ] )
env . Append ( SHCCFLAGS = [ ' /LD ' ] )
2014-04-14 14:31:02 +01:00
# Static code analysis
if env [ ' analyze ' ] :
if env [ ' msvc ' ] :
# http://msdn.microsoft.com/en-us/library/ms173498.aspx
env . Append ( CCFLAGS = [
' /analyze ' ,
#'/analyze:log', '${TARGET.base}.xml',
2015-03-24 19:50:48 +00:00
' /wd28251 ' , # Inconsistent annotation for function
2014-04-14 14:31:02 +01:00
] )
if env [ ' clang ' ] :
# scan-build will produce more comprehensive output
env . Append ( CCFLAGS = [ ' --analyze ' ] )
2008-07-17 03:23:43 +01:00
# Assembler options
2013-04-24 22:02:18 +01:00
if gcc_compat :
2008-07-17 03:23:43 +01:00
if env [ ' machine ' ] == ' x86 ' :
env . Append ( ASFLAGS = [ ' -m32 ' ] )
if env [ ' machine ' ] == ' x86_64 ' :
env . Append ( ASFLAGS = [ ' -m64 ' ] )
# Linker options
linkflags = [ ]
2009-06-28 10:54:23 +01:00
shlinkflags = [ ]
2013-04-24 22:02:18 +01:00
if gcc_compat :
2008-07-17 03:23:43 +01:00
if env [ ' machine ' ] == ' x86 ' :
linkflags + = [ ' -m32 ' ]
if env [ ' machine ' ] == ' x86_64 ' :
linkflags + = [ ' -m64 ' ]
2010-01-28 09:32:15 +00:00
if env [ ' platform ' ] not in ( ' darwin ' ) :
shlinkflags + = [
' -Wl,-Bsymbolic ' ,
]
2009-08-13 16:32:51 +01:00
# Handle circular dependencies in the libraries
2010-01-24 05:43:26 +00:00
if env [ ' platform ' ] in ( ' darwin ' ) :
pass
else :
env [ ' _LIBFLAGS ' ] = ' -Wl,--start-group ' + env [ ' _LIBFLAGS ' ] + ' -Wl,--end-group '
2011-09-06 13:13:32 +01:00
if env [ ' platform ' ] == ' windows ' :
2014-09-11 11:43:04 +01:00
linkflags + = [
' -Wl,--nxcompat ' , # DEP
' -Wl,--dynamicbase ' , # ASLR
]
2011-09-06 13:13:32 +01:00
# Avoid depending on gcc runtime DLLs
linkflags + = [ ' -static-libgcc ' ]
2011-11-03 09:58:52 +00:00
if ' w64 ' in env [ ' CC ' ] . split ( ' - ' ) :
2011-09-06 13:14:09 +01:00
linkflags + = [ ' -static-libstdc++ ' ]
2011-09-06 13:13:32 +01:00
# Handle the @xx symbol munging of DLL exports
shlinkflags + = [ ' -Wl,--enable-stdcall-fixup ' ]
#shlinkflags += ['-Wl,--kill-at']
2009-12-11 15:16:22 +00:00
if msvc :
2011-02-08 10:26:17 +00:00
if env [ ' build ' ] == ' release ' :
2009-12-11 15:16:22 +00:00
# enable Link-time Code Generation
linkflags + = [ ' /LTCG ' ]
env . Append ( ARFLAGS = [ ' /LTCG ' ] )
2009-02-12 12:59:58 +00:00
if platform == ' windows ' and msvc :
2008-07-17 03:23:43 +01:00
# See also:
# - http://msdn2.microsoft.com/en-us/library/y0zzbyt4.aspx
2009-02-12 11:57:45 +00:00
linkflags + = [
' /fixed:no ' ,
' /incremental:no ' ,
2014-09-11 11:43:04 +01:00
' /dynamicbase ' , # ASLR
' /nxcompat ' , # DEP
2009-02-12 11:57:45 +00:00
]
2008-07-17 03:23:43 +01:00
env . Append ( LINKFLAGS = linkflags )
2009-06-28 10:54:23 +01:00
env . Append ( SHLINKFLAGS = shlinkflags )
2008-07-17 03:23:43 +01:00
2011-01-30 11:17:07 +00:00
# We have C++ in several libraries, so always link with the C++ compiler
2013-04-24 22:02:18 +01:00
if gcc_compat :
2011-01-30 11:17:07 +00:00
env [ ' LINK ' ] = env [ ' CXX ' ]
2008-07-17 03:25:20 +01:00
# Default libs
2011-06-17 16:28:27 +01:00
libs = [ ]
2012-08-30 07:16:44 +01:00
if env [ ' platform ' ] in ( ' darwin ' , ' freebsd ' , ' linux ' , ' posix ' , ' sunos ' ) :
2011-06-17 16:28:27 +01:00
libs + = [ ' m ' , ' pthread ' , ' dl ' ]
2012-12-05 08:59:21 +00:00
if env [ ' platform ' ] in ( ' linux ' , ) :
2012-12-04 19:36:52 +00:00
libs + = [ ' rt ' ]
2013-10-04 18:28:42 +01:00
if env [ ' platform ' ] in ( ' haiku ' ) :
2013-10-20 05:31:50 +01:00
libs + = [ ' root ' , ' be ' , ' network ' , ' translation ' ]
2011-06-17 16:28:27 +01:00
env . Append ( LIBS = libs )
2008-07-17 03:25:20 +01:00
2011-08-10 09:07:29 +01:00
# OpenMP
if env [ ' openmp ' ] :
if env [ ' msvc ' ] :
env . Append ( CCFLAGS = [ ' /openmp ' ] )
# When building openmp release VS2008 link.exe crashes with LNK1103 error.
# Workaround: overwrite PDB flags with empty value as it isn't required anyways
if env [ ' build ' ] == ' release ' :
env [ ' PDB ' ] = ' '
if env [ ' gcc ' ] :
env . Append ( CCFLAGS = [ ' -fopenmp ' ] )
env . Append ( LIBS = [ ' gomp ' ] )
2010-11-01 13:30:22 +00:00
# Load tools
2011-03-03 15:28:36 +00:00
env . Tool ( ' lex ' )
2015-03-19 11:53:36 +00:00
if env [ ' msvc ' ] :
env . Append ( LEXFLAGS = [
# Force flex to use const keyword in prototypes, as relies on
# __cplusplus or __STDC__ macro to determine whether it's safe to
# use const keyword, but MSVC never defines __STDC__ unless we
# disable all MSVC extensions.
' -DYY_USE_CONST= ' ,
] )
2015-03-20 06:53:09 +00:00
# Flex relies on __STDC_VERSION__>=199901L to decide when to include
# C99 inttypes.h. We always have inttypes.h available with MSVC
# (either the one bundled with MSVC 2013, or the one we bundle
# ourselves), but we can't just define __STDC_VERSION__ without
# breaking stuff, as MSVC doesn't fully support C99. There's also no
# way to premptively include stdint.
env . Append ( CCFLAGS = [ ' -FIinttypes.h ' ] )
2015-03-19 13:30:19 +00:00
if host_platform . system ( ) == ' Windows ' :
# Prefer winflexbison binaries, as not only they are easier to install
# (no additional dependencies), but also better Windows support.
if check_prog ( env , ' win_flex ' ) :
env [ " LEX " ] = ' win_flex '
env . Append ( LEXFLAGS = [
# windows compatibility (uses <io.h> instead of <unistd.h> and
# _isatty, _fileno functions)
' --wincompat '
] )
2011-03-03 15:28:36 +00:00
env . Tool ( ' yacc ' )
2015-03-19 13:30:19 +00:00
if host_platform . system ( ) == ' Windows ' :
if check_prog ( env , ' win_bison ' ) :
env [ " YACC " ] = ' win_bison '
2010-04-10 02:41:39 +01:00
if env [ ' llvm ' ] :
env . Tool ( ' llvm ' )
2010-11-01 13:30:22 +00:00
2008-07-17 03:23:43 +01:00
# Custom builders and methods
2009-12-31 17:58:56 +00:00
env . Tool ( ' custom ' )
2008-09-07 23:54:15 +01:00
createInstallMethods ( env )
2015-03-04 14:23:52 +00:00
createMSVCCompatMethods ( env )
2008-07-17 03:23:43 +01:00
2014-11-15 22:07:42 +00:00
env . PkgCheckModules ( ' X11 ' , [ ' x11 ' , ' xext ' , ' xdamage ' , ' xfixes ' , ' glproto >= 1.4.13 ' ] )
2014-06-16 11:24:15 +01:00
env . PkgCheckModules ( ' XCB ' , [ ' x11-xcb ' , ' xcb-glx >= 1.8.1 ' , ' xcb-dri2 >= 1.8 ' ] )
2011-06-30 17:36:37 +01:00
env . PkgCheckModules ( ' XF86VIDMODE ' , [ ' xxf86vm ' ] )
2014-02-13 00:28:27 +00:00
env . PkgCheckModules ( ' DRM ' , [ ' libdrm >= 2.4.38 ' ] )
env . PkgCheckModules ( ' UDEV ' , [ ' libudev >= 151 ' ] )
2011-06-30 17:36:37 +01:00
2015-01-19 20:54:44 +00:00
if env [ ' x11 ' ] :
env . Append ( CPPPATH = env [ ' X11_CPPPATH ' ] )
2011-06-30 17:36:37 +01:00
env [ ' dri ' ] = env [ ' x11 ' ] and env [ ' drm ' ]
2008-07-17 03:23:43 +01:00
# for debugging
#print env.Dump()
2008-06-06 06:48:57 +01:00
def exists ( env ) :
2008-07-17 03:23:43 +01:00
return 1