-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
307 lines (237 loc) · 8.38 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# -*- mode: python -*-
# ET build script
# TTimo <ttimo@idsoftware.com>
# http://scons.sourceforge.net
import sys, os, time, commands, re, pickle, StringIO, popen2, commands, pdb, zipfile, string, tempfile
import SCons
import scons_utils
conf_filename='site.conf'
# choose configuration variables which should be saved between runs
# ( we handle all those as strings )
serialized=[ 'CC', 'CXX', 'JOBS', 'BUILD', 'BUILD_ROOT', 'MASTER', 'NOCONF' ]
# help -------------------------------------------
Help("""
Usage: scons [OPTIONS] [TARGET] [CONFIG]
[OPTIONS] and [TARGET] are covered in command line options, use scons -H
[CONFIG]: KEY="VALUE" [...]
a number of configuration options saved between runs in the """ + conf_filename + """ file
erase """ + conf_filename + """ to start with default settings again
CC (default gcc)
CXX (default g++)
Specify C and C++ compilers (defaults gcc and g++)
ex: CC="gcc-3.3"
You can use ccache and distcc, for instance:
CC="ccache distcc gcc" CXX="ccache distcc g++"
JOBS (default 1)
Parallel build
BUILD (default debug)
Use debug-all/debug/release to select build settings
ex: BUILD="release"
debug-all: no optimisations, debugging symbols
debug: -O -g
release: all optimisations, including CPU target etc.
BUILD_ROOT (default 'build')
change the build root directory
NOCONF (default 0, not saved)
ignore site configuration and use defaults + command line only
MASTER (default '')
set to override the default master server address
"""
)
# end help ---------------------------------------
# sanity -----------------------------------------
EnsureSConsVersion( 0, 96 )
# end sanity -------------------------------------
# system detection -------------------------------
# CPU type
cpu = commands.getoutput('uname -m')
dll_cpu = '???' # grmbl, alternative naming for .so
exp = re.compile('.*i?86.*')
if exp.match(cpu):
cpu = 'x86'
dll_cpu = 'i386'
else:
cpu = commands.getoutput('uname -p')
if ( cpu == 'powerpc' ):
cpu = 'ppc'
dll_cpu = cpu
else:
cpu = 'cpu'
dll_cpu = cpu
OS = commands.getoutput( 'uname -s' )
if ( OS == 'Darwin' ):
print 'EXPERIMENTAL - INCOMPLETE'
print 'Use the XCode projects to compile ET universal binaries for OSX'
cpu = 'osx'
dll_cpu = 'osx'
print 'cpu: ' + cpu
# end system detection ---------------------------
# default settings -------------------------------
CC = 'gcc -m32'
CXX = 'g++ -m32'
JOBS = '1'
BUILD = 'debug'
BUILD_ROOT = 'build'
NOCONF = '0'
MASTER = ''
# end default settings ---------------------------
# arch detection ---------------------------------
def gcc_major():
major = os.popen( CC + ' -dumpversion' ).read().strip()
major = re.sub('^([^.]+)\\..*$', '\\1', major)
print 'gcc major: %s' % major
return major
gcc3 = (gcc_major() != '2')
def gcc_is_mingw():
mingw = os.popen( CC + ' -dumpmachine' ).read()
return re.search('mingw', mingw) != None
if gcc_is_mingw():
g_os = 'win32'
elif OS == 'Darwin':
g_os = 'Darwin'
else:
g_os = 'Linux'
print 'OS: %s' % g_os
# end arch detection -----------------------------
# site settings ----------------------------------
if ( not ARGUMENTS.has_key( 'NOCONF' ) or ARGUMENTS['NOCONF'] != '1' ):
site_dict = {}
if (os.path.exists(conf_filename)):
site_file = open(conf_filename, 'r')
p = pickle.Unpickler(site_file)
site_dict = p.load()
print 'Loading build configuration from ' + conf_filename + ':'
for k, v in site_dict.items():
exec_cmd = k + '=\'' + v + '\''
print ' ' + exec_cmd
exec(exec_cmd)
else:
print 'Site settings ignored'
# end site settings ------------------------------
# command line settings --------------------------
for k in ARGUMENTS.keys():
exec_cmd = k + '=\'' + ARGUMENTS[k] + '\''
print 'Command line: ' + exec_cmd
exec( exec_cmd )
# end command line settings ----------------------
# save site configuration ----------------------
if ( not ARGUMENTS.has_key( 'NOCONF' ) or ARGUMENTS['NOCONF'] != '1' ):
for k in serialized:
exec_cmd = 'site_dict[\'' + k + '\'] = ' + k
exec(exec_cmd)
site_file = open(conf_filename, 'w')
p = pickle.Pickler(site_file)
p.dump(site_dict)
site_file.close()
# end save site configuration ------------------
# general configuration, target selection --------
g_build = BUILD_ROOT + '/' + BUILD
SConsignFile( 'scons.signatures' )
SetOption('num_jobs', JOBS)
if ( OS == 'Linux' ):
LINK = CC
else:
LINK = CXX
# common flags
# BASE + CORE + OPT for engine
# BASE + GAME + OPT for game
BASECPPFLAGS = [ ]
CORECPPPATH = [ ]
CORELIBPATH = [ ]
CORECPPFLAGS = [ ]
GAMECPPFLAGS = [ ]
BASELINKFLAGS = [ ]
CORELINKFLAGS = [ ]
# for release build, further optimisations that may not work on all files
OPTCPPFLAGS = [ ]
if ( OS == 'Darwin' ):
BASECPPFLAGS += [ '-D__MACOS__', '-Wno-long-double', '-Wno-unknown-pragmas', '-Wno-trigraphs', '-fpascal-strings', '-fasm-blocks', '-Wreturn-type', '-Wunused-variable', '-ffast-math', '-fno-unsafe-math-optimizations', '-fvisibility=hidden', '-mmacosx-version-min=10.4', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk' ]
BASECPPFLAGS += [ '-arch', 'i386' ]
BASELINKFLAGS += [ '-arch', 'i386' ]
BASECPPFLAGS.append( '-pipe' )
# warn all
BASECPPFLAGS.append( '-Wall' )
# don't wrap gcc messages
BASECPPFLAGS.append( '-fmessage-length=0' )
if ( BUILD == 'debug-all' ):
BASECPPFLAGS.append( '-g' )
BASECPPFLAGS.append( '-D_DEBUG' )
elif ( BUILD == 'debug' ):
BASECPPFLAGS.append( '-g' )
BASECPPFLAGS.append( '-O1' )
BASECPPFLAGS.append( '-D_DEBUG' )
elif ( BUILD == 'release' ):
BASECPPFLAGS.append( '-DNDEBUG' )
if ( OS == 'Linux' ):
# -fomit-frame-pointer: gcc manual indicates -O sets this implicitely,
# only if that doesn't affect debugging
# on Linux, this affects backtrace capability, so I'm assuming this is needed
# -finline-functions: implicit at -O3
# -fschedule-insns2: implicit at -O3
# -funroll-loops ?
# -mfpmath=sse -msse ?
OPTCPPFLAGS = [ '-O3', '-march=i686', '-Winline', '-ffast-math', '-fomit-frame-pointer', '-finline-functions', '-fschedule-insns2' ]
elif ( OS == 'Darwin' ):
OPTCPPFLAGS = []
else:
print 'Unknown build configuration ' + BUILD
sys.exit(0)
# create the build environements
if g_os == 'win32':
g_base_env = Environment( tools=['mingw'], ENV = os.environ, CC = CC, CXX = CXX, LINK = LINK, CPPFLAGS = BASECPPFLAGS, LINKFLAGS = BASELINKFLAGS, CPPPATH = CORECPPPATH, LIBPATH = CORELIBPATH )
else:
g_base_env = Environment( ENV = os.environ, CC = CC, CXX = CXX, LINK = LINK, CPPFLAGS = BASECPPFLAGS, LINKFLAGS = BASELINKFLAGS, CPPPATH = CORECPPPATH, LIBPATH = CORELIBPATH )
scons_utils.SetupUtils( g_base_env )
g_env = g_base_env.Clone()
g_env['CPPFLAGS'] += OPTCPPFLAGS
g_env['CPPFLAGS'] += CORECPPFLAGS
g_env['LINKFLAGS'] += CORELINKFLAGS
if ( OS == 'Darwin' ):
# configure for dynamic bundle
g_env['SHLINKFLAGS'] = '$LINKFLAGS -bundle -flat_namespace -undefined suppress'
g_env['SHLIBSUFFIX'] = '.so'
# maintain this dangerous optimization off at all times
g_env.Append( CPPFLAGS = '-fno-strict-aliasing' )
if ( int(JOBS) > 1 ):
print 'Using buffered process output'
scons_utils.SetupBufferedOutput( g_env )
# mark the globals
local_dedicated = 0
# curl
local_curl = 0 # config selection
curl_lib = []
GLOBALS = 'g_env OS g_os BUILD local_dedicated curl_lib local_curl MASTER gcc3 cpu'
# end general configuration ----------------------
# win32 cross compilation ----------------------
if g_os == 'win32' and os.name != 'nt':
# mingw doesn't define the cpu type, but our only target is x86
g_env.Append(CPPDEFINES = '_M_IX86=400')
g_env.Append(LINKFLAGS = '-static-libgcc')
# scons doesn't support cross-compiling, so set these up manually
g_env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 1
g_env['WIN32DEFSUFFIX'] = '.def'
g_env['PROGSUFFIX'] = '.exe'
g_env['SHLIBSUFFIX'] = '.dll'
g_env['SHCCFLAGS'] = '$CCFLAGS'
cpu = 'x86'
# end win32 cross compilation ------------------
# targets ----------------------------------------
toplevel_targets = []
# build curl if needed
#if ( OS != 'Darwin' ):
# # 1: debug, 2: release
# if ( BUILD == 'release' ):
# local_curl = 2
# else:
# local_curl = 1
# Export( 'GLOBALS ' + GLOBALS )
# curl_lib = SConscript( 'SConscript.curl' )
local_dedicated = 1
Export( 'GLOBALS ' + GLOBALS )
BuildDir( g_build + '/dedicated', '.', duplicate = 0 )
etded = SConscript( g_build + '/dedicated/SConscript.core' )
if ( g_os == 'win32' ):
toplevel_targets.append( InstallAs( '#etded.exe', etded ) )
else:
toplevel_targets.append( InstallAs( '#etded.' + cpu, etded ) )
# end targets ------------------------------------