blob: e2650d6c8e2e225d2428b7fbb211bd0043fbdac8 [file] [log] [blame]
José Fonseca94090432008-02-27 17:36:28 +09001#######################################################################
2# Common SCons code
3
4import os
5import os.path
6import sys
7import platform as _platform
8
9
10#######################################################################
11# Defaults
12
13_platform_map = {
14 'linux2': 'linux',
15 'win32': 'winddk',
16}
17
18default_platform = sys.platform
19default_platform = _platform_map.get(default_platform, default_platform)
20
21_machine_map = {
22 'x86': 'x86',
23 'i386': 'x86',
24 'i486': 'x86',
25 'i586': 'x86',
26 'i686': 'x86',
27 'x86_64': 'x86_64',
28}
29if 'PROCESSOR_ARCHITECTURE' in os.environ:
30 default_machine = os.environ['PROCESSOR_ARCHITECTURE']
31else:
32 default_machine = _platform.machine()
33default_machine = _machine_map.get(default_machine, 'generic')
34
35if default_platform in ('linux', 'freebsd', 'darwin'):
36 default_dri = 'yes'
37elif default_platform in ('winddk',):
38 default_dri = 'no'
39else:
40 default_dri = 'no'
41
42
43#######################################################################
44# Common options
45
46def Options():
47 from SCons.Options import Options
48 from SCons.Options.BoolOption import BoolOption
49 from SCons.Options.EnumOption import EnumOption
50 opts = Options('config.py')
51 opts.Add(BoolOption('debug', 'build debug version', 'no'))
52 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
53 allowed_values=('generic', 'x86', 'x86_64')))
54 opts.Add(EnumOption('platform', 'target platform', default_platform,
55 allowed_values=('linux', 'cell', 'winddk')))
56 opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
57 opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
58 return opts
59
60
61#######################################################################
62# Convenience Library Builder
63# based on the stock StaticLibrary and SharedLibrary builders
64
65import SCons.Action
66import SCons.Builder
67
68def createConvenienceLibBuilder(env):
69 """This is a utility function that creates the ConvenienceLibrary
70 Builder in an Environment if it is not there already.
71
72 If it is already there, we return the existing one.
73 """
74
75 try:
76 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
77 except KeyError:
78 action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
79 if env.Detect('ranlib'):
80 ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
81 action_list.append(ranlib_action)
82
83 convenience_lib = SCons.Builder.Builder(action = action_list,
84 emitter = '$LIBEMITTER',
85 prefix = '$LIBPREFIX',
86 suffix = '$LIBSUFFIX',
87 src_suffix = '$SHOBJSUFFIX',
88 src_builder = 'SharedObject')
89 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
90 env['BUILDERS']['Library'] = convenience_lib
91
92 return convenience_lib
93
94
95#######################################################################
96# Build
97
98def make_build_dir(env):
99 # Put build output in a separate dir, which depends on the current configuration
100 # See also http://www.scons.org/wiki/AdvancedBuildExample
101 build_topdir = 'build'
102 build_subdir = env['platform']
103 if env['dri']:
104 build_subdir += "-dri"
105 if env['llvm']:
106 build_subdir += "-llvm"
107 if env['machine'] != 'generic':
108 build_subdir += '-' + env['machine']
109 if env['debug']:
110 build_subdir += "-debug"
111 build_dir = os.path.join(build_topdir, build_subdir)
112 return build_dir
113