2018-05-28 17:17:25 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
# a1batross, mittorn, 2018
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2019-10-05 02:06:51 +02:00
|
|
|
from waflib import Logs, Context, Configure
|
2018-05-28 17:17:25 +02:00
|
|
|
import sys
|
2018-12-13 06:08:03 +01:00
|
|
|
import os
|
|
|
|
|
2018-06-17 13:30:59 +02:00
|
|
|
VERSION = '0.99'
|
|
|
|
APPNAME = 'xash3d-fwgs'
|
|
|
|
top = '.'
|
|
|
|
|
2019-10-05 02:06:51 +02:00
|
|
|
Context.Context.line_just = 55 # should fit for everything on 80x26
|
|
|
|
|
2019-02-19 15:49:09 +01:00
|
|
|
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
|
2019-11-17 21:31:25 +01:00
|
|
|
mandatory = False
|
2019-02-19 15:49:09 +01:00
|
|
|
|
2019-11-17 21:31:25 +01:00
|
|
|
def __init__(self, name, dedicated=True, singlebin=False, mandatory = False):
|
2019-02-19 15:49:09 +01:00
|
|
|
self.name = name
|
|
|
|
self.dedicated = dedicated
|
|
|
|
self.singlebin = singlebin
|
2019-11-17 21:31:25 +01:00
|
|
|
self.mandatory = mandatory
|
2019-02-19 15:49:09 +01:00
|
|
|
|
2019-11-04 23:01:33 +01:00
|
|
|
def is_enabled(self, ctx):
|
2019-11-17 21:31:25 +01:00
|
|
|
if not self.mandatory:
|
|
|
|
if self.name in ctx.env.IGNORE_PROJECTS:
|
|
|
|
self.ignore = True
|
|
|
|
|
|
|
|
if self.ignore:
|
|
|
|
return False
|
|
|
|
|
2019-11-04 23:01:33 +01:00
|
|
|
if ctx.env.SINGLE_BINARY and self.singlebin:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if ctx.env.DEST_OS == 'android' and self.singlebin:
|
|
|
|
return False
|
|
|
|
|
|
|
|
if ctx.env.DEDICATED and self.dedicated:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
2019-02-19 15:49:09 +01:00
|
|
|
SUBDIRS = [
|
2019-11-17 21:31:25 +01:00
|
|
|
Subproject('public', dedicated=False, mandatory = True),
|
2019-02-19 15:49:09 +01:00
|
|
|
Subproject('game_launch', singlebin=True),
|
2019-11-17 21:31:25 +01:00
|
|
|
Subproject('ref_gl',),
|
|
|
|
Subproject('ref_soft'),
|
2019-02-19 15:49:09 +01:00
|
|
|
Subproject('mainui'),
|
|
|
|
Subproject('vgui_support'),
|
2019-11-17 21:31:25 +01:00
|
|
|
Subproject('stub/server', dedicated=False),
|
|
|
|
Subproject('stub/client'),
|
2020-01-19 01:38:37 +01:00
|
|
|
Subproject('dllemu'),
|
|
|
|
Subproject('engine', dedicated=False),
|
2019-02-19 15:49:09 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
def subdirs():
|
|
|
|
return map(lambda x: x.name, SUBDIRS)
|
|
|
|
|
2018-05-28 17:17:25 +02:00
|
|
|
def options(opt):
|
2019-02-19 14:33:14 +01:00
|
|
|
grp = opt.add_option_group('Common options')
|
2018-12-13 06:13:27 +01:00
|
|
|
|
2019-03-26 14:25:54 +01:00
|
|
|
grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
|
2019-10-11 02:46:17 +02:00
|
|
|
help = 'build Xash Dedicated Server [default: %default]')
|
2018-11-18 21:04:30 +01:00
|
|
|
|
2019-03-26 14:25:54 +01:00
|
|
|
grp.add_option('--single-binary', action = 'store_true', dest = 'SINGLE_BINARY', default = False,
|
2019-10-23 19:47:26 +02:00
|
|
|
help = 'build single "xash" binary (always enabled for dedicated) [default: %default]')
|
2019-02-19 15:49:09 +01:00
|
|
|
|
2019-03-26 14:25:54 +01:00
|
|
|
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
|
2019-10-11 02:46:17 +02:00
|
|
|
help = 'allow targetting 64-bit engine(Linux/Windows/OSX x86 only) [default: %default]')
|
2018-11-18 21:04:30 +01:00
|
|
|
|
2019-07-27 13:34:59 +02:00
|
|
|
grp.add_option('-W', '--win-style-install', action = 'store_true', dest = 'WIN_INSTALL', default = False,
|
2019-10-11 02:46:17 +02:00
|
|
|
help = 'install like Windows build, ignore prefix, useful for development [default: %default]')
|
2018-12-13 06:13:27 +01:00
|
|
|
|
2019-03-20 00:38:13 +01:00
|
|
|
grp.add_option('--enable-bsp2', action = 'store_true', dest = 'SUPPORT_BSP2_FORMAT', default = False,
|
2019-10-11 02:46:17 +02:00
|
|
|
help = 'build engine and renderers with BSP2 map support(recommended for Quake, breaks compatibility!) [default: %default]')
|
2019-07-27 14:36:24 +02:00
|
|
|
|
2019-11-06 21:13:03 +01:00
|
|
|
grp.add_option('--low-memory-mode', action = 'store', dest = 'LOW_MEMORY', default = 0, type = 'int',
|
2019-10-26 07:12:59 +02:00
|
|
|
help = 'enable low memory mode (only for devices have <128 ram)')
|
|
|
|
|
2019-11-17 21:31:25 +01:00
|
|
|
grp.add_option('--ignore-projects', action = 'store', dest = 'IGNORE_PROJECTS', default = None,
|
|
|
|
help = 'disable selected projects from build [default: %default]')
|
|
|
|
|
2021-01-29 01:33:14 +01:00
|
|
|
opt.load('compiler_optimizations subproject')
|
2019-02-18 19:25:26 +01:00
|
|
|
|
2019-11-17 21:31:25 +01:00
|
|
|
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)
|
2019-02-19 15:49:09 +01:00
|
|
|
|
2019-11-17 21:31:25 +01:00
|
|
|
opt.load('xshlib xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test')
|
2019-02-19 14:33:14 +01:00
|
|
|
if sys.platform == 'win32':
|
2019-04-08 19:55:28 +02:00
|
|
|
opt.load('msvc msdev msvs')
|
2019-04-11 21:45:23 +02:00
|
|
|
opt.load('reconfigure')
|
|
|
|
|
2018-05-28 17:17:25 +02:00
|
|
|
def configure(conf):
|
2021-01-29 01:33:14 +01:00
|
|
|
conf.load('fwgslib reconfigure compiler_optimizations')
|
2019-11-17 21:31:25 +01:00
|
|
|
if conf.options.IGNORE_PROJECTS:
|
|
|
|
conf.env.IGNORE_PROJECTS = conf.options.IGNORE_PROJECTS.split(',')
|
|
|
|
|
2019-02-19 15:49:09 +01:00
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
# 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'
|
2018-06-17 13:30:59 +02:00
|
|
|
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
|
|
|
|
if sys.platform == 'win32':
|
2019-11-04 23:01:33 +01:00
|
|
|
conf.load('msvc msvc_pdb msdev msvs')
|
2021-01-29 01:33:14 +01:00
|
|
|
conf.load('xshlib subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install waf_unit_test enforce_pic')
|
|
|
|
|
2018-06-17 13:30:59 +02:00
|
|
|
|
2021-01-29 01:33:14 +01:00
|
|
|
enforce_pic = True # modern defaults
|
2019-11-07 02:49:49 +01:00
|
|
|
|
2019-05-06 03:11:12 +02:00
|
|
|
# modify options dictionary early
|
2019-09-19 16:07:41 +02:00
|
|
|
if conf.env.DEST_OS == 'android':
|
2019-11-04 23:01:33 +01:00
|
|
|
conf.options.NO_VGUI= True # skip vgui
|
2019-05-06 03:11:12 +02:00
|
|
|
conf.options.NANOGL = True
|
|
|
|
conf.options.GLWES = True
|
|
|
|
conf.options.GL = False
|
2021-01-29 01:33:14 +01:00
|
|
|
elif conf.env.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
|
2019-11-07 04:56:07 +01:00
|
|
|
conf.options.NO_ASYNC_RESOLVE = True
|
2019-11-07 03:07:10 +01:00
|
|
|
conf.define('XASH_SDLMAIN', 1)
|
2019-11-06 21:13:03 +01:00
|
|
|
enforce_pic = False
|
|
|
|
|
2021-01-29 01:33:14 +01:00
|
|
|
if conf.env.STATIC_LINKING:
|
|
|
|
enforce_pic = False # PIC may break full static builds
|
|
|
|
|
|
|
|
conf.check_pic(enforce_pic)
|
2019-11-06 21:13:03 +01:00
|
|
|
|
2019-05-31 01:59:45 +02:00
|
|
|
# We restrict 64-bit builds ONLY for Win/Linux/OSX running on Intel architecture
|
|
|
|
# Because compatibility with original GoldSrc
|
2019-11-04 23:01:33 +01:00
|
|
|
if conf.env.DEST_OS in ['win32', 'linux', 'darwin'] and conf.env.DEST_CPU == 'x86_64':
|
2019-10-18 04:06:10 +02:00
|
|
|
conf.env.BIT32_MANDATORY = not conf.options.ALLOW64
|
|
|
|
if not conf.env.BIT32_MANDATORY:
|
2019-05-31 01:59:45 +02:00
|
|
|
Logs.info('WARNING: will build engine for 32-bit target')
|
|
|
|
else:
|
2019-10-18 04:06:10 +02:00
|
|
|
conf.env.BIT32_MANDATORY = False
|
2019-11-04 23:01:33 +01:00
|
|
|
|
2019-05-12 02:03:34 +02:00
|
|
|
conf.load('force_32bit')
|
2018-12-13 06:13:27 +01:00
|
|
|
|
2019-09-27 23:23:21 +02:00
|
|
|
compiler_optional_flags = [
|
2019-12-03 00:35:23 +01:00
|
|
|
# '-Wall', '-Wextra', '-Wpedantic',
|
2019-09-27 23:23:21 +02:00
|
|
|
'-fdiagnostics-color=always',
|
|
|
|
'-Werror=return-type',
|
|
|
|
'-Werror=parentheses',
|
2019-10-05 02:06:51 +02:00
|
|
|
'-Werror=vla',
|
|
|
|
'-Werror=tautological-compare',
|
|
|
|
'-Werror=duplicated-cond',
|
|
|
|
'-Werror=duplicated-branches', # BEWARE: buggy
|
|
|
|
'-Werror=bool-compare',
|
|
|
|
'-Werror=bool-operation',
|
2020-11-18 10:15:54 +01:00
|
|
|
'-Wcast-align',
|
2020-09-29 14:42:43 +02:00
|
|
|
'-Werror=cast-align=strict', # =strict is for GCC >=8
|
|
|
|
'-Werror=packed',
|
|
|
|
'-Werror=packed-not-aligned',
|
2020-05-12 23:24:50 +02:00
|
|
|
'-Wuninitialized', # older GCC versions have -Wmaybe-uninitialized enabled by this switch, which is not accurate
|
|
|
|
# so just warn, not error
|
2019-12-24 01:56:07 +01:00
|
|
|
'-Winit-self',
|
2019-12-23 04:48:17 +01:00
|
|
|
'-Werror=implicit-fallthrough=2', # clang incompatible without "=2"
|
2019-11-04 23:01:33 +01:00
|
|
|
# '-Wdouble-promotion', # disable warning flood
|
2019-10-05 02:06:51 +02:00
|
|
|
'-Wstrict-aliasing',
|
|
|
|
]
|
|
|
|
|
|
|
|
c_compiler_optional_flags = [
|
2019-12-02 00:13:23 +01:00
|
|
|
'-Werror=incompatible-pointer-types',
|
2019-10-18 05:20:27 +02:00
|
|
|
'-Werror=implicit-function-declaration',
|
|
|
|
'-Werror=int-conversion',
|
2019-10-05 02:06:51 +02:00
|
|
|
'-Werror=implicit-int',
|
|
|
|
'-Werror=strict-prototypes',
|
|
|
|
'-Werror=old-style-declaration',
|
|
|
|
'-Werror=old-style-definition',
|
2019-12-23 04:48:17 +01:00
|
|
|
'-Werror=declaration-after-statement',
|
2020-02-08 17:13:46 +01:00
|
|
|
'-Werror=enum-conversion',
|
|
|
|
'-fnonconst-initializers' # owcc
|
2019-09-27 23:23:21 +02:00
|
|
|
]
|
|
|
|
|
2021-01-29 01:33:14 +01:00
|
|
|
cflags, linkflags = conf.get_optimization_flags()
|
2019-10-11 03:12:07 +02:00
|
|
|
|
|
|
|
# And here C++ flags starts to be treated separately
|
|
|
|
cxxflags = list(cflags)
|
|
|
|
if conf.env.COMPILER_CC != 'msvc':
|
2021-01-29 01:33:14 +01:00
|
|
|
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')
|
2019-12-03 00:35:23 +01:00
|
|
|
|
|
|
|
conf.env.append_unique('CFLAGS', cflags)
|
|
|
|
conf.env.append_unique('CXXFLAGS', cxxflags)
|
|
|
|
conf.env.append_unique('LINKFLAGS', linkflags)
|
2019-10-05 02:06:51 +02:00
|
|
|
|
2019-10-11 06:40:40 +02:00
|
|
|
cxxflags += conf.filter_cxxflags(compiler_optional_flags, cflags)
|
2019-10-18 05:20:27 +02:00
|
|
|
cflags += conf.filter_cflags(compiler_optional_flags + c_compiler_optional_flags, cflags)
|
2019-09-27 23:59:09 +02:00
|
|
|
|
2019-10-11 03:12:07 +02:00
|
|
|
conf.env.append_unique('CFLAGS', cflags)
|
|
|
|
conf.env.append_unique('CXXFLAGS', cxxflags)
|
|
|
|
conf.env.append_unique('LINKFLAGS', linkflags)
|
2018-10-24 19:12:32 +02:00
|
|
|
|
2019-10-06 05:34:34 +02:00
|
|
|
# check if we can use C99 tgmath
|
|
|
|
if conf.check_cc(header_name='tgmath.h', mandatory=False):
|
2019-11-05 07:41:26 +01:00
|
|
|
if conf.env.COMPILER_CC == 'msvc':
|
|
|
|
conf.define('_CRT_SILENCE_NONCONFORMING_TGMATH_H', 1)
|
2019-10-18 05:46:46 +02:00
|
|
|
tgmath_usable = conf.check_cc(fragment='''#include<tgmath.h>
|
2019-10-18 06:02:59 +02:00
|
|
|
int main(void){ return (int)sin(2.0f); }''',
|
|
|
|
msg='Checking if tgmath.h is usable', mandatory=False)
|
2019-10-18 05:46:46 +02:00
|
|
|
conf.define_cond('HAVE_TGMATH_H', tgmath_usable)
|
|
|
|
else:
|
|
|
|
conf.undefine('HAVE_TGMATH_H')
|
2019-10-05 02:10:13 +02:00
|
|
|
|
2020-03-29 23:46:58 +02:00
|
|
|
# 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')
|
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
conf.env.DEDICATED = conf.options.DEDICATED
|
2019-02-19 15:49:09 +01:00
|
|
|
conf.env.SINGLE_BINARY = conf.options.SINGLE_BINARY or conf.env.DEDICATED
|
2020-02-08 17:13:46 +01:00
|
|
|
if conf.env.DEST_OS == 'dos':
|
|
|
|
conf.env.SINGLE_BINARY = True
|
2018-11-05 03:57:32 +01:00
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
if conf.env.DEST_OS != 'win32':
|
2019-11-04 23:01:33 +01:00
|
|
|
conf.check_cc(lib='dl', mandatory=False)
|
2019-09-19 16:07:41 +02:00
|
|
|
|
2019-11-04 23:01:33 +01:00
|
|
|
if not conf.env.LIB_M: # HACK: already added in xcompile!
|
|
|
|
conf.check_cc(lib='m')
|
2018-12-13 06:08:03 +01:00
|
|
|
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
|
2019-10-18 04:11:18 +02:00
|
|
|
a = map(lambda x: {
|
2019-10-18 05:35:05 +02:00
|
|
|
# 'features': 'c',
|
|
|
|
# 'message': '...' + x,
|
2019-10-18 04:41:56 +02:00
|
|
|
'lib': x,
|
2019-10-18 05:35:05 +02:00
|
|
|
# 'uselib_store': x.upper(),
|
|
|
|
# 'global_define': False,
|
2019-10-18 04:11:18 +02:00
|
|
|
}, [
|
|
|
|
'user32',
|
|
|
|
'shell32',
|
|
|
|
'gdi32',
|
|
|
|
'advapi32',
|
|
|
|
'dbghelp',
|
|
|
|
'psapi',
|
|
|
|
'ws2_32'
|
|
|
|
])
|
|
|
|
|
2019-10-18 05:35:05 +02:00
|
|
|
for i in a:
|
|
|
|
conf.check_cc(**i)
|
|
|
|
|
|
|
|
# conf.multicheck(*a, run_all_tests = True, mandatory = True)
|
2018-10-24 19:12:32 +02:00
|
|
|
|
2018-05-29 00:02:32 +02:00
|
|
|
# indicate if we are packaging for Linux/BSD
|
2019-11-04 23:01:33 +01:00
|
|
|
if not conf.options.WIN_INSTALL and conf.env.DEST_OS not in ['win32', 'darwin', 'android']:
|
2018-05-29 00:02:32 +02:00
|
|
|
conf.env.LIBDIR = conf.env.BINDIR = '${PREFIX}/lib/xash3d'
|
|
|
|
else:
|
2018-10-08 21:38:59 +02:00
|
|
|
conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX
|
|
|
|
|
2019-10-11 02:10:08 +02:00
|
|
|
conf.define('XASH_BUILD_COMMIT', conf.env.GIT_VERSION if conf.env.GIT_VERSION else 'notset')
|
2021-01-29 01:33:14 +01:00
|
|
|
conf.define('XASH_LOW_MEMORY', conf.options.LOW_MEMORY)
|
2019-10-26 07:12:59 +02:00
|
|
|
|
2018-05-28 17:17:25 +02:00
|
|
|
for i in SUBDIRS:
|
2019-11-04 23:01:33 +01:00
|
|
|
if not i.is_enabled(conf):
|
2019-02-19 15:49:09 +01:00
|
|
|
continue
|
|
|
|
|
2019-04-10 23:15:48 +02:00
|
|
|
conf.add_subproject(i.name)
|
2018-05-28 17:17:25 +02:00
|
|
|
|
|
|
|
def build(bld):
|
2019-11-17 21:31:25 +01:00
|
|
|
bld.load('xshlib')
|
2019-02-19 15:49:09 +01:00
|
|
|
for i in SUBDIRS:
|
2019-11-04 23:01:33 +01:00
|
|
|
if not i.is_enabled(bld):
|
2019-02-19 15:49:09 +01:00
|
|
|
continue
|
|
|
|
|
2019-04-10 23:15:48 +02:00
|
|
|
bld.add_subproject(i.name)
|