blob: b836a8b41dbfeb78054d1f2a5aca2cc866b6cae7 [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
José Fonseca13174c12008-03-03 18:52:37 +010046def AddOptions(opts):
José Fonseca94090432008-02-27 17:36:28 +090047 from SCons.Options.BoolOption import BoolOption
48 from SCons.Options.EnumOption import EnumOption
José Fonseca94090432008-02-27 17:36:28 +090049 opts.Add(BoolOption('debug', 'build debug version', 'no'))
José Fonseca5aa10822008-03-04 14:29:27 +010050 #opts.Add(BoolOption('quiet', 'quiet command lines', 'no'))
José Fonseca94090432008-02-27 17:36:28 +090051 opts.Add(EnumOption('machine', 'use machine-specific assembly code', default_machine,
52 allowed_values=('generic', 'x86', 'x86_64')))
53 opts.Add(EnumOption('platform', 'target platform', default_platform,
54 allowed_values=('linux', 'cell', 'winddk')))
55 opts.Add(BoolOption('llvm', 'use LLVM', 'no'))
56 opts.Add(BoolOption('dri', 'build DRI drivers', default_dri))
José Fonseca94090432008-02-27 17:36:28 +090057
58
59#######################################################################
José Fonseca5aa10822008-03-04 14:29:27 +010060# Quiet command lines
61#
62# See also http://www.scons.org/wiki/HidingCommandLinesInOutput
63
64def quietCommandLines(env):
65 env['CCCOMSTR'] = "Compiling $SOURCE ..."
66 env['CXXCOMSTR'] = "Compiling $SOURCE ..."
67 env['ARCOMSTR'] = "Archiving $TARGET ..."
68 env['RANLIBCOMSTR'] = ""
69 env['LINKCOMSTR'] = "Linking $TARGET ..."
70
71
72#######################################################################
José Fonseca94090432008-02-27 17:36:28 +090073# Convenience Library Builder
74# based on the stock StaticLibrary and SharedLibrary builders
75
76import SCons.Action
77import SCons.Builder
78
79def createConvenienceLibBuilder(env):
80 """This is a utility function that creates the ConvenienceLibrary
81 Builder in an Environment if it is not there already.
82
83 If it is already there, we return the existing one.
84 """
85
86 try:
87 convenience_lib = env['BUILDERS']['ConvenienceLibrary']
88 except KeyError:
89 action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
90 if env.Detect('ranlib'):
91 ranlib_action = SCons.Action.Action("$RANLIBCOM", "$RANLIBCOMSTR")
92 action_list.append(ranlib_action)
93
94 convenience_lib = SCons.Builder.Builder(action = action_list,
95 emitter = '$LIBEMITTER',
96 prefix = '$LIBPREFIX',
97 suffix = '$LIBSUFFIX',
98 src_suffix = '$SHOBJSUFFIX',
99 src_builder = 'SharedObject')
100 env['BUILDERS']['ConvenienceLibrary'] = convenience_lib
101 env['BUILDERS']['Library'] = convenience_lib
102
103 return convenience_lib
104
105
106#######################################################################
107# Build
108
109def make_build_dir(env):
110 # Put build output in a separate dir, which depends on the current configuration
111 # See also http://www.scons.org/wiki/AdvancedBuildExample
112 build_topdir = 'build'
113 build_subdir = env['platform']
114 if env['dri']:
115 build_subdir += "-dri"
116 if env['llvm']:
117 build_subdir += "-llvm"
118 if env['machine'] != 'generic':
119 build_subdir += '-' + env['machine']
120 if env['debug']:
121 build_subdir += "-debug"
122 build_dir = os.path.join(build_topdir, build_subdir)
José Fonseca7a678552008-02-27 20:13:16 +0900123 # Place the .sconsign file on the builddir too, to avoid issues with different scons
124 # versions building the same source file
125 env.SConsignFile(os.path.join(build_dir, '.sconsign'))
José Fonseca94090432008-02-27 17:36:28 +0900126 return build_dir
127
José Fonseca5aa10822008-03-04 14:29:27 +0100128
129#######################################################################
130# Common environment generation code
131
132def generate(env):
133 # FIXME: this is already too late
134 #if env.get('quiet', False):
135 # quietCommandLines(env)
136 createConvenienceLibBuilder(env)
137
138 # for debugging
139 #print env.Dump()
140