forked from spring/spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
398 lines (337 loc) · 16.8 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
# Copyright (C) 2006 Tobi Vollebregt
# see rts/build/scons/*.py for the core of the build system
""" Available targets.
Each target has an equivalent install target. E.g. `CentralBuildAI' has
`install-CentralBuildAI' and the default target has `install'.
[default]
spring
unitsync
GroupAI
CentralBuildAI
MetalMakerAI
SimpleFormationAI
GlobalAI
JCAI
NTAI
OTAI
TestGlobalAI
"""
import os, sys
sys.path.append('rts/build/scons')
import filelist
if sys.platform == 'win32':
# force to mingw, otherwise picks up msvc
myTools = ['mingw', 'rts', 'gch']
else:
myTools = ['default', 'rts', 'gch']
env = Environment(tools = myTools, toolpath = ['.', 'rts/build/scons'])
if env['use_gch']:
env['Gch'] = env.Gch('rts/System/StdAfx.h', CPPDEFINES=env['CPPDEFINES']+env['spring_defines'])[0]
else:
import os.path
if os.path.exists('rts/System/StdAfx.h.gch'):
os.unlink('rts/System/StdAfx.h.gch')
################################################################################
### Build streflop (which has it's own Makefile-based build system)
################################################################################
def createStaticExtLibraryBuilder(env):
"""This is a utility function that creates the StaticExtLibrary
Builder in an Environment if it is not there already.
If it is already there, we return the existing one."""
import SCons.Action
try:
static_extlib = env['BUILDERS']['StaticExtLibrary']
except KeyError:
action_list = [ SCons.Action.Action("$ARCOM", "$ARCOMSTR") ]
if env.Detect('ranlib'):
ranlib_action = SCons.Action.Action("$RANLIBCOM",
"$RANLIBCOMSTR")
action_list.append(ranlib_action)
static_extlib = SCons.Builder.Builder(action = action_list,
emitter = '$LIBEMITTER',
prefix = '$LIBPREFIX',
suffix = '$LIBSUFFIX',
src_suffix = '$OBJSUFFIX',
src_builder = 'SharedObject')
env['BUILDERS']['StaticExtLibrary'] = static_extlib
return static_extlib
# stores shared objects so newer scons versions don't choke with
def create_static_objects(env, fileList, suffix, additionalCPPDEFINES = []):
objsList = []
myEnv = env.Clone()
myEnv.AppendUnique(CPPDEFINES = additionalCPPDEFINES)
for f in fileList:
while isinstance(f, list):
f = f[0]
fpath, fbase = os.path.split(f)
fname, fext = fbase.rsplit('.', 1)
objsList.append(myEnv.StaticObject(os.path.join(fpath, fname + suffix), f))
return objsList
# setup build environment
senv = env.Clone(builddir=os.path.join(env['builddir'], 'streflop'))
senv['CPPPATH'] = []
senv.BuildDir(os.path.join(senv['builddir'], 'rts/lib/streflop'), 'rts/lib/streflop', duplicate = False)
for d in filelist.list_directories(senv, 'rts/lib/streflop', exclude_list=[]):
senv.BuildDir(os.path.join(senv['builddir'], d), d, duplicate = False)
# setup flags and defines
if senv['fpmath'] == 'sse':
senv['CPPDEFINES'] = ['STREFLOP_SSE=1']
else:
senv['CPPDEFINES'] = ['STREFLOP_X87=1']
senv['CXXFLAGS'] = ['-Wall', '-O3', '-pipe', '-g', '-mno-tls-direct-seg-refs', '-fsingle-precision-constant', '-frounding-math', '-fsignaling-nans', '-fno-strict-aliasing', '-mieee-fp']
senv.AppendUnique(CXXFLAGS = senv['streflop_extra'])
# create the libm sub-part build environment
slibmenv = senv.Clone()
slibmenv.AppendUnique(CPPPATH = ['rts/lib/streflop/libm/headers'])
# gather the sources
sobjs_flt32 = create_static_objects(slibmenv, filelist.get_source(slibmenv, 'rts/lib/streflop/libm/flt-32'), '-streflop-flt32', ['LIBM_COMPILING_FLT32'])
#sobjs_dbl64 = create_static_objects(slibmenv, filelist.get_source(slibmenv, 'rts/lib/streflop/libm/dbl-64'), '-streflop-dbl64', ['LIBM_COMPILING_DBL64'])
#sobjs_ldbl96 = create_static_objects(slibmenv, filelist.get_source(slibmenv, 'rts/lib/streflop/libm/ldbl-96'), '-streflop-ldbl96', ['LIBM_COMPILING_LDBL96'])
streflopSource_tmp = [
'rts/lib/streflop/SMath.cpp',
'rts/lib/streflop/Random.cpp'
]
streflopSource = []
for f in streflopSource_tmp: streflopSource += [os.path.join(senv['builddir'], f)]
streflopSource += sobjs_flt32
# not needed => safer (and faster) to not compile them at all
#streflopSource += sobjs_flt32 + sobjs_dbl64 + sobjs_ldbl96
# compile
createStaticExtLibraryBuilder(senv)
streflop_lib = senv.StaticExtLibrary(senv['builddir'], streflopSource)
#streflop_lib = senv.StaticLibrary(senv['builddir'], streflopSource)
Alias('streflop', streflop_lib) # Allow `scons streflop' to compile just streflop
################################################################################
### Build spring(.exe)
################################################################################
spring_files = filelist.get_spring_source(env)
# spring.exe icon
if env['platform'] == 'windows':
# resource builder (the default one of mingw gcc 4.1.1 crashes because of a popen bug in msvcrt.dll)
if sys.platform == 'win32':
rcbld = Builder(action = 'windres --use-temp-file -i $SOURCE -o $TARGET', suffix = '.o', src_suffix = '.rc')
else:
# dirty hack assuming on all non-win32 systems windres is called i586-mingw32msvc-windres..
rcbld = Builder(action = 'i586-mingw32msvc-windres --use-temp-file -i $SOURCE -o $TARGET', suffix = '.o', src_suffix = '.rc')
env.Append(BUILDERS = {'RES': rcbld})
spring_files += env.RES(env['builddir'] + '/rts/build/scons/icon.rc', CPPPATH=[])
# calculate datadir locations
if env['platform'] == 'windows':
datadir = []
else:
datadir = ['SPRING_DATADIR="\\"'+os.path.join(env['prefix'], env['datadir'])+'\\""',
'SPRING_DATADIR_2="\\"'+os.path.join(env['prefix'], env['libdir'])+'\\""']
# Build DataDirLocater.cpp separately from the other sources. This is to prevent recompilation of
# the entire source if one wants to change just the install installprefix (and hence the datadir).
ddlcpp = env.Object(os.path.join(env['builddir'], 'rts/System/FileSystem/DataDirLocater.cpp'), CPPDEFINES = env['CPPDEFINES']+env['spring_defines']+datadir)
spring_files += [ddlcpp]
spring_files += [streflop_lib]
if env['use_nedmalloc']:
nedmalloc = SConscript('tools/nedmalloc/SConscript', exports='env')
spring_files += [nedmalloc]
if env['platform'] != 'windows':
spring = env.Program('game/spring', spring_files, CPPDEFINES=env['CPPDEFINES']+env['spring_defines'])
else: # create import library and .def file on Windows
spring = env.Program('game/spring', spring_files, CPPDEFINES=env['CPPDEFINES']+env['spring_defines'], LINKFLAGS=env['LINKFLAGS'] + ['-Wl,--output-def,game/spring.def', '-Wl,--kill-at', '--add-stdcall-alias','-Wl,--out-implib,game/spring.a'] )
Alias('spring', spring)
Default(spring)
inst = env.Install(os.path.join(env['installprefix'], env['bindir']), spring)
Alias('install', inst)
Alias('install-spring', inst)
# Strip the executable if rts.py said so.
if env['strip']:
env.AddPostAction(spring, Action([['strip','$TARGET']]))
################################################################################
### Build unitsync shared object
################################################################################
# HACK we should probably compile libraries from 7zip, hpiutil2 and minizip
# so we don't need so much bloat here.
# Need a new env otherwise scons chokes on equal targets built with different flags.
usync_builddir = os.path.join(env['builddir'], 'unitsync')
uenv = env.Clone(builddir=usync_builddir)
uenv.AppendUnique(CPPDEFINES=['UNITSYNC', 'BITMAP_NO_OPENGL'])
def remove_precompiled_header(env):
while 'USE_PRECOMPILED_HEADER' in env['CPPDEFINES']:
env['CPPDEFINES'].remove('USE_PRECOMPILED_HEADER')
while '-DUSE_PRECOMPILED_HEADER' in env['CFLAGS']:
env['CFLAGS'].remove('-DUSE_PRECOMPILED_HEADER')
while '-DUSE_PRECOMPILED_HEADER' in env['CXXFLAGS']:
env['CXXFLAGS'].remove('-DUSE_PRECOMPILED_HEADER')
remove_precompiled_header(uenv)
def usync_get_source(*args, **kwargs):
return filelist.get_source(uenv, ignore_builddir=True, *args, **kwargs)
uenv.BuildDir(os.path.join(uenv['builddir'], 'tools/unitsync'), 'tools/unitsync', duplicate = False)
unitsync_files = usync_get_source('tools/unitsync')
unitsync_fs_files = usync_get_source('rts/System/FileSystem/', exclude_list=('rts/System/FileSystem/DataDirLocater.cpp'));
unitsync_lua_files = usync_get_source('rts/lib/lua/src');
unitsync_7zip_files = usync_get_source('rts/lib/7zip');
unitsync_minizip_files = usync_get_source('rts/lib/minizip', 'rts/lib/minizip/iowin32.c');
unitsync_hpiutil2_files = usync_get_source('rts/lib/hpiutil2');
unitsync_extra_files = [
'rts/Game/GameVersion.cpp',
'rts/Lua/LuaUtils.cpp',
'rts/Lua/LuaIO.cpp',
'rts/Lua/LuaParser.cpp',
'rts/Map/MapParser.cpp',
'rts/Map/SMF/SmfMapFile.cpp',
'rts/Rendering/Textures/Bitmap.cpp',
'rts/Rendering/Textures/nv_dds.cpp',
'rts/Sim/Misc/SideParser.cpp',
'rts/System/Info.cpp',
'rts/System/Option.cpp',
'rts/System/ConfigHandler.cpp',
'rts/System/LogOutput.cpp',
]
unitsync_files.extend(unitsync_fs_files)
unitsync_files.extend(unitsync_lua_files)
unitsync_files.extend(unitsync_7zip_files)
unitsync_files.extend(unitsync_minizip_files)
unitsync_files.extend(unitsync_hpiutil2_files)
unitsync_files.extend(unitsync_extra_files)
if env['platform'] == 'windows':
# crosscompiles on buildbot need this, but native mingw builds fail
# during linking
if os.name != 'nt':
unitsync_files.append('rts/lib/minizip/iowin32.c')
unitsync_files.append('rts/System/FileSystem/DataDirLocater.cpp')
# some scons stupidity
unitsync_objects = [uenv.SharedObject(source=f, target=os.path.join(uenv['builddir'], f)+'.o') for f in unitsync_files]
# Need the -Wl,--kill-at --add-stdcall-alias because TASClient expects undecorated stdcall functions.
unitsync = uenv.SharedLibrary('game/unitsync', unitsync_objects, LINKFLAGS=env['LINKFLAGS'] + ['-Wl,--kill-at', '--add-stdcall-alias'])
else:
ddlcpp = uenv.SharedObject(os.path.join(env['builddir'], 'rts/System/FileSystem/DataDirLocater.cpp'), CPPDEFINES = uenv['CPPDEFINES']+datadir)
# some scons stupidity
unitsync_objects = [uenv.SharedObject(source=f, target=os.path.join(uenv['builddir'], f)+'.os') for f in unitsync_files]
unitsync_objects += [ ddlcpp ]
unitsync = uenv.SharedLibrary('game/unitsync', unitsync_objects)
Alias('unitsync', unitsync)
inst = env.Install(os.path.join(env['installprefix'], env['libdir']), unitsync)
Alias('install', inst)
Alias('install-unitsync', inst)
# Strip the DLL if rts.py said so.
if env['strip']:
env.AddPostAction(unitsync, Action([['strip','$TARGET']]))
# Somehow unitsync fails to build with mingw:
# "build\tools\unitsync\pybind.o(.text+0x129d): In function `initunitsync':
# pybind.cpp:663: undefined reference to `_imp__Py_InitModule4TraceRefs'"
# Figured this out: this means we're attempting to build unitsync with debugging
# enabled against a python version with debugging disabled.
if env['platform'] != 'windows':
Default(unitsync)
################################################################################
### AIs
################################################################################
# Make a copy of the build environment for the AIs, but remove libraries and add include path.
# TODO: make separate SConstructs for AIs
aienv = env.Clone()
aienv.AppendUnique(CPPPATH = ['rts/ExternalAI'])
aienv.AppendUnique(CPPDEFINES=['USING_CREG'])
remove_precompiled_header(aienv)
# Use subst() to substitute $installprefix in datadir.
install_dir = os.path.join(aienv['installprefix'], aienv['libdir'], 'AI/Helper-libs')
# store shared ai objects so newer scons versions don't choke with
# *** Two environments with different actions were specified for the same target
aiobjs = []
for f in filelist.get_shared_AI_source(aienv):
while isinstance(f, list):
f = f[0]
fpath, fbase = os.path.split(f)
fname, fext = fbase.rsplit('.', 1)
aiobjs.append(aienv.SharedObject(os.path.join(fpath, fname + '-ai'), f))
#Build GroupAIs
for f in filelist.list_groupAIs(aienv, exclude_list=['build']):
lib = aienv.SharedLibrary(os.path.join('game/AI/Helper-libs', f), aiobjs + filelist.get_groupAI_source(aienv, f))
Alias(f, lib) # Allow e.g. `scons CentralBuildAI' to compile just an AI.
Alias('GroupAI', lib) # Allow `scons GroupAI' to compile all groupAIs.
Default(lib)
inst = env.Install(install_dir, lib)
Alias('install', inst)
Alias('install-GroupAI', inst)
Alias('install-'+f, inst)
if aienv['strip']:
aienv.AddPostAction(lib, Action([['strip','$TARGET']]))
install_dir = os.path.join(aienv['installprefix'], aienv.subst(aienv['libdir']), 'AI/Bot-libs')
#Build GlobalAIs
for f in filelist.list_globalAIs(aienv, exclude_list=['build', 'CSAI', 'TestABICAI','AbicWrappersTestAI']):
lib = aienv.SharedLibrary(os.path.join('game/AI/Bot-libs', f), aiobjs + filelist.get_globalAI_source(aienv, f))
Alias(f, lib) # Allow e.g. `scons JCAI' to compile just a global AI.
Alias('GlobalAI', lib) # Allow `scons GlobalAI' to compile all globalAIs.
Default(lib)
inst = env.Install(install_dir, lib)
Alias('install', inst)
Alias('install-GlobalAI', inst)
Alias('install-'+f, inst)
if aienv['strip']:
aienv.AddPostAction(lib, Action([['strip','$TARGET']]))
################################################################################
### Run Tests
################################################################################
# Use this to avoid an error message 'how to make target test ?'
env.Alias('test', None)
# Simple unit testing framework. In all 'Test' subdirectories, if a file 'test'
# exists, it is run. This test script should then compile the test(s) and run them.
if 'test' in sys.argv and env['platform'] != 'windows':
for dir in filelist.list_directories(env, 'rts'):
if dir.endswith('/Test'):
test = os.path.join(dir, 'test')
if os.path.isfile(test):
os.system(test)
################################################################################
### Build gamedata zip archives & misc.
################################################################################
# Can't use these, we can't set the working directory and putting a SConscript
# in the respective directories doesn't work either because then the SConstript
# ends up in the zip too... Bah. SCons sucks. Just like autoshit and everything else btw.
#env.Zip('game/base/springcontent.sdz', filelist.list_files(env, 'installer/builddata/springcontent'))
#env.Zip('game/base/spring/bitmaps.sdz', filelist.list_files(env, 'installer/builddata/bitmaps'))
if not 'configure' in sys.argv and not 'test' in sys.argv and not 'install' in sys.argv:
if sys.platform != 'win32':
if env.GetOption('clean'):
if os.system("rm -f game/base/springcontent.sdz"):
env.Exit(1)
if os.system("rm -f game/base/spring/bitmaps.sdz"):
env.Exit(1)
if os.system("rm -f game/base/maphelper.sdz"):
env.Exit(1)
if os.system("rm -f game/base/cursors.sdz"):
env.Exit(1)
else:
if os.system("installer/make_gamedata_arch.sh"):
env.Exit(1)
inst = env.Install(os.path.join(env['installprefix'], env['datadir'], 'base'), 'game/base/springcontent.sdz')
Alias('install', inst)
inst = env.Install(os.path.join(env['installprefix'], env['datadir'], 'base'), 'game/base/maphelper.sdz')
Alias('install', inst)
inst = env.Install(os.path.join(env['installprefix'], env['datadir'], 'base'), 'game/base/cursors.sdz')
Alias('install', inst)
inst = env.Install(os.path.join(env['installprefix'], env['datadir'], 'base/spring'), 'game/base/spring/bitmaps.sdz')
Alias('install', inst)
# install fonts
for font in os.listdir('game/fonts'):
if not os.path.isdir(os.path.join('game/fonts', font)):
inst = env.Install(os.path.join(env['installprefix'], env['datadir'], 'fonts'), os.path.join('game/fonts', font))
Alias('install', inst)
# install some files from root of datadir
for f in ['cmdcolors.txt', 'ctrlpanel.txt', 'selectkeys.txt', 'uikeys.txt', 'teamcolors.lua']:
inst = env.Install(os.path.join(env['installprefix'], env['datadir']), os.path.join('game', f))
Alias('install', inst)
# install menu entry & icon
inst = env.Install(os.path.join(env['installprefix'], 'share/pixmaps'), 'rts/spring.png')
Alias('install', inst)
inst = env.Install(os.path.join(env['installprefix'], 'share/applications'), 'installer/freedesktop/applications/spring.desktop')
Alias('install', inst)
# install AAI config files
aai_data=filelist.list_files_recursive(env, 'game/AI/AAI')
for f in aai_data:
if not os.path.isdir(f):
inst = env.Install(os.path.join(aienv['installprefix'], aienv['datadir'], os.path.dirname(f)[5:]), f)
Alias('install', inst)
# install LuaUI files
for f in ['luaui.lua']:
inst = env.Install(os.path.join(env['installprefix'], env['datadir']), os.path.join('game', f))
Alias('install', inst)
luaui_files=filelist.list_files_recursive(env, 'game/LuaUI')
for f in luaui_files:
if not os.path.isdir(f):
inst = env.Install(os.path.join(env['installprefix'], env['datadir'], os.path.dirname(f)[5:]), f)
Alias('install', inst)