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 | |
José Fonseca | ae76027 | 2011-02-11 16:44:13 +0000 | [diff] [blame] | 17 | host_platform = _platform.system().lower() |
Vinson Lee | eb17802 | 2011-02-24 19:49:37 -0800 | [diff] [blame] | 18 | if host_platform.startswith('cygwin'): |
| 19 | host_platform = 'cygwin' |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 20 | |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 21 | # Search sys.argv[] for a "platform=foo" argument since we don't have |
| 22 | # an 'env' variable at this point. |
| 23 | if 'platform' in SCons.Script.ARGUMENTS: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 24 | target_platform = SCons.Script.ARGUMENTS['platform'] |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 25 | else: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 26 | target_platform = host_platform |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 27 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 28 | _machine_map = { |
| 29 | 'x86': 'x86', |
| 30 | 'i386': 'x86', |
| 31 | 'i486': 'x86', |
| 32 | 'i586': 'x86', |
| 33 | 'i686': 'x86', |
Alexander von Gluck IV | 5481b5a | 2012-01-17 15:46:01 +0000 | [diff] [blame] | 34 | 'BePC': 'x86', |
| 35 | 'Intel': 'x86', |
Michel Dänzer | 6b69e3c | 2008-10-23 10:28:48 +0200 | [diff] [blame] | 36 | 'ppc' : 'ppc', |
Alexander von Gluck IV | 5481b5a | 2012-01-17 15:46:01 +0000 | [diff] [blame] | 37 | 'BeBox': 'ppc', |
| 38 | 'BeMac': 'ppc', |
José Fonseca | 33d8ff9 | 2011-02-15 17:31:31 +0000 | [diff] [blame] | 39 | 'AMD64': 'x86_64', |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 40 | 'x86_64': 'x86_64', |
Alexander von Gluck IV | 5481b5a | 2012-01-17 15:46:01 +0000 | [diff] [blame] | 41 | 'sparc': 'sparc', |
| 42 | 'sun4u': 'sparc', |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 43 | } |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 44 | |
| 45 | |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 46 | # find host_machine value |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 47 | if 'PROCESSOR_ARCHITECTURE' in os.environ: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 48 | host_machine = os.environ['PROCESSOR_ARCHITECTURE'] |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 49 | else: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 50 | host_machine = _platform.machine() |
| 51 | host_machine = _machine_map.get(host_machine, 'generic') |
| 52 | |
| 53 | default_machine = host_machine |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 54 | default_toolchain = 'default' |
| 55 | |
José Fonseca | ae76027 | 2011-02-11 16:44:13 +0000 | [diff] [blame] | 56 | if target_platform == 'windows' and host_platform != 'windows': |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 57 | default_machine = 'x86' |
| 58 | default_toolchain = 'crossmingw' |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 59 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 60 | |
| 61 | # find default_llvm value |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 62 | if 'LLVM' in os.environ: |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 63 | default_llvm = 'yes' |
| 64 | else: |
| 65 | default_llvm = 'no' |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 66 | try: |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 67 | if target_platform != 'windows' and \ |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 68 | subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0: |
José Fonseca | cd4e587 | 2010-04-13 19:40:48 +0900 | [diff] [blame] | 69 | default_llvm = 'yes' |
| 70 | except: |
| 71 | pass |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 72 | |
Brian Paul | 6ca6189 | 2010-05-20 10:26:19 -0600 | [diff] [blame] | 73 | |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 74 | ####################################################################### |
| 75 | # Common options |
| 76 | |
José Fonseca | 13174c1 | 2008-03-03 18:52:37 +0100 | [diff] [blame] | 77 | def AddOptions(opts): |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 78 | try: |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 79 | from SCons.Variables.BoolVariable import BoolVariable as BoolOption |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 80 | except ImportError: |
José Fonseca | 0d0417c | 2009-05-01 16:12:17 +0100 | [diff] [blame] | 81 | from SCons.Options.BoolOption import BoolOption |
| 82 | try: |
José Fonseca | c9acd43 | 2008-05-01 00:58:04 +0900 | [diff] [blame] | 83 | from SCons.Variables.EnumVariable import EnumVariable as EnumOption |
José Fonseca | 0d0417c | 2009-05-01 16:12:17 +0100 | [diff] [blame] | 84 | except ImportError: |
| 85 | from SCons.Options.EnumOption import EnumOption |
José Fonseca | 67450f0 | 2010-09-29 14:08:53 +0100 | [diff] [blame] | 86 | opts.Add(EnumOption('build', 'build type', 'debug', |
| 87 | allowed_values=('debug', 'checked', 'profile', 'release'))) |
José Fonseca | c7bd0fa | 2011-06-17 18:42:39 +0100 | [diff] [blame] | 88 | opts.Add(BoolOption('verbose', 'verbose output', 'no')) |
José Fonseca | 9409043 | 2008-02-27 17:36:28 +0900 | [diff] [blame] | 89 | opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine, |
Michel Dänzer | 6b69e3c | 2008-10-23 10:28:48 +0200 | [diff] [blame] | 90 | allowed_values=('generic', 'ppc', 'x86', 'x86_64'))) |
José Fonseca | e1bc68b | 2011-01-13 20:52:01 +0000 | [diff] [blame] | 91 | opts.Add(EnumOption('platform', 'target platform', host_platform, |
Vinson Lee | 5cf6932 | 2012-05-23 17:26:20 -0700 | [diff] [blame] | 92 | allowed_values=('cygwin', 'darwin', 'freebsd', 'haiku', 'linux', 'sunos', 'windows'))) |
José Fonseca | 4175010 | 2011-06-17 14:48:28 +0100 | [diff] [blame] | 93 | opts.Add(BoolOption('embedded', 'embedded build', 'no')) |
José Fonseca | d3c0e23 | 2014-04-14 14:31:02 +0100 | [diff] [blame] | 94 | opts.Add(BoolOption('analyze', 'enable static code analysis where available', 'no')) |
José Fonseca | 601498a | 2010-11-01 13:30:22 +0000 | [diff] [blame] | 95 | opts.Add('toolchain', 'compiler toolchain', default_toolchain) |
Chia-I Wu | bb770af | 2011-01-14 17:50:29 +0800 | [diff] [blame] | 96 | opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no')) |
José Fonseca | ea532f0 | 2010-04-10 02:41:39 +0100 | [diff] [blame] | 97 | opts.Add(BoolOption('llvm', 'use LLVM', default_llvm)) |
Andreas Fänger | e411cd7 | 2011-08-10 08:07:29 +0000 | [diff] [blame] | 98 | opts.Add(BoolOption('openmp', 'EXPERIMENTAL: compile with openmp (swrast)', 'no')) |
José Fonseca | 67450f0 | 2010-09-29 14:08:53 +0100 | [diff] [blame] | 99 | opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes')) |
| 100 | opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no')) |
José Fonseca | 2699fce | 2011-06-17 20:12:18 +0100 | [diff] [blame] | 101 | opts.Add(BoolOption('quiet', 'DEPRECATED: profile build', 'yes')) |
Vinson Lee | 3d6892c | 2012-08-12 00:02:32 -0700 | [diff] [blame] | 102 | opts.Add(BoolOption('texture_float', 'enable floating-point textures and renderbuffers', 'no')) |
José Fonseca | c9be435 | 2011-06-17 20:07:12 +0100 | [diff] [blame] | 103 | if host_platform == 'windows': |
José Fonseca | 0582800 | 2014-05-01 15:49:36 +0100 | [diff] [blame] | 104 | opts.Add('MSVC_VERSION', 'Microsoft Visual C/C++ version') |