blob: f0b1ccc2c1f07ef10a65839ef486c692e82bd889 [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 = {
29 'x86': 'x86',
30 'i386': 'x86',
31 'i486': 'x86',
32 'i586': 'x86',
33 'i686': 'x86',
Alexander von Gluck IV5481b5a2012-01-17 15:46:01 +000034 'BePC': 'x86',
35 'Intel': 'x86',
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020036 'ppc' : 'ppc',
Alexander von Gluck IV5481b5a2012-01-17 15:46:01 +000037 'BeBox': 'ppc',
38 'BeMac': 'ppc',
José Fonseca33d8ff92011-02-15 17:31:31 +000039 'AMD64': 'x86_64',
José Fonseca94090432008-02-27 17:36:28 +090040 'x86_64': 'x86_64',
Alexander von Gluck IV5481b5a2012-01-17 15:46:01 +000041 '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:
José Fonsecae1bc68b2011-01-13 20:52:01 +000048 host_machine = os.environ['PROCESSOR_ARCHITECTURE']
José Fonseca94090432008-02-27 17:36:28 +090049else:
José Fonsecae1bc68b2011-01-13 20:52:01 +000050 host_machine = _platform.machine()
51host_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 \
José Fonseca601498a2010-11-01 13:30:22 +000068 subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
José Fonsecacd4e5872010-04-13 19:40:48 +090069 default_llvm = 'yes'
70 except:
71 pass
José Fonsecaea532f02010-04-10 02:41:39 +010072
Brian Paul6ca61892010-05-20 10:26:19 -060073
José Fonseca94090432008-02-27 17:36:28 +090074#######################################################################
75# Common options
76
José Fonseca13174c12008-03-03 18:52:37 +010077def AddOptions(opts):
José Fonsecac9acd432008-05-01 00:58:04 +090078 try:
José Fonsecac9acd432008-05-01 00:58:04 +090079 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
José Fonsecac9acd432008-05-01 00:58:04 +090080 except ImportError:
José Fonseca0d0417c2009-05-01 16:12:17 +010081 from SCons.Options.BoolOption import BoolOption
82 try:
José Fonsecac9acd432008-05-01 00:58:04 +090083 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
José Fonseca0d0417c2009-05-01 16:12:17 +010084 except ImportError:
85 from SCons.Options.EnumOption import EnumOption
José Fonseca67450f02010-09-29 14:08:53 +010086 opts.Add(EnumOption('build', 'build type', 'debug',
87 allowed_values=('debug', 'checked', 'profile', 'release')))
José Fonsecac7bd0fa2011-06-17 18:42:39 +010088 opts.Add(BoolOption('verbose', 'verbose output', 'no'))
José Fonseca94090432008-02-27 17:36:28 +090089 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020090 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
José Fonsecae1bc68b2011-01-13 20:52:01 +000091 opts.Add(EnumOption('platform', 'target platform', host_platform,
Alexander von Gluck IV64ae2092012-01-16 12:42:05 +000092 allowed_values=('linux', 'windows', 'darwin', 'cygwin', 'sunos', 'freebsd8', 'haiku')))
José Fonseca41750102011-06-17 14:48:28 +010093 opts.Add(BoolOption('embedded', 'embedded build', 'no'))
José Fonseca601498a2010-11-01 13:30:22 +000094 opts.Add('toolchain', 'compiler toolchain', default_toolchain)
Chia-I Wubb770af2011-01-14 17:50:29 +080095 opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
José Fonsecaea532f02010-04-10 02:41:39 +010096 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
Andreas Fängere411cd72011-08-10 08:07:29 +000097 opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)', 'no'))
José Fonseca67450f02010-09-29 14:08:53 +010098 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
99 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
José Fonseca2699fce2011-06-17 20:12:18 +0100100 opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
José Fonsecac9be4352011-06-17 20:07:12 +0100101 if host_platform == 'windows':
102 opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))