common.py 3 KB
Newer Older
1 2 3 4 5
#######################################################################
# Common SCons code

import os
import os.path
Brian Paul's avatar
Brian Paul committed
6
import re
7
import subprocess
8 9 10
import sys
import platform as _platform

11 12
import SCons.Script.SConscript

13 14 15 16

#######################################################################
# Defaults

17
host_platform = _platform.system().lower()
18 19
if host_platform.startswith('cygwin'):
    host_platform = 'cygwin'
20

21 22 23
# Search sys.argv[] for a "platform=foo" argument since we don't have
# an 'env' variable at this point.
if 'platform' in SCons.Script.ARGUMENTS:
24
    target_platform = SCons.Script.ARGUMENTS['platform']
25
else:
26
    target_platform = host_platform
27

28 29 30 31 32 33
_machine_map = {
	'x86': 'x86',
	'i386': 'x86',
	'i486': 'x86',
	'i586': 'x86',
	'i686': 'x86',
Michel Dänzer's avatar
Michel Dänzer committed
34
	'ppc' : 'ppc',
35
	'AMD64': 'x86_64',
36 37
	'x86_64': 'x86_64',
}
38 39


40
# find host_machine value
41
if 'PROCESSOR_ARCHITECTURE' in os.environ:
42
	host_machine = os.environ['PROCESSOR_ARCHITECTURE']
43
else:
44 45 46 47
	host_machine = _platform.machine()
host_machine = _machine_map.get(host_machine, 'generic')

default_machine = host_machine
48 49
default_toolchain = 'default'

50
if target_platform == 'windows' and host_platform != 'windows':
51 52
    default_machine = 'x86'
    default_toolchain = 'crossmingw'
53

54 55

# find default_llvm value
56
if 'LLVM' in os.environ:
57 58 59
    default_llvm = 'yes'
else:
    default_llvm = 'no'
60
    try:
61
        if target_platform != 'windows' and \
62
           subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
63 64 65
            default_llvm = 'yes'
    except:
        pass
66

67

68 69 70
#######################################################################
# Common options

71
def AddOptions(opts):
72 73 74
	try:
		from SCons.Variables.BoolVariable import BoolVariable as BoolOption
	except ImportError:
75 76
		from SCons.Options.BoolOption import BoolOption
	try:
77
		from SCons.Variables.EnumVariable import EnumVariable as EnumOption
78 79
	except ImportError:
		from SCons.Options.EnumOption import EnumOption
80 81
	opts.Add(EnumOption('build', 'build type', 'debug',
	                  allowed_values=('debug', 'checked', 'profile', 'release')))
82
	opts.Add(BoolOption('verbose', 'verbose output', 'no'))
83
	opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
Michel Dänzer's avatar
Michel Dänzer committed
84
											 allowed_values=('generic', 'ppc', 'x86', 'x86_64')))
85
	opts.Add(EnumOption('platform', 'target platform', host_platform,
86 87
											 allowed_values=('linux', 'cell', 'windows', 'winddk', 'wince', 'darwin', 'cygwin', 'sunos', 'freebsd8')))
	opts.Add(BoolOption('embedded', 'embedded build', 'no'))
88
	opts.Add('toolchain', 'compiler toolchain', default_toolchain)
Chia-I Wu's avatar
Chia-I Wu committed
89
	opts.Add(BoolOption('gles', 'EXPERIMENTAL: enable OpenGL ES support', 'no'))
90
	opts.Add(BoolOption('llvm', 'use LLVM', default_llvm))
91 92
	opts.Add(BoolOption('debug', 'DEPRECATED: debug build', 'yes'))
	opts.Add(BoolOption('profile', 'DEPRECATED: profile build', 'no'))
93
	opts.Add(BoolOption('quiet', 'DEPRECATED: quiet command lines', 'yes'))
94 95
	if host_platform == 'windows':
		opts.Add(EnumOption('MSVS_VERSION', 'MS Visual C++ version', None, allowed_values=('7.1', '8.0', '9.0')))