scons: Make LLVM a black-white dependency.
[mesa.git] / common.py
1 #######################################################################
2 # Common SCons code
3
4 import os
5 import os.path
6 import subprocess
7 import sys
8 import platform as _platform
9
10
11 #######################################################################
12 # Defaults
13
14 _platform_map = {
15 'linux2': 'linux',
16 'win32': 'windows',
17 }
18
19 default_platform = sys.platform
20 default_platform = _platform_map.get(default_platform, default_platform)
21
22 _machine_map = {
23 'x86': 'x86',
24 'i386': 'x86',
25 'i486': 'x86',
26 'i586': 'x86',
27 'i686': 'x86',
28 'ppc' : 'ppc',
29 'x86_64': 'x86_64',
30 }
31 if 'PROCESSOR_ARCHITECTURE' in os.environ:
32 default_machine = os.environ['PROCESSOR_ARCHITECTURE']
33 else:
34 default_machine = _platform.machine()
35 default_machine = _machine_map.get(default_machine, 'generic')
36
37 if 'LLVM' in os.environ or subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
38 default_llvm = 'yes'
39 else:
40 default_llvm = 'no'
41
42 if default_platform in ('linux', 'freebsd'):
43 default_dri = 'yes'
44 elif default_platform in ('winddk', 'windows', 'wince', 'darwin'):
45 default_dri = 'no'
46 else:
47 default_dri = 'no'
48
49
50 #######################################################################
51 # Common options
52
53 def AddOptions(opts):
54 try:
55 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
56 except ImportError:
57 from SCons.Options.BoolOption import BoolOption
58 try:
59 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
60 except ImportError:
61 from SCons.Options.EnumOption import EnumOption
62 opts.Add(BoolOption('debug', 'debug build', 'no'))
63 opts.Add(BoolOption('profile', 'profile build', 'no'))
64 opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
65 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
66 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
67 opts.Add(EnumOption('platform', 'target platform', default_platform,
68 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded')))
69 opts.Add('toolchain', 'compiler toolchain', 'default')
70 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
71 opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))