José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 1 | ####################################################################### |
| 2 | # Common SCons code |
| 3 | |
| 4 | import os |
| 5 | import os.path |
Brian Paul | 5c68248 | 2010-05-20 10:25:17 -0600 | [diff] [blame] | 6 | import re |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 7 | import subprocess |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 8 | import sys |
| 9 | import platform as _platform |
| 10 | |
| 11 | |
| 12 | ####################################################################### |
| 13 | # Defaults |
| 14 | |
| 15 | _platform_map = { |
| 16 | 'linux2': 'linux', |
José Fonseca | 00b463f | 2009-12-18 22:40:33 +0000 | [diff] [blame] | 17 | 'win32': 'windows', |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 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', |
Michel Dänzer | 6b69e3c | 2008-10-23 10:28:48 +0200 | [diff] [blame] | 29 | 'ppc' : 'ppc', |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 30 | 'x86_64': 'x86_64', |
| 31 | } |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 32 | |
| 33 | |
| 34 | # find default_machine value |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 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 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 41 | |
| 42 | # find default_llvm value |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 43 | if 'LLVM' in os.environ: |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 44 | default_llvm = 'yes' |
| 45 | else: |
Brian Paul | 5c68248 | 2010-05-20 10:25:17 -0600 | [diff] [blame] | 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 | |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 55 | default_llvm = 'no' |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 56 | try: |
Brian Paul | 5c68248 | 2010-05-20 10:25:17 -0600 | [diff] [blame] | 57 | if platform != 'windows' and subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0: |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 58 | default_llvm = 'yes' |
| 59 | except: |
| 60 | pass |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 61 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 62 | |
| 63 | # find default_dri value |
Vinson Lee | d27d659 | 2009-09-09 08:21:05 -0600 | [diff] [blame] | 64 | if default_platform in ('linux', 'freebsd'): |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 65 | default_dri = 'yes' |
Vinson Lee | d27d659 | 2009-09-09 08:21:05 -0600 | [diff] [blame] | 66 | elif default_platform in ('winddk', 'windows', 'wince', 'darwin'): |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 67 | default_dri = 'no' |
| 68 | else: |
| 69 | default_dri = 'no' |
| 70 | |
| 71 | |
| 72 | ####################################################################### |
| 73 | # Common options |
| 74 | |
José Fonseca | 13174c1 | 2008-03-03 18:52:37 +0100 | [diff] [blame] | 75 | def AddOptions(opts): |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 76 | try: |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 77 | from SCons.Variables.BoolVariable import BoolVariable as BoolOption |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 78 | except ImportError: |
José Fonseca | 0d0417c | 2009-05-01 16:12:17 +0100 | [diff] [blame] | 79 | from SCons.Options.BoolOption import BoolOption |
| 80 | try: |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 81 | from SCons.Variables.EnumVariable import EnumVariable as EnumOption |
José Fonseca | 0d0417c | 2009-05-01 16:12:17 +0100 | [diff] [blame] | 82 | except ImportError: |
| 83 | from SCons.Options.EnumOption import EnumOption |
José Fonseca | 67450f0 | 2010-09-29 14:08:53 +0100 | [diff] [blame^] | 84 | opts.Add(EnumOption('build', 'build type', 'debug', |
| 85 | allowed_values=('debug', 'checked', 'profile', 'release'))) |
José Fonseca | 0f50c4f | 2009-06-02 18:23:12 -0700 | [diff] [blame] | 86 | opts.Add(BoolOption('quiet', 'quiet command lines', 'yes')) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 87 | opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine, |
Michel Dänzer | 6b69e3c | 2008-10-23 10:28:48 +0200 | [diff] [blame] | 88 | allowed_values=('generic', 'ppc', 'x86', 'x86_64'))) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 89 | opts.Add(EnumOption('platform', 'target platform', default_platform, |
Vinson Lee | 4a859cd | 2010-08-11 17:58:06 -0700 | [diff] [blame] | 90 | allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8'))) |
José Fonseca | 711f642 | 2010-03-08 19:58:34 +0000 | [diff] [blame] | 91 | opts.Add('toolchain', 'compiler toolchain', 'default') |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 92 | opts.Add(BoolOption('llvm', 'use LLVM', default_llvm)) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 93 | opts.Add(BoolOption('dri', 'build DRI drivers', default_dri)) |
José Fonseca | 67450f0 | 2010-09-29 14:08:53 +0100 | [diff] [blame^] | 94 | opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes')) |
| 95 | opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no')) |