common.py 3.69 KB
Newer Older
1 2 3 4 5
#######################################################################
# Common SCons code

import os
import os.path
Brian Paul's avatar
Brian Paul committed
6
import re
7
import subprocess
8 9 10
import sys
import platform as _platform

11 12
import SCons.Script.SConscript

13 14 15 16

#######################################################################
# Defaults

17
host_platform = _platform.system().lower()
18 19
if host_platform.startswith('cygwin'):
    host_platform = 'cygwin'
20

21 22 23
# Search sys.argv[] for a "platform=foo" argument since we don't have
# an 'env' variable at this point.
if 'platform' in SCons.Script.ARGUMENTS:
Jose Fonseca's avatar
Jose Fonseca committed
24
    target_platform = SCons.Script.ARGUMENTS['platform']
25
else:
Jose Fonseca's avatar
Jose Fonseca committed
26
    target_platform = host_platform
27

28
_machine_map = {
Vinson Lee's avatar
Vinson Lee committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42
    'x86': 'x86',
    'i386': 'x86',
    'i486': 'x86',
    'i586': 'x86',
    'i686': 'x86',
    'BePC': 'x86',
    'Intel': 'x86',
    'ppc': 'ppc',
    'BeBox': 'ppc',
    'BeMac': 'ppc',
    'AMD64': 'x86_64',
    'x86_64': 'x86_64',
    'sparc': 'sparc',
    'sun4u': 'sparc',
43
}
44 45


Jose Fonseca's avatar
Jose Fonseca committed
46
# find host_machine value
47
if 'PROCESSOR_ARCHITECTURE' in os.environ:
Vinson Lee's avatar
Vinson Lee committed
48
    host_machine = os.environ['PROCESSOR_ARCHITECTURE']
49
else:
Vinson Lee's avatar
Vinson Lee committed
50
    host_machine = _platform.machine()
Jose Fonseca's avatar
Jose Fonseca committed
51 52 53
host_machine = _machine_map.get(host_machine, 'generic')

default_machine = host_machine
54 55
default_toolchain = 'default'

56
if target_platform == 'windows' and host_platform != 'windows':
57 58
    default_machine = 'x86'
    default_toolchain = 'crossmingw'
59

60 61

# find default_llvm value
62
if 'LLVM' in os.environ or 'LLVM_CONFIG' in os.environ:
63 64 65
    default_llvm = 'yes'
else:
    default_llvm = 'no'
66
    try:
Jose Fonseca's avatar
Jose Fonseca committed
67
        if target_platform != 'windows' and \
Vinson Lee's avatar
Vinson Lee committed
68 69
           subprocess.call(['llvm-config', '--version'],
                           stdout=subprocess.PIPE) == 0:
70 71 72
            default_llvm = 'yes'
    except:
        pass
73

74

75 76 77
#######################################################################
# Common options

78
def AddOptions(opts):
Vinson Lee's avatar
Vinson Lee committed
79 80 81 82 83 84 85 86 87 88
    try:
        from SCons.Variables.BoolVariable import BoolVariable as BoolOption
    except ImportError:
        from SCons.Options.BoolOption import BoolOption
    try:
        from SCons.Variables.EnumVariable import EnumVariable as EnumOption
    except ImportError:
        from SCons.Options.EnumOption import EnumOption
    opts.Add(EnumOption('build', 'build type', 'debug',
                        allowed_values=('debug', 'checked', 'profile',
89
                                        'release')))
Vinson Lee's avatar
Vinson Lee committed
90 91 92 93 94 95 96 97 98 99
    opts.Add(BoolOption('verbose', 'verbose output', 'no'))
    opts.Add(EnumOption('machine', 'use machine-specific assembly code',
                        default_machine,
                        allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
    opts.Add(EnumOption('platform', 'target platform', host_platform,
                        allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku',
                                        'linux', 'sunos', 'windows')))
    opts.Add(BoolOption('embedded', 'embedded build', 'no'))
    opts.Add(BoolOption('analyze',
                        'enable static code analysis where available', 'no'))
100
    opts.Add(BoolOption('asan', 'enable Address Sanitizer', 'no'))
Vinson Lee's avatar
Vinson Lee committed
101 102 103 104 105 106 107
    opts.Add('toolchain', 'compiler toolchain', default_toolchain)
    opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
    opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)',
                        'no'))
    opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
    opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
    opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
108
    opts.Add(BoolOption('swr', 'Build OpenSWR', 'no'))
Vinson Lee's avatar
Vinson Lee committed
109 110
    if host_platform == 'windows':
        opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')
111
        opts.Add('MSVC_USE_SCRIPT', 'Microsoft Visual C/C++ vcvarsall script', True)