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 | |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 11 | import SCons.Script.SConscript |
| 12 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 13 | |
| 14 | ####################################################################### |
| 15 | # Defaults |
| 16 | |
| 17 | _platform_map = { |
| 18 | 'linux2': 'linux', |
José Fonseca | 00b463f | 2009-12-18 22:40:33 +0000 | [diff] [blame] | 19 | 'win32': 'windows', |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | default_platform = sys.platform |
| 23 | default_platform = _platform_map.get(default_platform, default_platform) |
| 24 | |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 25 | # Search sys.argv[] for a "platform=foo" argument since we don't have |
| 26 | # an 'env' variable at this point. |
| 27 | if 'platform' in SCons.Script.ARGUMENTS: |
| 28 | selected_platform = SCons.Script.ARGUMENTS['platform'] |
| 29 | else: |
| 30 | selected_platform = default_platform |
| 31 | |
| 32 | cross_compiling = selected_platform != default_platform |
| 33 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 34 | _machine_map = { |
| 35 | 'x86': 'x86', |
| 36 | 'i386': 'x86', |
| 37 | 'i486': 'x86', |
| 38 | 'i586': 'x86', |
| 39 | 'i686': 'x86', |
Michel Dänzer | 6b69e3c | 2008-10-23 10:28:48 +0200 | [diff] [blame] | 40 | 'ppc' : 'ppc', |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 41 | 'x86_64': 'x86_64', |
| 42 | } |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 43 | |
| 44 | |
| 45 | # find default_machine value |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 46 | if 'PROCESSOR_ARCHITECTURE' in os.environ: |
| 47 | default_machine = os.environ['PROCESSOR_ARCHITECTURE'] |
| 48 | else: |
| 49 | default_machine = _platform.machine() |
| 50 | default_machine = _machine_map.get(default_machine, 'generic') |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 51 | default_toolchain = 'default' |
| 52 | |
| 53 | if selected_platform == 'windows' and cross_compiling: |
| 54 | default_machine = 'x86' |
| 55 | default_toolchain = 'crossmingw' |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 56 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 57 | |
| 58 | # find default_llvm value |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 59 | if 'LLVM' in os.environ: |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 60 | default_llvm = 'yes' |
| 61 | else: |
| 62 | default_llvm = 'no' |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 63 | try: |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 64 | if selected_platform != 'windows' and \ |
| 65 | subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0: |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 66 | default_llvm = 'yes' |
| 67 | except: |
| 68 | pass |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 69 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 70 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 71 | ####################################################################### |
| 72 | # Common options |
| 73 | |
José Fonseca | 13174c1 | 2008-03-03 18:52:37 +0100 | [diff] [blame] | 74 | def AddOptions(opts): |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 75 | try: |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 76 | from SCons.Variables.BoolVariable import BoolVariable as BoolOption |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 77 | except ImportError: |
José Fonseca | 0d0417c | 2009-05-01 16:12:17 +0100 | [diff] [blame] | 78 | from SCons.Options.BoolOption import BoolOption |
| 79 | try: |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 80 | from SCons.Variables.EnumVariable import EnumVariable as EnumOption |
José Fonseca | 0d0417c | 2009-05-01 16:12:17 +0100 | [diff] [blame] | 81 | except ImportError: |
| 82 | from SCons.Options.EnumOption import EnumOption |
José Fonseca | 67450f0 | 2010-09-29 14:08:53 +0100 | [diff] [blame] | 83 | opts.Add(EnumOption('build', 'build type', 'debug', |
| 84 | allowed_values=('debug', 'checked', 'profile', 'release'))) |
José Fonseca | 0f50c4f | 2009-06-02 18:23:12 -0700 | [diff] [blame] | 85 | opts.Add(BoolOption('quiet', 'quiet command lines', 'yes')) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 86 | opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine, |
Michel Dänzer | 6b69e3c | 2008-10-23 10:28:48 +0200 | [diff] [blame] | 87 | allowed_values=('generic', 'ppc', 'x86', 'x86_64'))) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 88 | opts.Add(EnumOption('platform', 'target platform', default_platform, |
Vinson Lee | 4a859cd | 2010-08-11 17:58:06 -0700 | [diff] [blame] | 89 | allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'embedded', 'cygwin', 'sunos5', 'freebsd8'))) |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 90 | opts.Add('toolchain', 'compiler toolchain', default_toolchain) |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 91 | opts.Add(BoolOption('llvm', 'use LLVM', default_llvm)) |
José Fonseca | 67450f0 | 2010-09-29 14:08:53 +0100 | [diff] [blame] | 92 | opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes')) |
| 93 | opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no')) |