OSDN Git Service

scons: Move MSVS_VERSION option to common module.
[android-x86/external-mesa.git] / common.py
1 #######################################################################
2 # Common SCons code
3
4 import os
5 import os.path
6 import re
7 import subprocess
8 import sys
9 import platform as _platform
10
11 import SCons.Script.SConscript
12
13
14 #######################################################################
15 # Defaults
16
17 _platform_map = {
18         'linux2': 'linux',
19         'win32': 'windows',
20 }
21
22 default_platform = sys.platform
23 default_platform = _platform_map.get(default_platform, default_platform)
24
25 # Search sys.argv[] for a "platform=foo" argument since we don't have
26 # an 'env' variable at this point.
27 if 'platform' in SCons.Script.ARGUMENTS:
28     selected_platform = SCons.Script.ARGUMENTS['platform']
29 else:
30     selected_platform = default_platform
31
32 cross_compiling = selected_platform != default_platform
33
34 _machine_map = {
35         'x86': 'x86',
36         'i386': 'x86',
37         'i486': 'x86',
38         'i586': 'x86',
39         'i686': 'x86',
40         'ppc' : 'ppc',
41         'x86_64': 'x86_64',
42 }
43
44
45 # find default_machine value
46 if 'PROCESSOR_ARCHITECTURE' in os.environ:
47         default_machine = os.environ['PROCESSOR_ARCHITECTURE']
48 else:
49         default_machine = _platform.machine()
50 default_machine = _machine_map.get(default_machine, 'generic')
51 default_toolchain = 'default'
52
53 if selected_platform == 'windows' and cross_compiling:
54     default_machine = 'x86'
55     default_toolchain = 'crossmingw'
56
57
58 # find default_llvm value
59 if 'LLVM' in os.environ:
60     default_llvm = 'yes'
61 else:
62     default_llvm = 'no'
63     try:
64         if selected_platform != 'windows' and \
65            subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
66             default_llvm = 'yes'
67     except:
68         pass
69
70
71 #######################################################################
72 # Common options
73
74 def AddOptions(opts):
75         try:
76                 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
77         except ImportError:
78                 from SCons.Options.BoolOption import BoolOption
79         try:
80                 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
81         except ImportError:
82                 from SCons.Options.EnumOption import EnumOption
83         opts.Add(EnumOption('build', 'build type', 'debug',
84                           allowed_values=('debug', 'checked', 'profile', 'release')))
85         opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
86         opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
87                                                                                          allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
88         opts.Add(EnumOption('platform', 'target platform', default_platform,
89                                                                                          allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
90         opts.Add('toolchain', 'compiler toolchain', default_toolchain)
91         opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
92         opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
93         opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
94         opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))