common.py revision 41750107496858a047afa8d81d20fe903f285a78
1####################################################################### 2# Common SCons code 3 4import os 5import os.path 6import re 7import subprocess 8import sys 9import platform as _platform 10 11import SCons.Script.SConscript 12 13 14####################################################################### 15# Defaults 16 17host_platform = _platform.system().lower() 18if host_platform.startswith('cygwin'): 19 host_platform = 'cygwin' 20 21# Search sys.argv[] for a "platform=foo" argument since we don't have 22# an 'env' variable at this point. 23if 'platform' in SCons.Script.ARGUMENTS: 24 target_platform = SCons.Script.ARGUMENTS['platform'] 25else: 26 target_platform = host_platform 27 28_machine_map = { 29 'x86': 'x86', 30 'i386': 'x86', 31 'i486': 'x86', 32 'i586': 'x86', 33 'i686': 'x86', 34 'ppc' : 'ppc', 35 'AMD64': 'x86_64', 36 'x86_64': 'x86_64', 37} 38 39 40# find host_machine value 41if 'PROCESSOR_ARCHITECTURE' in os.environ: 42 host_machine = os.environ['PROCESSOR_ARCHITECTURE'] 43else: 44 host_machine = _platform.machine() 45host_machine = _machine_map.get(host_machine, 'generic') 46 47default_machine = host_machine 48default_toolchain = 'default' 49 50if target_platform == 'windows' and host_platform != 'windows': 51 default_machine = 'x86' 52 default_toolchain = 'crossmingw' 53 54 55# find default_llvm value 56if 'LLVM' in os.environ: 57 default_llvm = 'yes' 58else: 59 default_llvm = 'no' 60 try: 61 if target_platform != 'windows' and \ 62 subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0: 63 default_llvm = 'yes' 64 except: 65 pass 66 67 68####################################################################### 69# Common options 70 71def AddOptions(opts): 72 try: 73 from SCons.Variables.BoolVariable import BoolVariable as BoolOption 74 except ImportError: 75 from SCons.Options.BoolOption import BoolOption 76 try: 77 from SCons.Variables.EnumVariable import EnumVariable as EnumOption 78 except ImportError: 79 from SCons.Options.EnumOption import EnumOption 80 opts.Add(EnumOption('build', 'build type', 'debug', 81 allowed_values=('debug', 'checked', 'profile', 'release'))) 82 opts.Add(BoolOption('quiet', 'quiet command lines', 'yes')) 83 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine, 84 allowed_values=('generic', 'ppc', 'x86', 'x86_64'))) 85 opts.Add(EnumOption('platform', 'target platform', host_platform, 86 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'cygwin', 'sunos', 'freebsd8'))) 87 opts.Add(BoolOption('embedded', 'embedded build', 'no')) 88 opts.Add('toolchain', 'compiler toolchain', default_toolchain) 89 opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no')) 90 opts.Add(BoolOption('llvm', 'use LLVM', default_llvm)) 91 opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes')) 92 opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no')) 93 opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0'))) 94