blob: cfee1b5dc2e58c03a2f5857586747b21ce4b31f9 [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',
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020034 'ppc' : 'ppc',
José Fonseca33d8ff92011-02-15 17:31:31 +000035 'AMD64': 'x86_64',
José Fonseca94090432008-02-27 17:36:28 +090036 'x86_64': 'x86_64',
37}
Brian Paul6ca61892010-05-20 10:26:19 -060038
39
José Fonsecae1bc68b2011-01-13 20:52:01 +000040# find host_machine value
José Fonseca94090432008-02-27 17:36:28 +090041if 'PROCESSOR_ARCHITECTURE' in os.environ:
José Fonsecae1bc68b2011-01-13 20:52:01 +000042 host_machine = os.environ['PROCESSOR_ARCHITECTURE']
José Fonseca94090432008-02-27 17:36:28 +090043else:
José Fonsecae1bc68b2011-01-13 20:52:01 +000044 host_machine = _platform.machine()
45host_machine = _machine_map.get(host_machine, 'generic')
46
47default_machine = host_machine
José Fonseca601498a2010-11-01 13:30:22 +000048default_toolchain = 'default'
49
José Fonsecaae760272011-02-11 16:44:13 +000050if target_platform == 'windows' and host_platform != 'windows':
José Fonseca601498a2010-11-01 13:30:22 +000051 default_machine = 'x86'
52 default_toolchain = 'crossmingw'
José Fonseca94090432008-02-27 17:36:28 +090053
Brian Paul6ca61892010-05-20 10:26:19 -060054
55# find default_llvm value
José Fonsecacd4e5872010-04-13 19:40:48 +090056if 'LLVM' in os.environ:
José Fonsecaea532f02010-04-10 02:41:39 +010057 default_llvm = 'yes'
58else:
59 default_llvm = 'no'
José Fonsecacd4e5872010-04-13 19:40:48 +090060 try:
José Fonsecae1bc68b2011-01-13 20:52:01 +000061 if target_platform != 'windows' and \
José Fonseca601498a2010-11-01 13:30:22 +000062 subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
José Fonsecacd4e5872010-04-13 19:40:48 +090063 default_llvm = 'yes'
64 except:
65 pass
José Fonsecaea532f02010-04-10 02:41:39 +010066
Brian Paul6ca61892010-05-20 10:26:19 -060067
José Fonseca94090432008-02-27 17:36:28 +090068#######################################################################
69# Common options
70
José Fonseca13174c12008-03-03 18:52:37 +010071def AddOptions(opts):
José Fonsecac9acd432008-05-01 00:58:04 +090072 try:
José Fonsecac9acd432008-05-01 00:58:04 +090073 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
José Fonsecac9acd432008-05-01 00:58:04 +090074 except ImportError:
José Fonseca0d0417c2009-05-01 16:12:17 +010075 from SCons.Options.BoolOption import BoolOption
76 try:
José Fonsecac9acd432008-05-01 00:58:04 +090077 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
José Fonseca0d0417c2009-05-01 16:12:17 +010078 except ImportError:
79 from SCons.Options.EnumOption import EnumOption
José Fonseca67450f02010-09-29 14:08:53 +010080 opts.Add(EnumOption('build', 'build type', 'debug',
81 allowed_values=('debug', 'checked', 'profile', 'release')))
José Fonsecac7bd0fa2011-06-17 18:42:39 +010082 opts.Add(BoolOption('verbose', 'verbose output', 'no'))
José Fonseca94090432008-02-27 17:36:28 +090083 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020084 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
José Fonsecae1bc68b2011-01-13 20:52:01 +000085 opts.Add(EnumOption('platform', 'target platform', host_platform,
José Fonseca41750102011-06-17 14:48:28 +010086 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'cygwin', 'sunos', 'freebsd8')))
87 opts.Add(BoolOption('embedded', 'embedded build', 'no'))
José Fonseca601498a2010-11-01 13:30:22 +000088 opts.Add('toolchain', 'compiler toolchain', default_toolchain)
Chia-I Wubb770af2011-01-14 17:50:29 +080089 opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
José Fonsecaea532f02010-04-10 02:41:39 +010090 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
Andreas Fängere411cd72011-08-10 08:07:29 +000091 opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)', 'no'))
José Fonseca67450f02010-09-29 14:08:53 +010092 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
93 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
José Fonseca2699fce2011-06-17 20:12:18 +010094 opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
José Fonsecac9be4352011-06-17 20:07:12 +010095 if host_platform == 'windows':
96 opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))