Merge remote branch 'origin/master' into nv50-compiler
[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
12 #######################################################################
13 # Defaults
14
15 _platform_map = {
16 'linux2': 'linux',
17 'win32': 'windows',
18 }
19
20 default_platform = sys.platform
21 default_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',
29 'ppc' : 'ppc',
30 'x86_64': 'x86_64',
31 }
32
33
34 # find default_machine value
35 if 'PROCESSOR_ARCHITECTURE' in os.environ:
36 default_machine = os.environ['PROCESSOR_ARCHITECTURE']
37 else:
38 default_machine = _platform.machine()
39 default_machine = _machine_map.get(default_machine, 'generic')
40
41
42 # find default_llvm value
43 if 'LLVM' in os.environ:
44 default_llvm = 'yes'
45 else:
46 # 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
55 default_llvm = 'no'
56 try:
57 if platform != 'windows' and subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
58 default_llvm = 'yes'
59 except:
60 pass
61
62
63 # find default_dri value
64 if default_platform in ('linux', 'freebsd'):
65 default_dri = 'yes'
66 elif default_platform in ('winddk', 'windows', 'wince', 'darwin'):
67 default_dri = 'no'
68 else:
69 default_dri = 'no'
70
71
72 #######################################################################
73 # Common options
74
75 def AddOptions(opts):
76 try:
77 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
78 except ImportError:
79 from SCons.Options.BoolOption import BoolOption
80 try:
81 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
82 except ImportError:
83 from SCons.Options.EnumOption import EnumOption
84 opts.Add(BoolOption('debug', 'debug build', 'yes'))
85 opts.Add(BoolOption('profile', 'profile build', 'no'))
86 opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
87 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
88 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
89 opts.Add(EnumOption('platform', 'target platform', default_platform,
90 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
91 opts.Add('toolchain', 'compiler toolchain', 'default')
92 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
93 opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))