blob: 7a939417e2555b54b0b8881d7318491911618e0e [file] [log] [blame]
José Fonseca94090432008-02-27 17:36:28 +09001#######################################################################
2# Common SCons code
3
4import os
5import os.path
Brian Paul5c682482010-05-20 10:25:17 -06006import re
José Fonsecaea532f02010-04-10 02:41:39 +01007import subprocess
José Fonseca94090432008-02-27 17:36:28 +09008import sys
9import platform as _platform
10
José Fonseca601498a2010-11-01 13:30:22 +000011import SCons.Script.SConscript
12
José Fonseca94090432008-02-27 17:36:28 +090013
14#######################################################################
15# Defaults
16
José Fonsecaae760272011-02-11 16:44:13 +000017host_platform = _platform.system().lower()
Vinson Leeeb178022011-02-24 19:49:37 -080018if host_platform.startswith('cygwin'):
19 host_platform = 'cygwin'
José Fonseca94090432008-02-27 17:36:28 +090020
José Fonseca601498a2010-11-01 13:30:22 +000021# 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:
José Fonsecae1bc68b2011-01-13 20:52:01 +000024 target_platform = SCons.Script.ARGUMENTS['platform']
José Fonseca601498a2010-11-01 13:30:22 +000025else:
José Fonsecae1bc68b2011-01-13 20:52:01 +000026 target_platform = host_platform
José Fonseca601498a2010-11-01 13:30:22 +000027
José Fonseca94090432008-02-27 17:36:28 +090028_machine_map = {
Vinson Lee60f77b22015-03-14 01:45:03 -070029 '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',
José Fonseca94090432008-02-27 17:36:28 +090043}
Brian Paul6ca61892010-05-20 10:26:19 -060044
45
José Fonsecae1bc68b2011-01-13 20:52:01 +000046# find host_machine value
José Fonseca94090432008-02-27 17:36:28 +090047if 'PROCESSOR_ARCHITECTURE' in os.environ:
Vinson Lee60f77b22015-03-14 01:45:03 -070048 host_machine = os.environ['PROCESSOR_ARCHITECTURE']
José Fonseca94090432008-02-27 17:36:28 +090049else:
Vinson Lee60f77b22015-03-14 01:45:03 -070050 host_machine = _platform.machine()
José Fonsecae1bc68b2011-01-13 20:52:01 +000051host_machine = _machine_map.get(host_machine, 'generic')
52
53default_machine = host_machine
José Fonseca601498a2010-11-01 13:30:22 +000054default_toolchain = 'default'
55
José Fonsecaae760272011-02-11 16:44:13 +000056if target_platform == 'windows' and host_platform != 'windows':
José Fonseca601498a2010-11-01 13:30:22 +000057 default_machine = 'x86'
58 default_toolchain = 'crossmingw'
José Fonseca94090432008-02-27 17:36:28 +090059
Brian Paul6ca61892010-05-20 10:26:19 -060060
61# find default_llvm value
José Fonsecacd4e5872010-04-13 19:40:48 +090062if 'LLVM' in os.environ:
José Fonsecaea532f02010-04-10 02:41:39 +010063 default_llvm = 'yes'
64else:
65 default_llvm = 'no'
José Fonsecacd4e5872010-04-13 19:40:48 +090066 try:
José Fonsecae1bc68b2011-01-13 20:52:01 +000067 if target_platform != 'windows' and \
Vinson Lee60f77b22015-03-14 01:45:03 -070068 subprocess.call(['llvm-config', '--version'],
69 stdout=subprocess.PIPE) == 0:
José Fonsecacd4e5872010-04-13 19:40:48 +090070 default_llvm = 'yes'
71 except:
72 pass
José Fonsecaea532f02010-04-10 02:41:39 +010073
Brian Paul6ca61892010-05-20 10:26:19 -060074
José Fonseca94090432008-02-27 17:36:28 +090075#######################################################################
76# Common options
77
José Fonseca13174c12008-03-03 18:52:37 +010078def AddOptions(opts):
Vinson Lee60f77b22015-03-14 01:45:03 -070079 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')))
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('toolchain', 'compiler toolchain', default_toolchain)
101 opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support',
102 'no'))
103 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
104 opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)',
105 'no'))
106 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
107 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
108 opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
109 opts.Add(BoolOption('texture_float',
110 'enable floating-point textures and renderbuffers',
111 'no'))
112 if host_platform == 'windows':
113 opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')