common.py 2.85 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 17 18

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

_platform_map = {
	'linux2': 'linux',
19
	'win32': 'windows',
20 21
}

José Fonseca's avatar
José Fonseca committed
22 23
host_platform = sys.platform
host_platform = _platform_map.get(host_platform, host_platform)
24

25 26 27
# 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:
José Fonseca's avatar
José Fonseca committed
28
    target_platform = SCons.Script.ARGUMENTS['platform']
29
else:
José Fonseca's avatar
José Fonseca committed
30
    target_platform = host_platform
31

José Fonseca's avatar
José Fonseca committed
32
cross_compiling = target_platform != host_platform
33

34 35 36 37 38 39
_machine_map = {
	'x86': 'x86',
	'i386': 'x86',
	'i486': 'x86',
	'i586': 'x86',
	'i686': 'x86',
Michel Dänzer's avatar
Michel Dänzer committed
40
	'ppc' : 'ppc',
41 42
	'x86_64': 'x86_64',
}
43 44


José Fonseca's avatar
José Fonseca committed
45
# find host_machine value
46
if 'PROCESSOR_ARCHITECTURE' in os.environ:
José Fonseca's avatar
José Fonseca committed
47
	host_machine = os.environ['PROCESSOR_ARCHITECTURE']
48
else:
José Fonseca's avatar
José Fonseca committed
49 50 51 52
	host_machine = _platform.machine()
host_machine = _machine_map.get(host_machine, 'generic')

default_machine = host_machine
53 54
default_toolchain = 'default'

José Fonseca's avatar
José Fonseca committed
55
if target_platform == 'windows' and cross_compiling:
56 57
    default_machine = 'x86'
    default_toolchain = 'crossmingw'
58

59 60

# find default_llvm value
61
if 'LLVM' in os.environ:
62 63 64
    default_llvm = 'yes'
else:
    default_llvm = 'no'
65
    try:
José Fonseca's avatar
José Fonseca committed
66
        if target_platform != 'windows' and \
67
           subprocess.call(['llvm-config', '--version'], stdout=subprocess.PIPE) == 0:
68 69 70
            default_llvm = 'yes'
    except:
        pass
71

72

73 74 75
#######################################################################
# Common options

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