Repository navigation
Expand file tree
/
Copy pathwscript
More file actions
735 lines (598 loc) · 28.4 KB
/
Copy pathwscript
File metadata and controls
735 lines (598 loc) · 28.4 KB
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
#! /usr/bin/env python
# encoding: utf-8
# a1batross, mittorn, 2018
from waflib import Build, Context, Logs, TaskGen
from waflib.Tools import waf_unit_test, c_tests
import clang_format
import sys
import os
# we need version 17 minimum
clang_format.CLANG_FORMAT_MIN_MAJOR = 17
VERSION = '0.99'
APPNAME = 'xash3d-fwgs'
top = '.'
default_prefix = '/' # Waf uses it to set default prefix
Context.Context.line_just = 55 # should fit for everything on 80x26
c_tests.LARGE_FRAGMENT='''#include <unistd.h>
int check[sizeof(off_t) >= 8 ? 1 : -1]; int main(void) { return 0; }'''
@TaskGen.feature('cshlib', 'cxxshlib', 'fcshlib')
@TaskGen.before_method('apply_implib')
def remove_implib_install(self):
if not getattr(self, 'install_path_implib', None):
self.install_path_implib = None
@TaskGen.feature('cprogram', 'cxxprogram')
@TaskGen.before_method('apply_flags_msvc')
def apply_subsystem_msvc(self):
if getattr(self, 'subsystem', None):
return # have custom subsystem
if 'test' in self.features:
self.subsystem = self.env.CONSOLE_SUBSYSTEM
@TaskGen.feature('format')
@TaskGen.after_method('make_format_tasks')
def use_xash_clang_format(self):
if self.bld.cmd != 'format':
return
wrapper = self.bld.bldnode.find_node('utils/xash-clang-format/xash-clang-format')
if not wrapper:
self.bld.fatal('no xash-clang-format found in build directory, reconfigure and rebuild with --enable-utils')
return
real_cf = clang_format.ClangFormatTask.binary
for t in self.tasks:
if isinstance(t, clang_format.ClangFormatTask):
t.binary = wrapper.abspath()
t.env.env = dict(os.environ, XASH_CLANG_FORMAT_BIN=real_cf)
class Subproject:
# manual_checkout: subproject is a submodule with update = none, its wscript is missing until it's checked out
def __init__(self, name, fnFilter = None, manual_checkout = False):
self.name = name
self.fnFilter = fnFilter
self.manual_checkout = manual_checkout
def is_exists(self, ctx):
return ctx.path.find_node(self.name + '/wscript')
def is_enabled(self, ctx):
if not self.is_exists(ctx):
return False
if self.fnFilter:
return self.fnFilter(ctx)
return True
class RefDll:
def __init__(self, name, default, key = None, all_renderers = True):
self.name = name
self.default = default
self.dest = key if key else name.upper()
self.all_renderers = all_renderers
def register_option(self, opt):
kw = dict()
if self.default:
act = 'disable'
kw['action'] = 'store_false'
else:
act = 'enable'
kw['action'] = 'store_true'
key = '--%s-%s' % (act, self.name)
kw['dest'] = self.dest
kw['default'] = self.default
kw['help'] = '%s %s renderer [default: %%(default)s]' % (act, self.name)
opt.add_option(key, **kw)
def register_env(self, env, opts, force):
env[self.dest] = (force and self.all_renderers) or opts.__dict__[self.dest]
def register_define(self, conf):
conf.define_cond('XASH_REF_%s_ENABLED' % self.dest, conf.env[self.dest])
SUBDIRS = [
# always configured and built
Subproject('public'),
Subproject('3rdparty/miniz', lambda x: not x.env.HAVE_SYSTEM_ZLIB),
Subproject('filesystem'),
Subproject('stub/server'),
Subproject('3rdparty/libbacktrace'),
Subproject('3rdparty/library_suffix'),
Subproject('3rdparty/yy-thunks'),
Subproject('utils/run-fuzzer', lambda x: x.env.ENABLE_FUZZER),
# disable only by engine feature, makes no sense to even parse subprojects in dedicated mode
Subproject('3rdparty/extras', lambda x: x.env.CLIENT and x.env.DEST_OS != 'android'),
Subproject('3rdparty/nanogl', lambda x: x.env.CLIENT and x.env.NANOGL, manual_checkout = True),
Subproject('3rdparty/gl-wes-v2', lambda x: x.env.CLIENT and x.env.GLWES, manual_checkout = True),
Subproject('3rdparty/gl4es', lambda x: x.env.CLIENT and x.env.GL4ES),
Subproject('ref/common', lambda x: x.env.CLIENT),
Subproject('ref/gl', lambda x: x.env.CLIENT and (x.env.GL or x.env.NANOGL or x.env.GLWES or x.env.GL4ES or x.env.GLES3COMPAT)),
Subproject('ref/soft', lambda x: x.env.CLIENT and x.env.SOFT),
Subproject('ref/null', lambda x: x.env.CLIENT and x.env.NULL),
Subproject('3rdparty/bzip2', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_BZ2),
Subproject('3rdparty/mpg123', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_MPG123),
Subproject('3rdparty/mbedtls'),
Subproject('3rdparty/opengnm', lambda x: x.env.CLIENT and x.env.DEST_OS == 'ps4'),
Subproject('3rdparty/ps4compat', lambda x: x.env.DEST_OS == 'ps4'),
Subproject('3rdparty/opus', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_OPUS),
Subproject('3rdparty/libogg', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_OGG),
Subproject('3rdparty/vorbis', lambda x: x.env.CLIENT and (not x.env.HAVE_SYSTEM_VORBIS or not x.env.HAVE_SYSTEM_VORBISFILE)),
Subproject('3rdparty/opusfile', lambda x: x.env.CLIENT and not x.env.HAVE_SYSTEM_OPUSFILE),
Subproject('3rdparty/maintui', lambda x: x.env.CLIENT and x.env.TUI, manual_checkout = True),
Subproject('3rdparty/mainui', lambda x: x.env.CLIENT and x.env.DEST_OS != 'android'),
# engine is obligated to provide VGUI interface in 32-bit builds on Windows/Linux/Mac as shared library
# on platforms supported only by Xash3D FWGS, freevgui can be linked statically into client library
Subproject('3rdparty/freevgui', lambda x: x.env.CLIENT and x.env.DEST_OS in ['win32', 'linux', 'darwin'] and x.env.DEST_CPU == 'x86'),
Subproject('3rdparty/MultiEmulator',lambda x: x.env.CLIENT),
Subproject('stub/client', lambda x: x.env.CLIENT),
Subproject('game_launch', lambda x: x.env.LAUNCHER and not x.env.SAILFISH),
Subproject('sailfish', lambda x: x.env.CLIENT and x.env.SAILFISH),
Subproject('engine'), # keep latest for static linking
# enabled optionally
Subproject('utils/mdldec', lambda x: x.env.ENABLE_UTILS),
Subproject('utils/xar', lambda x: x.env.ENABLE_UTILS),
Subproject('utils/xash-clang-format', lambda x: x.env.ENABLE_UTILS),
Subproject('utils/xrcon-tui', lambda x: x.env.ENABLE_UTILS),
# enabled on PSVita only
Subproject('ref/gl/vgl_shim', lambda x: x.env.DEST_OS == 'psvita'),
# enabled on PS4 only
Subproject('3rdparty/glslang', lambda x: x.env.CLIENT and x.env.GL and x.env.DEST_OS == 'ps4'),
Subproject('3rdparty/opengnm-psbc', lambda x: x.env.CLIENT and x.env.GL and x.env.DEST_OS == 'ps4'),
Subproject('ref/gl/gnm_shim', lambda x: x.env.CLIENT and x.env.GL and x.env.DEST_OS == 'ps4'),
]
REFDLLS = [
RefDll('soft', False, all_renderers = False),
RefDll('gl', True),
RefDll('gles1', False, 'NANOGL'),
RefDll('gles2', False, 'GLWES'),
RefDll('gl4es', False),
RefDll('gles3compat', False, 'GLES3COMPAT'),
RefDll('null', False),
]
def options(opt):
opt.load('reconfigure compiler_optimizations xshlib xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test msvs subproject ninja host_tool_compiler')
grp = opt.add_option_group('Common options')
grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
help = 'only build Xash Dedicated Server [default: %(default)s]')
grp.add_option('--enable-dedicated', action = 'store_true', dest = 'ENABLE_DEDICATED', default = False,
help = 'enable building Xash Dedicated Server alongside client [default: %(default)s]')
grp.add_option('--enable-tui', action = 'store_true', dest = 'ENABLE_TUI', default = False,
help = 'enable TUI main menu [default: %(default)s]')
grp.add_option('--gamedir', action = 'store', dest = 'GAMEDIR', default = 'valve',
help = 'engine default (base) game directory [default: %(default)s]')
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
help = 'allow targetting 64-bit engine(Linux/Windows only) [default: %(default)s]')
grp.add_option('-4', '--32bits', action = 'store_true', dest = 'FORCE32', default = False,
help = 'force targetting 32-bit engine, usually unneeded [default: %(default)s]')
grp.add_option('-P', '--enable-packaging', action = 'store_true', dest = 'PACKAGING', default = False,
help = 'respect prefix option, useful for packaging for various operating systems [default: %(default)s]')
grp.add_option('--enable-bundled-deps', action = 'store_true', dest = 'BUILD_BUNDLED_DEPS', default = False,
help = 'prefer to build bundled dependencies (like opus) instead of relying on system provided')
grp.add_option('--enable-hl25-extended-structs', action = 'store_true', dest = 'SUPPORT_HL25_EXTENDED_STRUCTS', default = False,
help = 'build engine and renderers with HL25 extended structs compatibility (might be required for some mods) [default: %(default)s]')
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('--disable-werror', action = 'store_true', dest = 'DISABLE_WERROR', default = False,
help = 'disable compilation abort on warning')
grp.add_option('--enable-tests', action = 'store_true', dest = 'TESTS', default = False,
help = 'enable building standalone tests (does not enable engine tests!) [default: %(default)s]')
grp.add_option('--disable-rpath', action = 'store_false', dest = 'ENABLE_RPATH', default = True,
help = 'disables rpath, duh!')
# a1ba: special option for me
grp.add_option('--enable-msvcdeps', action='store_true', dest='MSVCDEPS', default=False, help='')
grp.add_option('--enable-wafcache', action='store_true', dest='WAFCACHE', default=False, help='')
grp = opt.add_option_group('Renderers options')
grp.add_option('--enable-all-renderers', action='store_true', dest='ALL_RENDERERS', default=False,
help = 'enable all renderers supported by Xash3D FWGS [default: %(default)s]')
for dll in REFDLLS:
dll.register_option(grp)
grp = opt.add_option_group('Utilities options')
grp.add_option('--enable-utils', action = 'store_true', dest = 'ENABLE_UTILS', default = False,
help = 'enable building various development utilities [default: %(default)s]')
grp.add_option('--enable-fuzzer', action = 'store_true', dest = 'ENABLE_FUZZER', default = False,
help = 'enable building libFuzzer runner [default: %(default)s]' )
for i in SUBDIRS:
if not i.is_exists(opt):
continue
opt.add_subproject(i.name)
def check_system_pkg(conf, name):
return conf.check_cfg(package=name, uselib_store=name, args='--cflags --libs', mandatory=False)
def check_system_opus(conf):
# search for opus 1.4 only, it has fixes for custom modes
# 1.5 breaks custom modes: https://github.com/xiph/opus/issues/374
have_opus = conf.check_cfg(package='opus', uselib_store='opus', args=['opus = 1.4', '--cflags', '--libs'], mandatory=False)
# 1.6.1 fixes them again
if not have_opus:
have_opus = conf.check_cfg(package='opus', uselib_store='opus', args=['opus >= 1.6.1', '--cflags', '--libs'], mandatory=False)
if not have_opus:
return False
# now try to link with export that only exists with CUSTOM_MODES defined
frag='''#include <opus_custom.h>
int main(void) { return !opus_custom_encoder_init((OpusCustomEncoder *)1, (const OpusCustomMode *)1, 1); }'''
return conf.check_cc(msg='Checking if opus supports custom modes', defines='CUSTOM_MODES=1', use='opus werror', fragment=frag, mandatory=False)
def check_system_opusfile(conf):
if not check_system_pkg(conf, 'opusfile'):
return False
frag='''#include <opusfile.h>
int main(int argc, char **argv) { return opus_tagcompare(argv[0], argv[1]); }'''
return conf.check_cc(msg='Checking for libopusfile sanity', use='opusfile werror', fragment=frag, mandatory=False)
def check_system_mpg123(conf):
# 1.32 introduced portable API with int64_t reader callbacks
return conf.check_cfg(package='libmpg123', uselib_store='mpg123', args=['libmpg123 >= 1.32', '--cflags', '--libs'], mandatory=False)
def check_system_bzip2(conf):
frag='''#include <bzlib.h>
int main(void) { return (int)BZ2_bzlibVersion(); }'''
return conf.check_cc(lib='bz2', fragment=frag, uselib_store='bzip2', mandatory=False)
def check_system_zlib(conf):
# search for zlib-ng with native API first, then for anything providing zlib API
frag='''#include <zlib-ng.h>
int main(void) { zng_stream s = { 0 }; return zng_inflateInit2(&s, -MAX_WBITS); }'''
if conf.check_cc(lib='z-ng', fragment=frag, msg='Checking for zlib-ng', uselib_store='zlib', mandatory=False):
conf.env.append_unique('DEFINES_zlib', 'XASH_ZLIB_NG=1')
return True
frag='''#include <zlib.h>
int main(void) { z_stream s = { 0 }; return inflateInit2(&s, -MAX_WBITS); }'''
return conf.check_cc(lib='z', fragment=frag, msg='Checking for zlib', uselib_store='zlib', mandatory=False)
def check_system_freetype(conf):
frag='''#include <ft2build.h>
#include FT_FREETYPE_H
int main(void) { FT_Library library; return FT_Init_FreeType( &library ); }'''
# search for freetype
if conf.check_cfg(package='freetype2', uselib_store='freetype', args='--cflags --libs', mandatory=False):
return False
return conf.check_cc(msg='Checking for freetype2 sanity', use='freetype werror', fragment=frag, mandatory=False)
def configure(conf):
conf.load('fwgslib reconfigure compiler_optimizations')
if conf.options.ALLOW64:
conf.env.MSVC_TARGETS = ['x64']
elif sys.maxsize > 2 ** 32 and not conf.options.MSVC_WINE:
conf.env.MSVC_TARGETS = ['amd64_x86', 'x86']
else:
conf.env.MSVC_TARGETS = ['x86']
# Load compilers early
conf.load('xshlib xcompile compiler_c compiler_cxx')
if not conf.options.WAFCACHE:
conf.load('gccdeps')
if conf.options.MSVCDEPS:
conf.load('msvcdeps')
conf.env.WAFCACHE = conf.options.WAFCACHE
if conf.options.NSWITCH:
conf.load('nswitch')
if conf.options.PSVITA:
conf.load('psvita')
if conf.options.PS4:
conf.load('ps4')
# HACKHACK: override msvc DEST_CPU value by something that we understand
if conf.env.DEST_CPU == 'amd64':
conf.env.DEST_CPU = 'x86_64'
if conf.env.COMPILER_CC == 'msvc':
conf.load('msvc_pdb')
conf.load('msvs subproject clang_compilation_database strip_on_install waf_unit_test enforce_pic force_32bit ninja clang_format')
conf.env.MSVC_SUBSYSTEM = 'WINDOWS'
conf.env.CONSOLE_SUBSYSTEM = 'CONSOLE'
# Windows XP compatibility
if conf.env.MSVC_TARGETS[0] == 'amd64_x86' or conf.env.MSVC_TARGETS[0] == 'x86':
conf.env.MSVC_SUBSYSTEM += ',5.01'
conf.env.CONSOLE_SUBSYSTEM += ',5.01'
# Set default options for some platforms
if conf.env.DEST_OS == 'android':
conf.options.NANOGL = True
conf.options.GLWES = False # deprecated
conf.options.GL4ES = True
conf.options.GLES3COMPAT = True
conf.options.GL = False
elif conf.env.IOS:
conf.options.NANOGL = True
conf.options.GLWES = False # deprecated
conf.options.GL4ES = False # doesn't compile on ios yet
conf.options.GLES3COMPAT = True
conf.options.GL = False
elif conf.env.MAGX:
conf.options.SDL12 = True
conf.options.GL = False
conf.options.LOW_MEMORY = 1
enforce_pic = False
elif conf.env.MSVC_WINE:
conf.options.BUILD_BUNDLED_DEPS = True
elif conf.env.DEST_OS == 'ps4':
# no OpenGL driver: ref_gl draws through our OpenGL layer over GNM (ref/gl/gnm_shim)
conf.options.GL = True
conf.options.GLES3COMPAT = False
conf.options.SOFT = False
conf.options.USE_STBTT = True # mainui: no freetype2 package for PS4
conf.options.BUILD_BUNDLED_DEPS = True # the toolchain has no packages, host ones must not leak in
# opengnm calls them, both the engine and ref_gl link it
conf.env.LIB_PS4GNM_SYS = ['SceGnmDriver', 'SceVideoOut']
elif conf.env.SAILFISH:
conf.options.NANOGL = True
conf.options.GLWES = False # deprecated
conf.options.GL4ES = True
conf.options.GLES3COMPAT = True
conf.options.GL = False
# Harbour doesn't allow linking to system freetype
conf.options.USE_STBTT = True
# psvita needs -fPIC set manually and static builds are incompatible with -fPIC
enforce_pic = conf.env.DEST_OS != 'psvita' and not conf.env.STATIC_LINKING
conf.check_pic(enforce_pic)
# NOTE: We restrict 64-bit builds ONLY for Win/Linux running on Intel architecture
# Because compatibility with original GoldSrc
# NOTE: Since modern OSX (since Catalina) don't support 32-bit applications, there is no point
# to restrict them to 32-bit engine, despite GoldSrc is still officially supported.
# There is now `-4` (or `--32bits`) configure flag for those
# who want to specifically build engine for 32-bit
if conf.env.DEST_OS in ['win32', 'linux'] and conf.env.DEST_CPU == 'x86_64':
force_32bit = not conf.options.ALLOW64
else:
force_32bit = conf.options.FORCE32
if force_32bit:
conf.force_32bit()
cflags, linkflags = conf.get_optimization_flags()
cxxflags = list(cflags) # optimization flags are common between C and C++ but we need a copy
# on the Switch, allow undefined symbols by default, which is needed for libsolder to work
# we'll specifically disallow them for the engine executable
# additionally, shared libs are linked without standard libs, we'll add those back in the engine wscript
if conf.env.DEST_OS == 'nswitch':
linkflags.remove('-Wl,--no-undefined')
conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-nostartfiles'])
conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-nostartfiles'])
# same on the vita
elif conf.env.DEST_OS == 'psvita':
conf.env.append_unique('CFLAGS_cshlib', ['-fPIC'])
conf.env.append_unique('CXXFLAGS_cxxshlib', ['-fPIC', '-fno-use-cxa-atexit'])
conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all'])
conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all'])
# check if we need to use irix linkflags
elif conf.env.DEST_OS == 'irix' and conf.env.COMPILER_CC == 'gcc':
linkflags.remove('-Wl,--no-undefined')
linkflags.append('-Wl,-u,gl_INTERPRET_END')
# check if we're in a sgug environment
if 'sgug' in os.environ['LD_LIBRARYN32_PATH']:
linkflags.append('-lc')
elif conf.env.DEST_OS == 'darwin':
try:
linkflags.remove('-Wl,--no-undefined')
except:
pass
linkflags.append('-Wl,-undefined,error')
elif conf.env.SAILFISH:
conf.define('XASH_SAILFISH', 1)
# Harbour requires this name for the binary, desktop file, icons and /usr/share directory
conf.env.SAILFISH_PACKAGE = 'harbour-xash3d-fwgs'
# Harbour validator only recognizes DT_RPATH
linkflags.append('-Wl,--disable-new-dtags')
if conf.env.DEST_OS == 'ps4':
# fix broken struct sockaddr_storage in OpenOrbis headers
fix = conf.path.find_node('3rdparty/ps4compat/ps4_sockaddr.h').abspath()
cflags += ['-include', fix]
cxxflags += ['-include', fix]
conf.check_cc(cflags=cflags, linkflags=linkflags, msg='Checking for required C flags')
conf.check_cxx(cxxflags=cxxflags, 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)
if conf.env.COMPILER_CC == 'msvc':
opt_cflags = ['/we4013'] # -Werror=implicit-function-declaration
conf.env.CFLAGS_werror = conf.filter_cflags(opt_cflags, cflags)
else:
opt_flags = [
# '-Wall', '-Wextra', '-Wpedantic',
'-fdiagnostics-color=always',
# stable diagnostics, forced to error, sorted
'-Werror=alloc-size',
'-Werror=bool-compare',
'-Werror=bool-operation',
# '-Werror=cast-align=strict',
'-Werror=duplicated-cond',
'-Werror=format=2',
'-Werror=free-nonheap-object',
'-Werror=init-self',
'-Werror=implicit-fallthrough=2',
'-Werror=logical-op',
'-Werror=nonnull',
'-Werror=packed',
'-Werror=packed-not-aligned',
'-Werror=parentheses',
'-Werror=return-type',
'-Werror=sequence-point',
'-Werror=sizeof-pointer-memaccess',
'-Werror=sizeof-array-div',
'-Werror=sizeof-pointer-div',
'-Werror=strict-aliasing',
'-Werror=string-compare',
'-Werror=tautological-compare',
'-Werror=use-after-free=3',
'-Werror=vla',
'-Werror=write-strings',
# unstable diagnostics, may cause false positives
'-Walloc-zero',
'-Wmisleading-indentation',
'-Wmismatched-dealloc',
'-Wstringop-overflow',
'-Wuninitialized',
'-Wno-error=format-nonliteral',
# disabled, flood
# '-Wdouble-promotion',
'-Wunused-function',
'-Wunused-variable',
'-Wunused-but-set-variable',
]
if conf.env.COMPILER_CC == 'clang':
opt_flags += [
'-Werror=unsequenced', # clang's version of -Werror=sequence-point
]
opt_cflags = [
# disabled, as we're targetting C99 at least
# '-Werror=declaration-after-statement',
'-Werror=enum-conversion',
'-Wno-error=enum-float-conversion', # need this for cvars
'-Werror=implicit-int',
'-Werror=implicit-function-declaration',
'-Werror=incompatible-pointer-types',
'-Werror=int-conversion',
'-Werror=jump-misses-init',
'-Werror=old-style-declaration',
'-Werror=old-style-definition',
'-Werror=strict-prototypes',
'-fnonconst-initializers', # owcc
'-Wmissing-prototypes', # not an error yet
]
opt_cxxflags = [] # TODO:
if conf.options.DISABLE_WERROR:
opt_flags = []
opt_cflags = ['-Werror=implicit-function-declaration']
opt_cxxflags = []
conf.env.CFLAGS_werror = conf.filter_cflags(opt_flags + opt_cflags, cflags)
conf.env.CXXFLAGS_werror = conf.filter_cxxflags(opt_flags + opt_cxxflags, cxxflags)
conf.env.TESTS = conf.options.TESTS
conf.env.ENABLE_UTILS = conf.options.ENABLE_UTILS
conf.env.ENABLE_FUZZER = conf.options.ENABLE_FUZZER
conf.env.FREEVGUI_XASH_SUPPORT = True
if not conf.options.DEDICATED:
conf.env.SERVER = conf.options.ENABLE_DEDICATED
conf.env.CLIENT = True
conf.env.LAUNCHER = conf.env.DEST_OS not in ['android', 'nswitch', 'psvita', 'ps4', 'dos', 'emscripten'] and not conf.env.IOS and not conf.env.MAGX and not conf.env.STATIC_LINKING
else:
conf.env.SERVER = True
conf.env.CLIENT = False
conf.env.LAUNCHER = False
conf.env.TUI = conf.options.ENABLE_TUI
conf.define_cond('SUPPORT_HL25_EXTENDED_STRUCTS', conf.options.SUPPORT_HL25_EXTENDED_STRUCTS)
if conf.options.ENABLE_RPATH and conf.env.DEST_OS not in ['nswitch', 'psvita', 'ps4']:
if conf.env.DEST_OS == 'openbsd':
# OpenBSD requires -z origin to enable $ORIGIN expansion in RPATH
conf.env.RPATH_ST = '-Wl,-z,origin,-rpath,%s'
conf.env.DEFAULT_RPATH = '$ORIGIN'
elif conf.env.DEST_OS == 'irix':
conf.env.DEFAULT_RPATH = '/usr/lib32:/usr/sgug/lib32'
elif conf.env.DEST_OS == 'darwin':
conf.env.DEFAULT_RPATH = '@loader_path'
else:
conf.env.DEFAULT_RPATH = '$ORIGIN'
setattr(conf, 'refdlls', REFDLLS)
for refdll in REFDLLS:
refdll.register_env(conf.env, conf.options, conf.options.ALL_RENDERERS)
conf.env.GAMEDIR = conf.options.GAMEDIR
conf.define('XASH_GAMEDIR', conf.options.GAMEDIR)
if conf.env.DEST_OS == 'nswitch':
conf.check_cfg(package='solder', args='--cflags --libs', uselib_store='SOLDER')
if conf.env.HAVE_SOLDER and conf.env.LIB_SOLDER and conf.options.BUILD_TYPE == 'debug':
conf.env.LIB_SOLDER[0] += 'd' # load libsolderd in debug mode
conf.check_cc(lib='m')
elif conf.env.DEST_OS == 'psvita':
conf.check_cc(lib='vrtld')
conf.check_cc(lib='m')
elif conf.env.DEST_OS == 'android':
# maybe there is some better check?
if conf.find_program('termux-info', mandatory=False):
conf.env.TERMUX = True
conf.define('__TERMUX__', 1)
conf.check_cc(lib='dl')
conf.check_cc(lib='log')
if not conf.options.ANDROID_OPTS:
# if we're compiling on device itself
conf.check_cc(lib='m')
# otherwise LIB_M is defined by xcompile (as it might be libm_hard, depending on NDK configuration)
elif conf.env.DEST_OS == 'win32':
# MinGW defaults to msvcrt stdio, which lacks C99 conversions like %zu
# this also switches GCC format checking from ms_printf to gnu_printf
if conf.env.COMPILER_CC != 'msvc':
conf.env.append_unique('CFLAGS', '-D__USE_MINGW_ANSI_STDIO=1')
conf.env.append_unique('CXXFLAGS', '-D__USE_MINGW_ANSI_STDIO=1')
# 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 = [ 'user32', 'shell32', 'gdi32', 'advapi32', 'dbghelp', 'psapi', 'ws2_32', 'bcrypt' ]
if conf.env.MSVC_WINE:
# no LIBPATH under msvc-wine, the wrapper resolves libraries itself
for i in a:
conf.env['LIB_' + i.upper()] = [i]
elif conf.env.COMPILER_CC == 'msvc':
for i in a:
conf.start_msg('Checking for MSVC library')
conf.check_lib_msvc(i)
conf.end_msg(i)
else:
for i in a:
conf.check_cc(lib = i)
else:
conf.check_cc(lib='dl', mandatory = False)
conf.check_cc(lib='m')
# set _FILE_OFFSET_BITS=64 for filesystems with 64-bit inodes
# must be set globally as it changes ABI
if conf.env.DEST_OS == 'android' and conf.env.DEST_SIZEOF_VOID_P == 4:
# Android in 32-bit mode don't have good enough large file support
# with our native API level
# https://android.googlesource.com/platform/bionic/+/HEAD/docs/32-bit-abi.md
pass
elif conf.env.DEST_OS == 'psvita':
# PSVita don't have large file support at all
pass
else:
# try to guess how to support large files
conf.check_large_file(compiler = 'c', execute = False)
# indicate if we are packaging for Linux/BSD
if conf.options.PACKAGING:
conf.env.PREFIX = conf.options.prefix
if conf.env.SAILFISH:
# Harbour allows shipping libraries only in /usr/share/<name>/lib, including the game libraries in rodir
conf.env.LIBDIR = os.path.join(conf.env.PREFIX, 'share', conf.env.SAILFISH_PACKAGE, 'lib')
conf.env.SHAREDIR = conf.env.LIBDIR + '/rodir'
if conf.options.ENABLE_RPATH:
conf.env.DEFAULT_RPATH = conf.env.LIBDIR
else:
conf.env.SHAREDIR = '${PREFIX}/share/xash3d'
conf.env.LIBDIR += '/xash3d'
else:
conf.env.SHAREDIR = conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX
# there was a check for system libbacktrace but we can't be sure if it supports fileline or not
# therefore, always build libbacktrace ourselves
prefer_bundled_ogg = conf.options.BUILD_BUNDLED_DEPS
prefer_bundled_vorbis = conf.options.BUILD_BUNDLED_DEPS
prefer_bundled_opus = conf.options.BUILD_BUNDLED_DEPS
prefer_bundled_opusfile = conf.options.BUILD_BUNDLED_DEPS
prefer_bundled_mpg123 = conf.options.BUILD_BUNDLED_DEPS
prefer_bundled_bzip2 = conf.options.BUILD_BUNDLED_DEPS
prefer_bundled_freetype = conf.options.BUILD_BUNDLED_DEPS
# Harbour doesn't allow linking to these system libraries
if conf.env.SAILFISH:
prefer_bundled_opus = True
prefer_bundled_opusfile = True
prefer_bundled_mpg123 = True
prefer_bundled_freetype = True
# zlib is a part of platform API on Android
prefer_bundled_zlib = conf.options.BUILD_BUNDLED_DEPS and conf.env.DEST_OS != 'android'
if conf.env.CLIENT:
if not prefer_bundled_ogg:
conf.env.HAVE_SYSTEM_OGG = check_system_pkg(conf, 'ogg')
if not prefer_bundled_vorbis:
conf.env.HAVE_SYSTEM_VORBIS = check_system_pkg(conf, 'vorbis')
conf.env.HAVE_SYSTEM_VORBISFILE = check_system_pkg(conf, 'vorbisfile')
if not prefer_bundled_opus:
conf.env.HAVE_SYSTEM_OPUS = check_system_opus(conf)
if not prefer_bundled_opusfile:
conf.env.HAVE_SYSTEM_OPUSFILE = check_system_opusfile(conf)
if not prefer_bundled_mpg123:
conf.env.HAVE_SYSTEM_MPG123 = check_system_mpg123(conf)
if not prefer_bundled_bzip2:
conf.env.HAVE_SYSTEM_BZ2 = check_system_bzip2(conf)
if not prefer_bundled_freetype:
conf.env.HAVE_SYSTEM_FREETYPE = check_system_freetype(conf)
if not prefer_bundled_zlib:
conf.env.HAVE_SYSTEM_ZLIB = check_system_zlib(conf)
conf.define('XASH_LOW_MEMORY', conf.options.LOW_MEMORY)
for i in SUBDIRS:
if i.manual_checkout and not i.is_exists(conf) and i.fnFilter(conf):
conf.fatal('Can\'t find %s submodule. Run `git submodule update --init --checkout %s`.' % (i.name, i.name))
if not i.is_enabled(conf):
continue
conf.add_subproject(i.name)
def build(bld):
# enable progress bar mode if stdout is a terminal
if not bld.progress_bar and sys.stdout.isatty():
bld.progress_bar = 1
if bld.env.WAFCACHE:
bld.load('wafcache')
# guard rails to not let install to root
if bld.is_install and not bld.options.PACKAGING and not bld.options.destdir:
bld.fatal('Set the install destination directory using --destdir option')
# don't clean QtCreator files and reconfigure saved options
bld.clean_files = bld.bldnode.ant_glob('**',
excl='.qtc* *.user configuration.py .lock* *conf_check_*/** config.log 3rdparty/libbacktrace/*.h %s/*' % Build.CACHE_DIR,
quiet=True, generator=True)
bld.load('xshlib')
for i in SUBDIRS:
if not i.is_enabled(bld):
continue
bld.add_subproject(i.name)
if bld.env.TESTS:
bld.add_post_fun(waf_unit_test.summary)
bld.add_post_fun(waf_unit_test.set_exit_code)