scons: Try to support building 64bit binaries on 32bit windows.
[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 'x86_64': 'x86_64',
34 }
35
36
37 # find host_machine value
38 if 'PROCESSOR_ARCHITECTURE' in os.environ:
39 host_machine = os.environ['PROCESSOR_ARCHITECTURE']
40 else:
41 host_machine = _platform.machine()
42 host_machine = _machine_map.get(host_machine, 'generic')
43
44 default_machine = host_machine
45 default_toolchain = 'default'
46
47 if target_platform == 'windows' and host_platform != 'windows':
48 default_machine = 'x86'
49 default_toolchain = 'crossmingw'
50
51
52 # find default_llvm value
53 if 'LLVM' in os.environ:
54 default_llvm = 'yes'
55 else:
56 default_llvm = 'no'
57 try:
58 if target_platform != 'windows' and \
59 subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
60 default_llvm = 'yes'
61 except:
62 pass
63
64
65 #######################################################################
66 # Common options
67
68 def AddOptions(opts):
69 try:
70 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
71 except ImportError:
72 from SCons.Options.BoolOption import BoolOption
73 try:
74 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
75 except ImportError:
76 from SCons.Options.EnumOption import EnumOption
77 opts.Add(EnumOption('build', 'build type', 'debug',
78 allowed_values=('debug', 'checked', 'profile', 'release')))
79 opts.Add(BoolOption('quiet', 'quiet command lines', 'yes'))
80 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
81 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
82 opts.Add(EnumOption('platform', 'target platform', host_platform,
83 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8')))
84 opts.Add('toolchain', 'compiler toolchain', default_toolchain)
85 opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
86 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
87 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
88 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
89 opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))