OSDN Git Service

scons: add comments and whitespace
[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
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 print "sys.argv = " + sys.argv[2]
42
43
44 # find default_llvm value
45 if 'LLVM' in os.environ:
46     default_llvm = 'yes'
47 else:
48     # Search sys.argv[] for a "platform=foo" argument since we don't have
49     # an 'env' variable at this point.
50     platform = default_platform
51     pattern = re.compile("(platform=)(.*)")
52     for arg in sys.argv:
53         m = pattern.match(arg)
54         if m:
55             platform = m.group(2)
56
57     default_llvm = 'no'
58     try:
59         if platform != 'windows' and subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
60             default_llvm = 'yes'
61     except:
62         pass
63
64
65 # find default_dri value
66 if default_platform in ('linux', 'freebsd'):
67         default_dri = 'yes'
68 elif default_platform in ('winddk', 'windows', 'wince', 'darwin'):
69         default_dri = 'no'
70 else:
71         default_dri = 'no'
72
73
74 #######################################################################
75 # Common options
76
77 def AddOptions(opts):
78         try:
79                 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
80         except ImportError:
81                 from SCons.Options.BoolOption import BoolOption
82         try:
83                 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
84         except ImportError:
85                 from SCons.Options.EnumOption import EnumOption
86         opts.Add(BoolOption('debug', 'debug build', 'yes'))
87         opts.Add(BoolOption('profile', 'profile build', 'no'))
88         opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
89         opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
90                                                                                          allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
91         opts.Add(EnumOption('platform', 'target platform', default_platform,
92                                                                                          allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded')))
93         opts.Add('toolchain', 'compiler toolchain', 'default')
94         opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
95         opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))