• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#######################################################################
2# Common SCons code
3
4import os
5import os.path
6import re
7import subprocess
8import sys
9import platform as _platform
10
11import SCons.Script.SConscript
12
13
14#######################################################################
15# Defaults
16
17host_platform = _platform.system().lower()
18if host_platform.startswith('cygwin'):
19    host_platform = 'cygwin'
20
21# Search sys.argv[] for a "platform=foo" argument since we don't have
22# an 'env' variable at this point.
23if 'platform' in SCons.Script.ARGUMENTS:
24    target_platform = SCons.Script.ARGUMENTS['platform']
25else:
26    target_platform = host_platform
27
28_machine_map = {
29    'x86': 'x86',
30    'i386': 'x86',
31    'i486': 'x86',
32    'i586': 'x86',
33    'i686': 'x86',
34    'BePC': 'x86',
35    'Intel': 'x86',
36    'ppc': 'ppc',
37    'BeBox': 'ppc',
38    'BeMac': 'ppc',
39    'AMD64': 'x86_64',
40    'x86_64': 'x86_64',
41    'sparc': 'sparc',
42    'sun4u': 'sparc',
43}
44
45
46# find host_machine value
47if 'PROCESSOR_ARCHITECTURE' in os.environ:
48    host_machine = os.environ['PROCESSOR_ARCHITECTURE']
49else:
50    host_machine = _platform.machine()
51host_machine = _machine_map.get(host_machine, 'generic')
52
53default_machine = host_machine
54default_toolchain = 'default'
55
56if target_platform == 'windows' and host_platform != 'windows':
57    default_machine = 'x86'
58    default_toolchain = 'crossmingw'
59
60
61# find default_llvm value
62if 'LLVM' in os.environ or 'LLVM_CONFIG' in os.environ:
63    default_llvm = 'yes'
64else:
65    default_llvm = 'no'
66    try:
67        if target_platform != 'windows' and \
68           subprocess.call(['llvm-config', '--version'],
69                           stdout=subprocess.PIPE) == 0:
70            default_llvm = 'yes'
71    except:
72        pass
73
74
75#######################################################################
76# Common options
77
78def AddOptions(opts):
79    try:
80        from SCons.Variables.BoolVariable import BoolVariable as BoolOption
81    except ImportError:
82        from SCons.Options.BoolOption import BoolOption
83    try:
84        from SCons.Variables.EnumVariable import EnumVariable as EnumOption
85    except ImportError:
86        from SCons.Options.EnumOption import EnumOption
87    opts.Add(EnumOption('build', 'build type', 'debug',
88                        allowed_values=('debug', 'checked', 'profile',
89                                        'release', 'opt')))
90    opts.Add(BoolOption('verbose', 'verbose output', 'no'))
91    opts.Add(EnumOption('machine', 'use machine-specific assembly code',
92                        default_machine,
93                        allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
94    opts.Add(EnumOption('platform', 'target platform', host_platform,
95                        allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku',
96                                        'linux', 'sunos', 'windows')))
97    opts.Add(BoolOption('embedded', 'embedded build', 'no'))
98    opts.Add(BoolOption('analyze',
99                        'enable static code analysis where available', 'no'))
100    opts.Add(BoolOption('asan', 'enable Address Sanitizer', 'no'))
101    opts.Add('toolchain', 'compiler toolchain', default_toolchain)
102    opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support',
103                        'no'))
104    opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
105    opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)',
106                        'no'))
107    opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
108    opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
109    opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
110    opts.Add(BoolOption('texture_float',
111                        'enable floating-point textures and renderbuffers',
112                        'no'))
113    opts.Add(BoolOption('swr', 'Build OpenSWR', 'no'))
114    if host_platform == 'windows':
115        opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')
116