egl: drop unused _EGLDriver from WaitClient()
[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 if host_platform.startswith('cygwin'):
19 host_platform = 'cygwin'
20 # MSYS2 default platform selection.
21 if host_platform.startswith('mingw'):
22 host_platform = 'windows'
23
24 # Search sys.argv[] for a "platform=foo" argument since we don't have
25 # an 'env' variable at this point.
26 if 'platform' in SCons.Script.ARGUMENTS:
27 target_platform = SCons.Script.ARGUMENTS['platform']
28 else:
29 target_platform = host_platform
30
31 _machine_map = {
32 'x86': 'x86',
33 'i386': 'x86',
34 'i486': 'x86',
35 'i586': 'x86',
36 'i686': 'x86',
37 'BePC': 'x86',
38 'Intel': 'x86',
39 'ppc': 'ppc',
40 'BeBox': 'ppc',
41 'BeMac': 'ppc',
42 'AMD64': 'x86_64',
43 'x86_64': 'x86_64',
44 'sparc': 'sparc',
45 'sun4u': 'sparc',
46 }
47
48
49 # find host_machine value
50 if 'PROCESSOR_ARCHITECTURE' in os.environ:
51 host_machine = os.environ['PROCESSOR_ARCHITECTURE']
52 else:
53 host_machine = _platform.machine()
54 host_machine = _machine_map.get(host_machine, 'generic')
55 # MSYS2 default machine selection.
56 if _platform.system().lower().startswith('mingw') and 'MSYSTEM' in os.environ:
57 if os.environ['MSYSTEM'] == 'MINGW32':
58 host_machine = 'x86'
59 if os.environ['MSYSTEM'] == 'MINGW64':
60 host_machine = 'x86_64'
61
62 default_machine = host_machine
63 default_toolchain = 'default'
64 # MSYS2 default toolchain selection.
65 if _platform.system().lower().startswith('mingw'):
66 default_toolchain = 'mingw'
67
68 if target_platform == 'windows' and host_platform != 'windows':
69 default_machine = 'x86'
70 default_toolchain = 'crossmingw'
71
72
73 # find default_llvm value
74 if 'LLVM' in os.environ or 'LLVM_CONFIG' in os.environ:
75 default_llvm = 'yes'
76 else:
77 default_llvm = 'no'
78 try:
79 if target_platform != 'windows' and \
80 subprocess.call(['llvm-config', '--version'],
81 stdout=subprocess.PIPE) == 0:
82 default_llvm = 'yes'
83 except:
84 pass
85
86
87 #######################################################################
88 # Common options
89
90 def AddOptions(opts):
91 try:
92 from SCons.Variables.BoolVariable import BoolVariable as BoolOption
93 except ImportError:
94 from SCons.Options.BoolOption import BoolOption
95 try:
96 from SCons.Variables.EnumVariable import EnumVariable as EnumOption
97 except ImportError:
98 from SCons.Options.EnumOption import EnumOption
99 opts.Add(EnumOption('build', 'build type', 'debug',
100 allowed_values=('debug', 'checked', 'profile',
101 'release')))
102 opts.Add(BoolOption('verbose', 'verbose output', 'no'))
103 opts.Add(EnumOption('machine', 'use machine-specific assembly code',
104 default_machine,
105 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
106 opts.Add(EnumOption('platform', 'target platform', host_platform,
107 allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku',
108 'linux', 'sunos', 'windows')))
109 opts.Add(BoolOption('embedded', 'embedded build', 'no'))
110 opts.Add(BoolOption('analyze',
111 'enable static code analysis where available', 'no'))
112 opts.Add(BoolOption('asan', 'enable Address Sanitizer', 'no'))
113 opts.Add('toolchain', 'compiler toolchain', default_toolchain)
114 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
115 opts.Add(BoolOption('force_scons', 'Force enable scons on deprecated platforms', 'false'))
116 opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)',
117 'no'))
118 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
119 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
120 opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes'))
121 opts.Add(BoolOption('swr', 'Build OpenSWR', 'no'))
122 if host_platform == 'windows':
123 opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version')
124 opts.Add('MSVC_USE_SCRIPT', 'Microsoft Visual C/C++ vcvarsall script', True)