Merge remote branch 'origin/master' into pipe-video
[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 host_platform = _platform.system().lower()
18
19 # Search sys.argv[] for a "platform=foo" argument since we don't have
20 # an 'env' variable at this point.
21 if 'platform' in SCons.Script.ARGUMENTS:
22 target_platform = SCons.Script.ARGUMENTS['platform']
23 else:
24 target_platform = host_platform
25
26 _machine_map = {
27 'x86': 'x86',
28 'i386': 'x86',
29 'i486': 'x86',
30 'i586': 'x86',
31 'i686': 'x86',
32 'ppc' : 'ppc',
33 'AMD64': 'x86_64',
34 'x86_64': 'x86_64',
35 }
36
37
38 # find host_machine value
39 if 'PROCESSOR_ARCHITECTURE' in os.environ:
40 host_machine = os.environ['PROCESSOR_ARCHITECTURE']
41 else:
42 host_machine = _platform.machine()
43 host_machine = _machine_map.get(host_machine, 'generic')
44
45 default_machine = host_machine
46 default_toolchain = 'default'
47
48 if target_platform == 'windows' and host_platform != 'windows':
49 default_machine = 'x86'
50 default_toolchain = 'crossmingw'
51
52
53 # find default_llvm value
54 if 'LLVM' in os.environ:
55 default_llvm = 'yes'
56 else:
57 default_llvm = 'no'
58 try:
59 if target_platform != 'windows' and \
60 subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
61 default_llvm = 'yes'
62 except:
63 pass
64
65
66 #######################################################################
67 # Common options
68
69 def AddOptions(opts):
70 try:
71 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
72 except ImportError:
73 from SCons.Options.BoolOption import BoolOption
74 try:
75 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
76 except ImportError:
77 from SCons.Options.EnumOption import EnumOption
78 opts.Add(EnumOption('build', 'build type', 'debug',
79 allowed_values=('debug', 'checked', 'profile', 'release')))
80 opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
81 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
82 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
83 opts.Add(EnumOption('platform', 'target platform', host_platform,
84 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin_nt-5.1', 'cygwin_nt-6.1', 'sunos5', 'freebsd8')))
85 opts.Add('toolchain', 'compiler toolchain', default_toolchain)
86 opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
87 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
88 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
89 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
90 opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))