common.py revision 848b8605
1848b8605Smrg#######################################################################
2848b8605Smrg# Common SCons code
3848b8605Smrg
4848b8605Smrgimport os
5848b8605Smrgimport os.path
6848b8605Smrgimport re
7848b8605Smrgimport subprocess
8848b8605Smrgimport sys
9848b8605Smrgimport platform as _platform
10848b8605Smrg
11848b8605Smrgimport SCons.Script.SConscript
12848b8605Smrg
13848b8605Smrg
14848b8605Smrg#######################################################################
15848b8605Smrg# Defaults
16848b8605Smrg
17848b8605Smrghost_platform = _platform.system().lower()
18848b8605Smrgif host_platform.startswith('cygwin'):
19848b8605Smrg    host_platform = 'cygwin'
20848b8605Smrg
21848b8605Smrg# Search sys.argv[] for a "platform=foo" argument since we don't have
22848b8605Smrg# an 'env' variable at this point.
23848b8605Smrgif 'platform' in SCons.Script.ARGUMENTS:
24848b8605Smrg    target_platform = SCons.Script.ARGUMENTS['platform']
25848b8605Smrgelse:
26848b8605Smrg    target_platform = host_platform
27848b8605Smrg
28848b8605Smrg_machine_map = {
29848b8605Smrg	'x86': 'x86',
30848b8605Smrg	'i386': 'x86',
31848b8605Smrg	'i486': 'x86',
32848b8605Smrg	'i586': 'x86',
33848b8605Smrg	'i686': 'x86',
34848b8605Smrg	'BePC': 'x86',
35848b8605Smrg	'Intel': 'x86',
36848b8605Smrg	'ppc' : 'ppc',
37848b8605Smrg	'BeBox': 'ppc',
38848b8605Smrg	'BeMac': 'ppc',
39848b8605Smrg	'AMD64': 'x86_64',
40848b8605Smrg	'x86_64': 'x86_64',
41848b8605Smrg	'sparc': 'sparc',
42848b8605Smrg	'sun4u': 'sparc',
43848b8605Smrg}
44848b8605Smrg
45848b8605Smrg
46848b8605Smrg# find host_machine value
47848b8605Smrgif 'PROCESSOR_ARCHITECTURE' in os.environ:
48848b8605Smrg	host_machine = os.environ['PROCESSOR_ARCHITECTURE']
49848b8605Smrgelse:
50848b8605Smrg	host_machine = _platform.machine()
51848b8605Smrghost_machine = _machine_map.get(host_machine, 'generic')
52848b8605Smrg
53848b8605Smrgdefault_machine = host_machine
54848b8605Smrgdefault_toolchain = 'default'
55848b8605Smrg
56848b8605Smrgif target_platform == 'windows' and host_platform != 'windows':
57848b8605Smrg    default_machine = 'x86'
58848b8605Smrg    default_toolchain = 'crossmingw'
59848b8605Smrg
60848b8605Smrg
61848b8605Smrg# find default_llvm value
62848b8605Smrgif 'LLVM' in os.environ:
63848b8605Smrg    default_llvm = 'yes'
64848b8605Smrgelse:
65848b8605Smrg    default_llvm = 'no'
66848b8605Smrg    try:
67848b8605Smrg        if target_platform != 'windows' and \
68848b8605Smrg           subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
69848b8605Smrg            default_llvm = 'yes'
70848b8605Smrg    except:
71848b8605Smrg        pass
72848b8605Smrg
73848b8605Smrg
74848b8605Smrg#######################################################################
75848b8605Smrg# Common options
76848b8605Smrg
77848b8605Smrgdef AddOptions(opts):
78848b8605Smrg	try:
79848b8605Smrg		from SCons.Variables.BoolVariable import BoolVariable as BoolOption
80848b8605Smrg	except ImportError:
81848b8605Smrg		from SCons.Options.BoolOption import BoolOption
82848b8605Smrg	try:
83848b8605Smrg		from SCons.Variables.EnumVariable import EnumVariable as EnumOption
84848b8605Smrg	except ImportError:
85848b8605Smrg		from SCons.Options.EnumOption import EnumOption
86848b8605Smrg	opts.Add(EnumOption('build', 'build type', 'debug',
87848b8605Smrg	                  allowed_values=('debug', 'checked', 'profile', 'release')))
88848b8605Smrg	opts.Add(BoolOption('verbose', 'verbose output', 'no'))
89848b8605Smrg	opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
90848b8605Smrg											 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
91848b8605Smrg	opts.Add(EnumOption('platform', 'target platform', host_platform,
92848b8605Smrg											 allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku', 'linux', 'sunos', 'windows')))
93848b8605Smrg	opts.Add(BoolOption('embedded', 'embedded build', 'no'))
94848b8605Smrg	opts.Add(BoolOption('analyze', 'enable static code analysis where available', 'no'))
95848b8605Smrg	opts.Add('toolchain', 'compiler toolchain', default_toolchain)
96848b8605Smrg	opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
97848b8605Smrg	opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
98848b8605Smrg	opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)', 'no'))
99848b8605Smrg	opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
100848b8605Smrg	opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
101848b8605Smrg	opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
102848b8605Smrg	opts.Add(BoolOption('texture_float', 'enable floating-point textures and renderbuffers', 'no'))
103848b8605Smrg	if host_platform == 'windows':
104848b8605Smrg		opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')
105