blob: 13e8dc83e978bbcd2df2b3b92d38d977be7ecd51 [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
11
12#######################################################################
13# Defaults
14
15_platform_map = {
16 'linux2': 'linux',
José Fonseca00b463f2009-12-18 22:40:33 +000017 'win32': 'windows',
José Fonseca94090432008-02-27 17:36:28 +090018}
19
20default_platform = sys.platform
21default_platform = _platform_map.get(default_platform, default_platform)
22
23_machine_map = {
24 'x86': 'x86',
25 'i386': 'x86',
26 'i486': 'x86',
27 'i586': 'x86',
28 'i686': 'x86',
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020029 'ppc' : 'ppc',
José Fonseca94090432008-02-27 17:36:28 +090030 'x86_64': 'x86_64',
31}
Brian Paul6ca61892010-05-20 10:26:19 -060032
33
34# find default_machine value
José Fonseca94090432008-02-27 17:36:28 +090035if 'PROCESSOR_ARCHITECTURE' in os.environ:
36 default_machine = os.environ['PROCESSOR_ARCHITECTURE']
37else:
38 default_machine = _platform.machine()
39default_machine = _machine_map.get(default_machine, 'generic')
40
Brian Paul6ca61892010-05-20 10:26:19 -060041
42# find default_llvm value
José Fonsecacd4e5872010-04-13 19:40:48 +090043if 'LLVM' in os.environ:
José Fonsecaea532f02010-04-10 02:41:39 +010044 default_llvm = 'yes'
45else:
Brian Paul5c682482010-05-20 10:25:17 -060046 # Search sys.argv[] for a "platform=foo" argument since we don't have
47 # an 'env' variable at this point.
48 platform = default_platform
49 pattern = re.compile("(platform=)(.*)")
50 for arg in sys.argv:
51 m = pattern.match(arg)
52 if m:
53 platform = m.group(2)
54
José Fonsecaea532f02010-04-10 02:41:39 +010055 default_llvm = 'no'
José Fonsecacd4e5872010-04-13 19:40:48 +090056 try:
Brian Paul5c682482010-05-20 10:25:17 -060057 if platform != 'windows' and subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
José Fonsecacd4e5872010-04-13 19:40:48 +090058 default_llvm = 'yes'
59 except:
60 pass
José Fonsecaea532f02010-04-10 02:41:39 +010061
Brian Paul6ca61892010-05-20 10:26:19 -060062
63# find default_dri value
Vinson Leed27d6592009-09-09 08:21:05 -060064if default_platform in ('linux', 'freebsd'):
José Fonseca94090432008-02-27 17:36:28 +090065 default_dri = 'yes'
Vinson Leed27d6592009-09-09 08:21:05 -060066elif default_platform in ('winddk', 'windows', 'wince', 'darwin'):
José Fonseca94090432008-02-27 17:36:28 +090067 default_dri = 'no'
68else:
69 default_dri = 'no'
70
71
72#######################################################################
73# Common options
74
José Fonseca13174c12008-03-03 18:52:37 +010075def AddOptions(opts):
José Fonsecac9acd432008-05-01 00:58:04 +090076 try:
José Fonsecac9acd432008-05-01 00:58:04 +090077 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
José Fonsecac9acd432008-05-01 00:58:04 +090078 except ImportError:
José Fonseca0d0417c2009-05-01 16:12:17 +010079 from SCons.Options.BoolOption import BoolOption
80 try:
José Fonsecac9acd432008-05-01 00:58:04 +090081 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
José Fonseca0d0417c2009-05-01 16:12:17 +010082 except ImportError:
83 from SCons.Options.EnumOption import EnumOption
José Fonseca67450f02010-09-29 14:08:53 +010084 opts.Add(EnumOption('build', 'build type', 'debug',
85 allowed_values=('debug', 'checked', 'profile', 'release')))
José Fonseca0f50c4f2009-06-02 18:23:12 -070086 opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
José Fonseca94090432008-02-27 17:36:28 +090087 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
Michel Dänzer6b69e3c2008-10-23 10:28:48 +020088 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
José Fonseca94090432008-02-27 17:36:28 +090089 opts.Add(EnumOption('platform', 'target platform', default_platform,
Vinson Lee4a859cd2010-08-11 17:58:06 -070090 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
José Fonseca711f6422010-03-08 19:58:34 +000091 opts.Add('toolchain', 'compiler toolchain', 'default')
José Fonsecaea532f02010-04-10 02:41:39 +010092 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
José Fonseca94090432008-02-27 17:36:28 +090093 opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
José Fonseca67450f02010-09-29 14:08:53 +010094 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
95 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))