2018-05-28 18:17:25 +03:00
#! /usr/bin/env python
# encoding: utf-8
# a1batross, mittorn, 2018
2024-11-27 15:07:36 +03:00
from waflib import Build, Context, Logs, TaskGen
2024-04-29 05:29:53 +03:00
from waflib.Tools import waf_unit_test, c_tests
2018-05-28 18:17:25 +03:00
import sys
2018-12-13 08:08:03 +03:00
import os
2018-06-17 14:30:59 +03:00
VERSION = '0.99'
APPNAME = 'xash3d-fwgs'
top = '.'
2023-04-24 23:12:14 +03:00
default_prefix = '/' # Waf uses it to set default prefix
2018-06-17 14:30:59 +03:00
2019-10-05 03:06:51 +03:00
Context.Context.line_just = 55 # should fit for everything on 80x26
2024-05-03 15:37:48 +03:00
c_tests.LARGE_FRAGMENT='''#include <unistd.h>
int check[sizeof(off_t) >= 8 ? 1 : -1]; int main(void) { return 0; }'''
2024-11-27 15:07:36 +03:00
@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
2024-11-27 15:34:49 +03:00
@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
2019-02-19 17:49:09 +03:00
class Subproject:
2022-08-19 03:10:34 +03:00
def __init__(self, name, fnFilter = None):
2019-02-19 17:49:09 +03:00
self.name = name
2022-08-19 03:10:34 +03:00
self.fnFilter = fnFilter
2019-02-19 17:49:09 +03:00
2022-08-19 03:10:34 +03:00
def is_exists(self, ctx):
return ctx.path.find_node(self.name + '/wscript')
2019-11-18 03:31:25 +07:00
2022-08-19 03:10:34 +03:00
def is_enabled(self, ctx):
if not self.is_exists(ctx):
2021-03-05 15:57:52 +03:00
return False
2022-08-19 03:10:34 +03:00
if self.fnFilter:
return self.fnFilter(ctx)
2022-01-15 06:24:57 +03:00
2019-11-05 01:01:33 +03:00
return True
2023-03-24 01:47:34 +03:00
class RefDll:
def __init__(self, name, default, key = None):
self.name = name
self.default = default
self.dest = key if key else name.upper()
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
2024-05-25 04:58:28 +03:00
kw['help'] = '%s %s renderer [default: %%(default)s]' % (act, self.name)
2023-03-24 01:47:34 +03:00
opt.add_option(key, **kw)
def register_env(self, env, opts, force):
env[self.dest] = force or opts.__dict__[self.dest]
def register_define(self, conf):
conf.define_cond('XASH_REF_%s_ENABLED' % self.dest, conf.env[self.dest])
2019-02-19 17:49:09 +03:00
SUBDIRS = [
2022-08-19 03:10:34 +03:00
# always configured and built
Subproject('public'),
Subproject('filesystem'),
Subproject('stub/server'),
2020-01-19 07:38:37 +07:00
Subproject('dllemu'),
2024-12-01 20:04:10 +04:00
Subproject('3rdparty/libogg'),
Subproject('3rdparty/vorbis/libvorbis'),
Subproject('3rdparty/vorbis/libvorbisfile'),
Subproject('3rdparty/opusfile'),
2022-08-19 03:10:34 +03:00
# disable only by engine feature, makes no sense to even parse subprojects in dedicated mode
2022-09-11 02:22:26 +03:00
Subproject('3rdparty/extras', lambda x: not x.env.DEDICATED and x.env.DEST_OS != 'android'),
2022-09-10 20:54:34 +03:00
Subproject('3rdparty/nanogl', lambda x: not x.env.DEDICATED and x.env.NANOGL),
Subproject('3rdparty/gl-wes-v2', lambda x: not x.env.DEDICATED and x.env.GLWES),
Subproject('3rdparty/gl4es', lambda x: not x.env.DEDICATED and x.env.GL4ES),
Subproject('ref/gl', lambda x: not x.env.DEDICATED and (x.env.GL or x.env.NANOGL or x.env.GLWES or x.env.GL4ES)),
2023-12-15 07:29:38 +03:00
Subproject('ref/soft', lambda x: not x.env.DEDICATED and not x.env.SUPPORT_BSP2_FORMAT and x.env.SOFT),
2023-10-15 05:12:21 +03:00
Subproject('ref/null', lambda x: not x.env.DEDICATED and x.env.NULL),
2024-10-07 18:11:29 +03:00
Subproject('3rdparty/bzip2', lambda x: not x.env.DEDICATED and not x.env.HAVE_SYSTEM_BZ2),
2022-09-10 19:06:56 +03:00
Subproject('3rdparty/mainui', lambda x: not x.env.DEDICATED),
Subproject('3rdparty/vgui_support', lambda x: not x.env.DEDICATED),
2024-10-10 19:06:26 +03:00
Subproject('3rdparty/MultiEmulator',lambda x: not x.env.DEDICATED),
2024-09-29 20:35:19 +03:00
# Subproject('3rdparty/freevgui', lambda x: not x.env.DEDICATED),
2022-09-10 19:06:56 +03:00
Subproject('stub/client', lambda x: not x.env.DEDICATED),
2024-01-15 02:03:44 +03:00
Subproject('game_launch', lambda x: not x.env.DISABLE_LAUNCHER),
2024-10-24 00:37:05 +03:00
Subproject('engine'), # keep latest for static linking
2022-08-19 03:10:34 +03:00
# disable only by external dependency presense
2024-12-01 20:04:10 +04:00
Subproject('3rdparty/opus', lambda x: not x.env.HAVE_SYSTEM_OPUS),
2022-08-19 03:10:34 +03:00
# enabled optionally
Subproject('utils/mdldec', lambda x: x.env.ENABLE_UTILS),
2024-07-21 05:36:58 +03:00
Subproject('utils/xar', lambda x: x.env.ENABLE_UTILS and x.env.ENABLE_XAR),
2022-08-19 03:10:34 +03:00
Subproject('utils/run-fuzzer', lambda x: x.env.ENABLE_FUZZER),
2023-02-21 23:32:47 +01:00
# enabled on PSVita only
2023-02-26 20:29:34 +01:00
Subproject('ref/gl/vgl_shim', lambda x: x.env.DEST_OS == 'psvita'),
2019-02-19 17:49:09 +03:00
]
2023-03-24 01:47:34 +03:00
REFDLLS = [
RefDll('soft', True),
RefDll('gl', True),
RefDll('gles1', False, 'NANOGL'),
RefDll('gles2', False, 'GLWES'),
RefDll('gl4es', False),
2023-10-05 00:24:40 +03:00
RefDll('gles3compat', False),
2023-10-15 05:12:21 +03:00
RefDll('null', False),
2023-03-24 01:47:34 +03:00
]
2018-05-28 18:17:25 +03:00
def options(opt):
2024-05-25 22:40:25 +03:00
opt.load('reconfigure compiler_optimizations xshlib xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test msdev msvs subproject cmake')
2023-04-17 05:19:56 +03:00
2019-02-19 16:33:14 +03:00
grp = opt.add_option_group('Common options')
2018-12-13 08:13:27 +03:00
2019-03-26 16:25:54 +03:00
grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
2024-05-25 04:58:28 +03:00
help = 'build Xash Dedicated Server [default: %(default)s]')
2018-11-18 23:04:30 +03:00
2022-09-11 02:12:44 +03:00
grp.add_option('--gamedir', action = 'store', dest = 'GAMEDIR', default = 'valve',
2024-07-21 01:01:33 +03:00
help = 'engine default (base) game directory [default: %(default)s]')
2022-09-11 02:12:44 +03:00
2019-03-26 16:25:54 +03:00
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
2024-08-10 15:01:36 +03:00
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]')
2018-11-18 23:04:30 +03:00
2021-11-25 16:52:28 +03:00
grp.add_option('-P', '--enable-packaging', action = 'store_true', dest = 'PACKAGING', default = False,
2024-05-25 04:58:28 +03:00
help = 'respect prefix option, useful for packaging for various operating systems [default: %(default)s]')
2018-12-13 08:13:27 +03:00
2022-09-12 04:18:24 +00:00
grp.add_option('--enable-bundled-deps', action = 'store_true', dest = 'BUILD_BUNDLED_DEPS', default = False,
2022-08-19 04:03:53 +03:00
help = 'prefer to build bundled dependencies (like opus) instead of relying on system provided')
2019-03-20 02:38:13 +03:00
grp.add_option('--enable-bsp2', action = 'store_true', dest = 'SUPPORT_BSP2_FORMAT', default = False,
2024-05-25 04:58:28 +03:00
help = 'build engine and renderers with BSP2 map support(recommended for Quake, breaks compatibility!) [default: %(default)s]')
2019-07-27 15:36:24 +03:00
2024-11-02 02:16:59 +03:00
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]')
2024-05-25 04:58:28 +03:00
grp.add_option('--low-memory-mode', action = 'store', dest = 'LOW_MEMORY', default = 0, type = int,
2019-10-26 12:12:59 +07:00
help = 'enable low memory mode (only for devices have <128 ram)')
2021-09-06 00:04:27 +03:00
grp.add_option('--disable-werror', action = 'store_true', dest = 'DISABLE_WERROR', default = False,
help = 'disable compilation abort on warning')
2023-04-13 18:40:27 +03:00
grp.add_option('--enable-tests', action = 'store_true', dest = 'TESTS', default = False,
2024-05-25 04:58:28 +03:00
help = 'enable building standalone tests (does not enable engine tests!) [default: %(default)s]')
2023-04-13 18:40:27 +03:00
2023-08-08 09:23:23 +03:00
# a1ba: special option for me
grp.add_option('--debug-all-servers', action='store_true', dest='ALL_SERVERS', default=False, help='')
2022-09-10 20:54:34 +03:00
grp = opt.add_option_group('Renderers options')
grp.add_option('--enable-all-renderers', action='store_true', dest='ALL_RENDERERS', default=False,
2024-05-25 04:58:28 +03:00
help = 'enable all renderers supported by Xash3D FWGS [default: %(default)s]')
2022-09-10 20:54:34 +03:00
2023-03-24 01:47:34 +03:00
for dll in REFDLLS:
dll.register_option(grp)
2022-09-10 20:54:34 +03:00
2021-03-05 15:57:52 +03:00
grp = opt.add_option_group('Utilities options')
grp.add_option('--enable-utils', action = 'store_true', dest = 'ENABLE_UTILS', default = False,
2024-05-25 04:58:28 +03:00
help = 'enable building various development utilities [default: %(default)s]')
2021-03-05 15:57:52 +03:00
2024-07-21 05:36:58 +03:00
grp.add_option('--enable-xar', action = 'store_true', dest = 'ENABLE_XAR', default = False,
help = 'enable building Xash ARchiver (experimental) [default: %(default)s]')
2022-01-15 06:24:57 +03:00
grp.add_option('--enable-fuzzer', action = 'store_true', dest = 'ENABLE_FUZZER', default = False,
2024-05-25 04:58:28 +03:00
help = 'enable building libFuzzer runner [default: %(default)s]' )
2022-01-15 06:24:57 +03:00
2019-11-18 03:31:25 +07:00
for i in SUBDIRS:
2022-08-19 03:10:34 +03:00
if not i.is_exists(opt):
2019-11-18 03:31:25 +07:00
continue
opt.add_subproject(i.name)
2019-02-19 17:49:09 +03:00
2018-05-28 18:17:25 +03:00
def configure(conf):
2021-01-29 03:33:14 +03:00
conf.load('fwgslib reconfigure compiler_optimizations')
2024-08-18 14:13:51 +03:00
if conf.options.ALLOW64:
conf.env.MSVC_TARGETS = ['x64']
2024-11-02 01:55:35 +03:00
elif sys.maxsize > 2 ** 32 and not conf.options.MSVC_WINE:
2024-08-18 14:13:51 +03:00
conf.env.MSVC_TARGETS = ['amd64_x86', 'x86']
else:
conf.env.MSVC_TARGETS = ['x86']
2021-02-21 22:15:13 -08:00
2021-02-25 17:16:17 +03:00
# Load compilers early
2024-11-27 15:08:42 +03:00
conf.load('xshlib xcompile compiler_c compiler_cxx gccdeps')
2021-02-25 17:16:17 +03:00
2023-02-05 02:09:32 +01:00
if conf.options.NSWITCH:
conf.load('nswitch')
2023-02-13 20:53:17 +01:00
if conf.options.PSVITA:
conf.load('psvita')
2021-02-25 17:16:17 +03:00
# HACKHACK: override msvc DEST_CPU value by something that we understand
if conf.env.DEST_CPU == 'amd64':
2021-02-21 22:15:13 -08:00
conf.env.DEST_CPU = 'x86_64'
2018-06-17 14:30:59 +03:00
2021-02-25 17:16:17 +03:00
if conf.env.COMPILER_CC == 'msvc':
conf.load('msvc_pdb')
2024-10-24 00:37:05 +03:00
conf.load('msvs msdev subproject clang_compilation_database strip_on_install waf_unit_test enforce_pic cmake force_32bit')
2021-02-25 17:16:17 +03:00
2024-10-17 14:56:10 +03:00
if conf.env.MSVC_TARGETS[0] == 'amd64_x86' or conf.env.MSVC_TARGETS[0] == 'x86':
2021-03-05 17:59:54 +03:00
conf.env.MSVC_SUBSYSTEM = 'WINDOWS,5.01'
conf.env.CONSOLE_SUBSYSTEM = 'CONSOLE,5.01'
else:
conf.env.MSVC_SUBSYSTEM = 'WINDOWS'
conf.env.CONSOLE_SUBSYSTEM = 'CONSOLE'
2021-01-29 03:33:14 +03:00
enforce_pic = True # modern defaults
2019-11-07 04:49:49 +03:00
2019-05-06 04:11:12 +03:00
# modify options dictionary early
2019-09-19 17:07:41 +03:00
if conf.env.DEST_OS == 'android':
2023-11-03 16:34:21 +03:00
conf.options.NO_VGUI = True # skip vgui
conf.options.NANOGL = True
2024-02-26 10:55:42 +03:00
conf.options.GLWES = False # deprecated
2023-11-03 16:34:21 +03:00
conf.options.GL4ES = True
2023-11-03 17:01:47 +03:00
conf.options.GLES3COMPAT = True
2023-11-03 16:34:21 +03:00
conf.options.GL = False
conf.define('XASH_SDLMAIN', 1)
2021-01-29 03:33:14 +03:00
elif conf.env.MAGX:
conf.options.SDL12 = True
conf.options.NO_VGUI = True
conf.options.GL = False
conf.options.LOW_MEMORY = 1
2019-11-07 06:56:07 +03:00
conf.options.NO_ASYNC_RESOLVE = True
2019-11-07 05:07:10 +03:00
conf.define('XASH_SDLMAIN', 1)
2019-11-06 23:13:03 +03:00
enforce_pic = False
2023-02-05 02:09:32 +01:00
elif conf.env.DEST_OS == 'nswitch':
conf.options.NO_VGUI = True
conf.options.GL = True
conf.options.USE_STBTT = True
2023-02-13 20:53:17 +01:00
elif conf.env.DEST_OS == 'psvita':
conf.options.NO_VGUI = True
conf.options.GL = True
conf.options.USE_STBTT = True
# we'll specify -fPIC by hand for shared libraries only
enforce_pic = False
2019-11-06 23:13:03 +03:00
2021-01-29 03:33:14 +03:00
if conf.env.STATIC_LINKING:
enforce_pic = False # PIC may break full static builds
conf.check_pic(enforce_pic)
2019-11-06 23:13:03 +03:00
2024-08-10 15:01:36 +03:00
# NOTE: We restrict 64-bit builds ONLY for Win/Linux running on Intel architecture
2019-05-31 02:59:45 +03:00
# Because compatibility with original GoldSrc
2024-08-10 15:01:36 +03:00
# 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':
2024-10-24 00:37:05 +03:00
force_32bit = not conf.options.ALLOW64
2019-05-31 02:59:45 +03:00
else:
2024-10-24 00:37:05 +03:00
force_32bit = conf.options.FORCE32
2024-08-10 15:01:36 +03:00
2024-10-24 00:37:05 +03:00
if force_32bit:
2024-08-10 15:01:36 +03:00
Logs.info('WARNING: will build engine for 32-bit target')
2024-10-24 00:37:05 +03:00
conf.force_32bit(True)
2018-12-13 08:13:27 +03:00
2021-01-29 03:33:14 +03:00
cflags, linkflags = conf.get_optimization_flags()
2023-03-24 01:47:34 +03:00
cxxflags = list(cflags) # optimization flags are common between C and C++ but we need a copy
2019-10-11 04:12:07 +03:00
2023-02-05 02:09:32 +01:00
# on the Switch, allow undefined symbols by default, which is needed for libsolder to work
2023-02-08 00:52:48 +01:00
# 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
2023-02-05 02:09:32 +01:00
if conf.env.DEST_OS == 'nswitch':
linkflags.remove('-Wl,--no-undefined')
2023-03-24 02:09:23 +03:00
conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-nostartfiles'])
conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-nostartfiles'])
2023-02-13 20:53:17 +01:00
# same on the vita
2023-03-24 02:09:23 +03:00
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'])
2023-03-24 01:47:34 +03:00
# check if we need to use irix linkflags
2023-03-24 02:09:23 +03:00
elif conf.env.DEST_OS == 'irix' and conf.env.COMPILER_CC == 'gcc':
2023-03-24 01:47:34 +03:00
linkflags.remove('-Wl,--no-undefined')
linkflags.append('-Wl,--unresolved-symbols=ignore-all')
# check if we're in a sgug environment
if 'sgug' in os.environ['LD_LIBRARYN32_PATH']:
linkflags.append('-lc')
2023-06-02 06:35:51 +03:00
elif conf.env.SAILFISH in ['aurora', 'sailfish']:
2023-06-01 04:56:30 +03:00
# TODO: enable XASH_MOBILE_PLATFORM
2023-06-02 06:16:40 +03:00
conf.define('XASH_SAILFISH', 1)
2023-06-02 06:35:51 +03:00
if conf.env.SAILFISH == 'aurora':
2023-06-02 06:16:40 +03:00
conf.define('XASH_AURORAOS', 1)
2023-06-01 04:56:30 +03:00
# Do not warn us about bug in SDL_Audio headers
conf.env.append_unique('CFLAGS', ['-Wno-attributes'])
conf.env.append_unique('CXXFLAGS', ['-Wno-attributes'])
2019-09-28 04:59:09 +07:00
2023-03-24 01:47:34 +03:00
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')
2023-01-14 00:35:30 -06:00
2019-10-11 04:12:07 +03:00
conf.env.append_unique('CFLAGS', cflags)
conf.env.append_unique('CXXFLAGS', cxxflags)
conf.env.append_unique('LINKFLAGS', linkflags)
2018-10-24 20:12:32 +03:00
2024-04-20 20:47:51 +03:00
if conf.env.COMPILER_CC != 'msvc':
2023-03-24 01:47:34 +03:00
opt_flags = [
# '-Wall', '-Wextra', '-Wpedantic',
'-fdiagnostics-color=always',
# stable diagnostics, forced to error, sorted
2023-12-11 07:11:40 +03:00
'-Werror=alloc-size',
2023-03-24 01:47:34 +03:00
'-Werror=bool-compare',
'-Werror=bool-operation',
2024-09-29 20:35:35 +03:00
# '-Werror=cast-align=strict',
2023-03-24 01:47:34 +03:00
'-Werror=duplicated-cond',
2024-07-18 01:28:35 +03:00
'-Werror=format-extra-args',
2024-09-30 03:58:12 +03:00
'-Werror=free-nonheap-object',
2023-03-24 01:47:34 +03:00
'-Werror=implicit-fallthrough=2',
'-Werror=logical-op',
2023-10-22 16:20:55 +03:00
'-Werror=nonnull',
2023-03-24 01:47:34 +03:00
'-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',
2023-05-14 09:39:15 +03:00
'-Werror=unsequenced', # clang's version of -Werror=sequence-point
2023-03-24 01:47:34 +03:00
'-Werror=vla',
'-Werror=write-strings',
# unstable diagnostics, may cause false positives
2024-06-24 20:01:29 +03:00
'-Walloc-zero',
'-Wformat=2',
2023-03-24 01:47:34 +03:00
'-Winit-self',
'-Wmisleading-indentation',
2024-09-30 03:58:12 +03:00
'-Wmismatched-dealloc',
2023-08-07 19:44:41 +03:00
'-Wstringop-overflow',
2023-03-24 01:47:34 +03:00
'-Wunintialized',
# disabled, flood
# '-Wdouble-promotion',
2023-12-04 02:53:07 +03:00
2024-01-27 22:12:12 +03:00
'-Wunused-function',
2023-12-04 02:53:07 +03:00
'-Wunused-variable',
'-Wunused-but-set-variable',
2023-03-24 01:47:34 +03:00
]
opt_cflags = [
'-Werror=declaration-after-statement',
'-Werror=enum-conversion',
2024-11-03 04:24:54 +03:00
'-Wno-error=enum-float-conversion', # need this for cvars
2023-03-24 01:47:34 +03:00
'-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',
2024-01-27 19:41:52 +03:00
'-fnonconst-initializers', # owcc
'-Wmissing-prototypes', # not an error yet
2023-03-24 01:47:34 +03:00
]
opt_cxxflags = [] # TODO:
2024-04-20 20:47:51 +03:00
if conf.options.DISABLE_WERROR:
opt_flags = []
opt_cflags = ['-Werror=implicit-function-declaration']
opt_cxxflags = []
2024-01-30 15:04:57 +03:00
conf.env.CFLAGS_werror = conf.filter_cflags(opt_flags + opt_cflags, cflags)
conf.env.CXXFLAGS_werror = conf.filter_cxxflags(opt_flags + opt_cxxflags, cxxflags)
2023-03-24 01:47:34 +03:00
2023-04-13 18:40:27 +03:00
conf.env.TESTS = conf.options.TESTS
2021-03-05 15:57:52 +03:00
conf.env.ENABLE_UTILS = conf.options.ENABLE_UTILS
2022-01-15 06:24:57 +03:00
conf.env.ENABLE_FUZZER = conf.options.ENABLE_FUZZER
2018-12-13 08:08:03 +03:00
conf.env.DEDICATED = conf.options.DEDICATED
2024-11-02 01:57:33 +03:00
conf.define_cond('SUPPORT_BSP2_FORMAT', conf.options.SUPPORT_BSP2_FORMAT)
2024-11-02 02:16:59 +03:00
conf.define_cond('SUPPORT_HL25_EXTENDED_STRUCTS', conf.options.SUPPORT_HL25_EXTENDED_STRUCTS)
2018-11-05 07:57:32 +05:00
2023-12-30 23:45:17 +03:00
# disable game_launch compiling on platform where it's not needed
2024-10-24 00:37:05 +03:00
conf.env.DISABLE_LAUNCHER = conf.env.DEST_OS in ['android', 'nswitch', 'psvita', 'dos'] or conf.env.MAGX or conf.env.DEDICATED or conf.env.STATIC_LINKING
2023-12-30 23:45:17 +03:00
2023-06-01 04:56:30 +03:00
if conf.env.SAILFISH == 'aurora':
conf.env.DEFAULT_RPATH = '/usr/share/su.xash.Engine/lib'
2023-09-15 20:35:51 +03:00
elif conf.env.DEST_OS == 'darwin':
conf.env.DEFAULT_RPATH = '@loader_path'
2024-01-23 21:03:10 +03:00
elif 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'
2023-06-01 04:56:30 +03:00
else:
conf.env.DEFAULT_RPATH = '$ORIGIN'
2023-03-24 01:47:34 +03:00
setattr(conf, 'refdlls', REFDLLS)
for refdll in REFDLLS:
refdll.register_env(conf.env, conf.options, conf.options.ALL_RENDERERS)
2022-09-10 20:54:34 +03:00
2022-09-11 02:12:44 +03:00
conf.env.GAMEDIR = conf.options.GAMEDIR
conf.define('XASH_GAMEDIR', conf.options.GAMEDIR)
2023-08-08 09:23:23 +03:00
conf.define_cond('XASH_ALL_SERVERS', conf.options.ALL_SERVERS)
2022-09-11 02:12:44 +03:00
2023-03-24 01:47:34 +03:00
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':
conf.check_cc(lib='dl')
conf.check_cc(lib='log')
# LIB_M added in xcompile!
elif conf.env.DEST_OS == 'win32':
2018-12-13 08:08:03 +03:00
# Common Win32 libraries
# Don't check them more than once, to save time
# Usually, they are always available
# but we need them in uselib
2022-12-17 23:16:49 +03:00
a = [ 'user32', 'shell32', 'gdi32', 'advapi32', 'dbghelp', 'psapi', 'ws2_32' ]
2021-06-14 01:13:28 +03:00
if 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)
2023-03-24 01:47:34 +03:00
else:
2023-11-22 15:25:38 -05:00
conf.check_cc(lib='dl', mandatory = False)
2023-03-24 01:47:34 +03:00
conf.check_cc(lib='m')
2018-10-24 20:12:32 +03:00
2022-02-01 19:42:38 +03:00
# set _FILE_OFFSET_BITS=64 for filesystems with 64-bit inodes
2024-04-29 05:29:53 +03:00
# must be set globally as it changes ABI
2024-05-03 15:44:35 +03:00
if conf.env.DEST_OS not in ['psvita']:
conf.check_large_file(compiler = 'c', execute = False)
2021-12-03 09:22:19 +03:00
2018-05-29 01:02:32 +03:00
# indicate if we are packaging for Linux/BSD
2021-11-25 16:52:28 +03:00
if conf.options.PACKAGING:
2023-04-24 23:12:14 +03:00
conf.env.PREFIX = conf.options.prefix
2023-06-01 04:56:30 +03:00
if conf.env.SAILFISH == "aurora":
conf.env.SHAREDIR = '${PREFIX}/share/su.xash.Engine/rodir'
elif conf.env.SAILFISH == "sailfish":
conf.env.SHAREDIR = '${PREFIX}/share/harbour-xash3d-fwgs/rodir'
else:
conf.env.SHAREDIR = '${PREFIX}/share/xash3d'
conf.env.LIBDIR += '/xash3d'
2018-05-29 01:02:32 +03:00
else:
2021-11-27 05:57:01 +03:00
conf.env.SHAREDIR = conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX
2018-10-08 22:38:59 +03:00
2022-08-19 04:03:53 +03:00
if not conf.options.BUILD_BUNDLED_DEPS:
2023-06-21 13:21:19 +03:00
# search for opus 1.4 or higher, it has fixes for custom modes
2023-06-21 13:18:57 +03:00
if conf.check_cfg(package='opus', uselib_store='opus', args='opus >= 1.4 --cflags --libs', mandatory=False):
# now try to link with export that only exists with CUSTOM_MODES defined
frag='''#include <opus_custom.h>
2023-11-01 01:35:39 +03:00
int main(void) { return !opus_custom_encoder_init((OpusCustomEncoder *)1, (const OpusCustomMode *)1, 1); }'''
2023-06-21 13:18:57 +03:00
2024-01-30 15:04:57 +03:00
if conf.check_cc(msg='Checking if opus supports custom modes', defines='CUSTOM_MODES=1', use='opus werror', fragment=frag, mandatory=False):
2023-06-21 13:18:57 +03:00
conf.env.HAVE_SYSTEM_OPUS = True
2022-08-19 04:03:53 +03:00
2024-10-07 18:11:29 +03:00
# search for bzip2
BZIP2_CHECK='''#include <bzlib.h>
int main(void) { return (int)BZ2_bzlibVersion(); }'''
if conf.check_cc(lib='bz2', fragment=BZIP2_CHECK, uselib_store='bzip2', mandatory=False):
conf.env.HAVE_SYSTEM_BZ2 = True
2021-01-29 03:33:14 +03:00
conf.define('XASH_LOW_MEMORY', conf.options.LOW_MEMORY)
2019-10-26 12:12:59 +07:00
2018-05-28 18:17:25 +03:00
for i in SUBDIRS:
2019-11-05 01:01:33 +03:00
if not i.is_enabled(conf):
2019-02-19 17:49:09 +03:00
continue
2019-04-11 00:15:48 +03:00
conf.add_subproject(i.name)
2018-05-28 18:17:25 +03:00
def build(bld):
2023-04-24 23:12:14 +03:00
# 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')
2022-10-04 03:02:49 +03:00
# don't clean QtCreator files and reconfigure saved options
bld.clean_files = bld.bldnode.ant_glob('**',
excl='*.user configuration.py .lock* *conf_check_*/** config.log %s/*' % Build.CACHE_DIR,
quiet=True, generator=True)
2021-06-14 21:19:52 +03:00
bld.load('xshlib')
2021-05-09 16:32:53 +03:00
2019-02-19 17:49:09 +03:00
for i in SUBDIRS:
2019-11-05 01:01:33 +03:00
if not i.is_enabled(bld):
2019-02-19 17:49:09 +03:00
continue
2019-04-11 00:15:48 +03:00
bld.add_subproject(i.name)
2023-04-13 18:40:27 +03:00
if bld.env.TESTS:
bld.add_post_fun(waf_unit_test.summary)
bld.add_post_fun(waf_unit_test.set_exit_code)