-
Notifications
You must be signed in to change notification settings - Fork 4
/
wscript
459 lines (375 loc) · 20.2 KB
/
wscript
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
#! /usr/bin/env python
# encoding: utf-8
# a1batross, mittorn, 2018
from __future__ import print_function
from waflib import Logs, Context, Configure
import sys
import os
VERSION = '0.99'
APPNAME = 'xash3d-fwgs'
top = '.'
Context.Context.line_just = 55 # should fit for everything on 80x26
class Subproject:
name = ''
dedicated = True # if true will be ignored when building dedicated server
singlebin = False # if true will be ignored when singlebinary is set
ignore = False # if true will be ignored, set by user request
mandatory = False
def __init__(self, name, dedicated=True, singlebin=False, mandatory = False):
self.name = name
self.dedicated = dedicated
self.singlebin = singlebin
self.mandatory = mandatory
def is_enabled(self, ctx):
if not self.mandatory:
if self.name in ctx.env.IGNORE_PROJECTS:
self.ignore = True
if self.ignore:
return False
if ctx.env.SINGLE_BINARY and self.singlebin:
return False
if ctx.env.DEST_OS == 'android' and self.singlebin:
return False
if ctx.env.DEST_OS == 'wii' and 'ref' in self.name and 'gx' in self.name:
return False
if ctx.env.DEDICATED and self.dedicated:
return False
return True
SUBDIRS = [
Subproject('public', dedicated=False, mandatory = True),
Subproject('game_launch', singlebin=True),
Subproject('ref_gl',),
Subproject('ref_gx',),
Subproject('ref_soft'),
Subproject('mainui'),
Subproject('vgui_support'),
Subproject('stub/server', dedicated=False),
Subproject('stub/client'),
Subproject('dllemu'),
Subproject('engine', dedicated=False),
]
def subdirs():
return map(lambda x: x.name, SUBDIRS)
def options(opt):
grp = opt.add_option_group('Common options')
# half-life wii
grp.add_option('-w', '--Wii', action='store_true', dest='BUILD_WII', default = True,
help = 'build the engine for wii')
# half-life wii
grp.add_option('-T', '--build-type', action='store', dest='BUILD_TYPE', default = None,
help = 'build type: debug, release or none(custom flags)')
grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
help = 'build Xash Dedicated Server [default: %default]')
grp.add_option('--single-binary', action = 'store_true', dest = 'SINGLE_BINARY', default = False,
help = 'build single "xash" binary (always enabled for dedicated) [default: %default]')
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
help = 'allow targetting 64-bit engine(Linux/Windows/OSX x86 only) [default: %default]')
grp.add_option('-W', '--win-style-install', action = 'store_true', dest = 'WIN_INSTALL', default = False,
help = 'install like Windows build, ignore prefix, useful for development [default: %default]')
grp.add_option('--enable-bsp2', action = 'store_true', dest = 'SUPPORT_BSP2_FORMAT', default = False,
help = 'build engine and renderers with BSP2 map support(recommended for Quake, breaks compatibility!) [default: %default]')
grp.add_option('--enable-lto', action = 'store_true', dest = 'LTO', default = False,
help = 'enable Link Time Optimization if possible [default: %default]')
grp.add_option('--enable-poly-opt', action = 'store_true', dest = 'POLLY', default = False,
help = 'enable polyhedral optimization if possible [default: %default]')
grp.add_option('--low-memory-mode', action = 'store', dest = 'LOW_MEMORY', default = 0, type = 'int',
help = 'enable low memory mode (only for devices have <128 ram)')
grp.add_option('--enable-magx', action = 'store_true', dest = 'MAGX', default = False,
help = 'enable targetting for MotoMAGX phones [default: %default]')
grp.add_option('--ignore-projects', action = 'store', dest = 'IGNORE_PROJECTS', default = None,
help = 'disable selected projects from build [default: %default]')
opt.load('subproject')
for i in SUBDIRS:
if not i.mandatory and not opt.path.find_node(i.name+'/wscript'):
i.ignore = True
continue
opt.add_subproject(i.name)
opt.load('xshlib xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test')
if sys.platform == 'win32':
opt.load('msvc msdev msvs')
opt.load('reconfigure')
def configure(conf):
if conf.options.BUILD_WII:
print("--Building for Wii--")
conf.env.DEST_OS = "wii"
conf.env.DEST_CPU = "powerpc"
conf.env.CC = "/opt/devkitpro/devkitPPC/bin/powerpc-eabi-gcc"
conf.env.CXX = "/opt/devkitpro/devkitPPC/bin/powerpc-eabi-g++"
WII_CFLAGS = "-MMD -MP -MF -g -Wall -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float -D__wii__ -D__ppc__ -logc".split()
WII_LDFLAGS = "-g -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float -Wl,-Map,out-xash-wii.map -L/opt/devkitpro/libogc/lib/wii -lfat -lwiiuse -lbte -logc -lm".split()
WII_CXXFLAGS = []
WII_CXXFLAGS += ["-fno-rtti", "-fno-exceptions"]
WII_CXXFLAGS += WII_CFLAGS
conf.env.append_unique('CFLAGS', WII_CFLAGS)
conf.env.append_unique('CXXFLAGS', WII_CXXFLAGS)
conf.env.append_unique('LDFLAGS', WII_LDFLAGS)
conf.env.append_unique('INCLUDES', '/opt/devkitpro/libogc/include'.split())
enforce_pic = True # modern defaults
valid_build_types = ['fastnative', 'fast', 'release', 'debug', 'nooptimize', 'sanitize', 'none']
conf.load('fwgslib reconfigure')
if conf.options.IGNORE_PROJECTS:
conf.env.IGNORE_PROJECTS = conf.options.IGNORE_PROJECTS.split(',')
conf.start_msg('Build type')
if conf.options.BUILD_TYPE == None:
conf.end_msg('not set', color='RED')
conf.fatal('Please set a build type, for example "-T release"')
elif not conf.options.BUILD_TYPE in valid_build_types:
conf.end_msg(conf.options.BUILD_TYPE, color='RED')
conf.fatal('Invalid build type. Valid are: %s' % ', '.join(valid_build_types))
conf.end_msg(conf.options.BUILD_TYPE)
# -march=native should not be used
if conf.options.BUILD_TYPE.startswith('fast'):
Logs.warn('WARNING: \'%s\' build type should not be used in release builds', conf.options.BUILD_TYPE)
# Force XP compability, all build targets should add
# subsystem=bld.env.MSVC_SUBSYSTEM
# TODO: wrapper around bld.stlib, bld.shlib and so on?
conf.env.MSVC_SUBSYSTEM = 'WINDOWS,5.01'
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
if sys.platform == 'win32':
conf.load('msvc msvc_pdb msdev msvs')
conf.load('xshlib subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install waf_unit_test')
try:
conf.env.CC_VERSION[0]
except IndexError:
conf.env.CC_VERSION = (0,)
# modify options dictionary early
if conf.env.DEST_OS == 'android':
conf.options.NO_VGUI= True # skip vgui
conf.options.NANOGL = True
conf.options.GLWES = True
conf.options.GL = False
if conf.env.STATIC_LINKING:
enforce_pic = False # PIC may break static linking
conf.env.MAGX = conf.options.MAGX
if conf.options.MAGX:
conf.options.USE_SELECT = True
conf.options.SDL12 = True
conf.options.NO_VGUI = True
conf.options.GL = False
conf.options.LOW_MEMORY = 1
conf.options.SINGLE_BINARY = True
conf.options.NO_ASYNC_RESOLVE = True
conf.define('XASH_SDLMAIN', 1)
enforce_pic = False
# useless to change toolchain path, as toolchain meant to be placed in this path
toolchain_path = '/opt/toolchains/motomagx/arm-eabi2/lib/'
conf.env.INCLUDES_MAGX = [toolchain_path + i for i in ['ezx-z6/include', 'qt-2.3.8/include']]
conf.env.LIBPATH_MAGX = [toolchain_path + i for i in ['ezx-z6/lib', 'qt-2.3.8/lib']]
conf.env.LINKFLAGS_MAGX = ['-Wl,-rpath-link=' + i for i in conf.env.LIBPATH_MAGX]
for lib in ['qte-mt', 'ezxappbase', 'ezxpm', 'log_util']:
conf.check_cc(lib=lib, use='MAGX', uselib_store='MAGX')
if enforce_pic:
# Every static library must have fPIC
if conf.env.DEST_OS != 'win32' and '-fPIC' in conf.env.CFLAGS_cshlib:
conf.env.append_unique('CFLAGS_cstlib', '-fPIC')
conf.env.append_unique('CXXFLAGS_cxxstlib', '-fPIC')
else:
if '-fPIC' in conf.env.CFLAGS_cshlib:
conf.env.CFLAGS_cshlib.remove('-fPIC')
if '-fPIC' in conf.env.CXXFLAGS_cshlib:
conf.env.CXXFLAGS_cxxshlib.remove('-fPIC')
if '-fPIC' in conf.env.CFLAGS_MACBUNDLE:
conf.env.CFLAGS_MACBUNDLE.remove('-fPIC')
if '-fPIC' in conf.env.CXXFLAGS_MACBUNDLE:
conf.env.CXXFLAGS_MACBUNDLE.remove('-fPIC')
# We restrict 64-bit builds ONLY for Win/Linux/OSX running on Intel architecture
# Because compatibility with original GoldSrc
if conf.env.DEST_OS in ['win32', 'linux', 'darwin'] and conf.env.DEST_CPU == 'x86_64':
conf.env.BIT32_MANDATORY = not conf.options.ALLOW64
if not conf.env.BIT32_MANDATORY:
Logs.info('WARNING: will build engine for 32-bit target')
else:
conf.env.BIT32_MANDATORY = False
conf.load('force_32bit')
linker_flags = {
'common': {
'msvc': ['/DEBUG'], # always create PDB, doesn't affect result binaries
# 'gcc': ['-Wl,--no-undefined'], # half life wii comments
'owcc': ['-Wl,option stack=512k']
},
'sanitize': {
'clang': ['-fsanitize=undefined', '-fsanitize=address'],
'gcc': ['-fsanitize=undefined', '-fsanitize=address'],
}
}
compiler_c_cxx_flags = {
'common': {
# disable thread-safe local static initialization for C++11 code, as it cause crashes on Windows XP
'msvc': ['/D_USING_V110_SDK71_', '/Zi', '/FS', '/Zc:threadSafeInit-', '/MT'],
'clang': ['-g', '-gdwarf-2', '-fvisibility=hidden'],
'gcc': ['-g', '-fvisibility=hidden'],
'owcc': ['-fno-short-enum', '-ffloat-store', '-g3']
},
'fast': {
'msvc': ['/O2', '/Oy'],
'gcc': {
'3': ['-O3', '-fomit-frame-pointer'],
'default': ['-Ofast', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer']
},
'clang': ['-Ofast'],
'default': ['-O3']
},
'fastnative': {
'msvc': ['/O2', '/Oy'],
'gcc': ['-Ofast', '-march=native', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer'],
'clang': ['-Ofast', '-march=native'],
'default': ['-O3']
},
'release': {
'msvc': ['/O2'],
'owcc': ['-O3', '-foptimize-sibling-calls', '-fomit-leaf-frame-pointer', '-fomit-frame-pointer', '-fschedule-insns', '-funsafe-math-optimizations', '-funroll-loops', '-frerun-optimizer', '-finline-functions', '-finline-limit=512', '-fguess-branch-probability', '-fno-strict-aliasing', '-floop-optimize'],
'default': ['-O3']
},
'debug': {
'msvc': ['/O1'],
'gcc': ['-Og'],
'owcc': ['-O0', '-fno-omit-frame-pointer', '-funwind-tables', '-fno-omit-leaf-frame-pointer'],
'default': ['-O1']
},
'sanitize': {
'msvc': ['/Od', '/RTC1'],
'gcc': ['-Og', '-fsanitize=undefined', '-fsanitize=address'],
'clang': ['-O0', '-fsanitize=undefined', '-fsanitize=address'],
'default': ['-O0']
},
'nooptimize': {
'msvc': ['/Od'],
'default': ['-O0']
}
}
compiler_optional_flags = [
# '-Wall', '-Wextra', '-Wpedantic',
'-fdiagnostics-color=always',
#'-Werror=return-type', half-life wii comment
'-Werror=parentheses',
'-Werror=vla',
'-Werror=tautological-compare',
'-Werror=duplicated-cond',
'-Werror=duplicated-branches', # BEWARE: buggy
'-Werror=bool-compare',
'-Werror=bool-operation',
'-Wcast-align',
'-Werror=cast-align=strict', # =strict is for GCC >=8
#'-Werror=packed', half-life wii comment
'-Werror=packed-not-aligned',
'-Wuninitialized', # older GCC versions have -Wmaybe-uninitialized enabled by this switch, which is not accurate
# so just warn, not error
'-Winit-self',
'-Werror=implicit-fallthrough=2', # clang incompatible without "=2"
# '-Wdouble-promotion', # disable warning flood
'-Wstrict-aliasing',
]
c_compiler_optional_flags = [
'-Werror=incompatible-pointer-types',
#'-Werror=implicit-function-declaration', half-life wii comment
'-Werror=int-conversion',
'-Werror=implicit-int',
#'-Werror=strict-prototypes', half-life wii comment
'-Werror=old-style-declaration',
'-Werror=old-style-definition',
#'-Werror=declaration-after-statement', half-life wii comment
'-Werror=enum-conversion',
'-fnonconst-initializers' # owcc
]
linkflags = conf.get_flags_by_type(linker_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC, conf.env.CC_VERSION[0])
cflags = conf.get_flags_by_type(compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC, conf.env.CC_VERSION[0])
# Here we don't differentiate C or C++ flags
if conf.options.LTO:
lto_cflags = {
'msvc': ['/GL'],
'gcc': ['-flto'],
'clang': ['-flto']
}
lto_linkflags = {
'msvc': ['/LTCG'],
'gcc': ['-flto'],
'clang': ['-flto']
}
cflags += conf.get_flags_by_compiler(lto_cflags, conf.env.COMPILER_CC)
linkflags += conf.get_flags_by_compiler(lto_linkflags, conf.env.COMPILER_CC)
if conf.options.POLLY:
polly_cflags = {
'gcc': ['-fgraphite-identity'],
'clang': ['-mllvm', '-polly']
# msvc sosat :(
}
cflags += conf.get_flags_by_compiler(polly_cflags, conf.env.COMPILER_CC)
# And here C++ flags starts to be treated separately
cxxflags = list(cflags)
if conf.env.COMPILER_CC != 'msvc':
conf.check_cc(cflags=cflags, linkflags=linkflags, msg= 'Checking for required C flags')
conf.check_cxx(cxxflags=cflags, linkflags=linkflags, msg= 'Checking for required C++ flags')
conf.env.append_unique('CFLAGS', cflags)
conf.env.append_unique('CXXFLAGS', cxxflags)
conf.env.append_unique('LINKFLAGS', linkflags)
cxxflags += conf.filter_cxxflags(compiler_optional_flags, cflags)
cflags += conf.filter_cflags(compiler_optional_flags + c_compiler_optional_flags, cflags)
conf.env.append_unique('CFLAGS', cflags)
conf.env.append_unique('CXXFLAGS', cxxflags)
conf.env.append_unique('LINKFLAGS', linkflags)
# check if we can use C99 tgmath
if conf.check_cc(header_name='tgmath.h', mandatory=False):
if conf.env.COMPILER_CC == 'msvc':
conf.define('_CRT_SILENCE_NONCONFORMING_TGMATH_H', 1)
tgmath_usable = conf.check_cc(fragment='''#include<tgmath.h>
int main(void){ return (int)sin(2.0f); }''',
msg='Checking if tgmath.h is usable', mandatory=False)
conf.define_cond('HAVE_TGMATH_H', tgmath_usable)
else:
conf.undefine('HAVE_TGMATH_H')
# check if we can use C99 stdint
if conf.check_cc(header_name='stdint.h', mandatory=False):
# use system
conf.define('STDINT_H', 'stdint.h')
else:
# include portable stdint by Paul Hsich
conf.define('STDINT_H', 'pstdint.h')
conf.env.DEDICATED = conf.options.DEDICATED
conf.env.SINGLE_BINARY = conf.options.SINGLE_BINARY or conf.env.DEDICATED
if conf.env.DEST_OS == 'dos':
conf.env.SINGLE_BINARY = True
if conf.env.DEST_OS != 'win32':
conf.check_cc(lib='dl', mandatory=False)
if not conf.env.LIB_M: # HACK: already added in xcompile!
conf.check_cc(lib='m')
else:
# Common Win32 libraries
# Don't check them more than once, to save time
# Usually, they are always available
# but we need them in uselib
a = map(lambda x: {
# 'features': 'c',
# 'message': '...' + x,
'lib': x,
# 'uselib_store': x.upper(),
# 'global_define': False,
}, [
'user32',
'shell32',
'gdi32',
'advapi32',
'dbghelp',
'psapi',
'ws2_32'
])
for i in a:
conf.check_cc(**i)
# conf.multicheck(*a, run_all_tests = True, mandatory = True)
# indicate if we are packaging for Linux/BSD
if not conf.options.WIN_INSTALL and conf.env.DEST_OS not in ['win32', 'darwin', 'android']:
conf.env.LIBDIR = conf.env.BINDIR = '${PREFIX}/lib/xash3d'
else:
conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX
conf.define('XASH_BUILD_COMMIT', conf.env.GIT_VERSION if conf.env.GIT_VERSION else 'notset')
if conf.options.LOW_MEMORY:
conf.define('XASH_LOW_MEMORY', conf.options.LOW_MEMORY)
for i in SUBDIRS:
if not i.is_enabled(conf):
continue
conf.add_subproject(i.name)
def build(bld):
bld.load('xshlib')
for i in SUBDIRS:
if not i.is_enabled(bld):
continue
bld.add_subproject(i.name)