blob: b7749c925dfc3db0d7734cdd0462edc5016e15bd [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
17_platform_map = {
18 'linux2': 'linux',
José Fonseca00b463f2009-12-18 22:40:33 +000019 'win32': 'windows',
José Fonseca94090432008-02-27 17:36:28 +090020}
21
22default_platform = sys.platform
23default_platform = _platform_map.get(default_platform, default_platform)
24
José Fonseca601498a2010-11-01 13:30:22 +000025# Search sys.argv[] for a "platform=foo" argument since we don't have
26# an 'env' variable at this point.
27if 'platform' in SCons.Script.ARGUMENTS:
28 selected_platform = SCons.Script.ARGUMENTS['platform']
29else:
30 selected_platform = default_platform
31
32cross_compiling = selected_platform != default_platform
33
José Fonseca94090432008-02-27 17:36:28 +090034_machine_map = {
35 'x86': 'x86',
36 'i386': 'x86',
37 'i486': 'x86',
38 'i586': 'x86',
39 'i686': 'x86',
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020040 'ppc' : 'ppc',
José Fonseca94090432008-02-27 17:36:28 +090041 'x86_64': 'x86_64',
42}
Brian Paul6ca61892010-05-20 10:26:19 -060043
44
45# find default_machine value
José Fonseca94090432008-02-27 17:36:28 +090046if 'PROCESSOR_ARCHITECTURE' in os.environ:
47 default_machine = os.environ['PROCESSOR_ARCHITECTURE']
48else:
49 default_machine = _platform.machine()
50default_machine = _machine_map.get(default_machine, 'generic')
José Fonseca601498a2010-11-01 13:30:22 +000051default_toolchain = 'default'
52
53if selected_platform == 'windows' and cross_compiling:
54 default_machine = 'x86'
55 default_toolchain = 'crossmingw'
José Fonseca94090432008-02-27 17:36:28 +090056
Brian Paul6ca61892010-05-20 10:26:19 -060057
58# find default_llvm value
José Fonsecacd4e5872010-04-13 19:40:48 +090059if 'LLVM' in os.environ:
José Fonsecaea532f02010-04-10 02:41:39 +010060 default_llvm = 'yes'
61else:
62 default_llvm = 'no'
José Fonsecacd4e5872010-04-13 19:40:48 +090063 try:
José Fonseca601498a2010-11-01 13:30:22 +000064 if selected_platform != 'windows' and \
65 subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
José Fonsecacd4e5872010-04-13 19:40:48 +090066 default_llvm = 'yes'
67 except:
68 pass
José Fonsecaea532f02010-04-10 02:41:39 +010069
Brian Paul6ca61892010-05-20 10:26:19 -060070
José Fonseca94090432008-02-27 17:36:28 +090071#######################################################################
72# Common options
73
José Fonseca13174c12008-03-03 18:52:37 +010074def AddOptions(opts):
José Fonsecac9acd432008-05-01 00:58:04 +090075 try:
José Fonsecac9acd432008-05-01 00:58:04 +090076 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
José Fonsecac9acd432008-05-01 00:58:04 +090077 except ImportError:
José Fonseca0d0417c2009-05-01 16:12:17 +010078 from SCons.Options.BoolOption import BoolOption
79 try:
José Fonsecac9acd432008-05-01 00:58:04 +090080 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
José Fonseca0d0417c2009-05-01 16:12:17 +010081 except ImportError:
82 from SCons.Options.EnumOption import EnumOption
José Fonseca67450f02010-09-29 14:08:53 +010083 opts.Add(EnumOption('build', 'build type', 'debug',
84 allowed_values=('debug', 'checked', 'profile', 'release')))
José Fonseca0f50c4f2009-06-02 18:23:12 -070085 opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
José Fonseca94090432008-02-27 17:36:28 +090086 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020087 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
José Fonseca94090432008-02-27 17:36:28 +090088 opts.Add(EnumOption('platform', 'target platform', default_platform,
Vinson Lee4a859cd2010-08-11 17:58:06 -070089 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
José Fonseca601498a2010-11-01 13:30:22 +000090 opts.Add('toolchain', 'compiler toolchain', default_toolchain)
José Fonsecaea532f02010-04-10 02:41:39 +010091 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
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'))