2018-05-28 17:17:25 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
# a1batross, mittorn, 2018
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2019-01-07 01:59:56 +01:00
|
|
|
from waflib import Logs
|
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-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
|
|
|
|
|
|
|
|
def __init__(self, name, dedicated=True, singlebin=False):
|
|
|
|
self.name = name
|
|
|
|
self.dedicated = dedicated
|
|
|
|
self.singlebin = singlebin
|
|
|
|
|
|
|
|
SUBDIRS = [
|
2019-03-20 00:38:13 +01:00
|
|
|
Subproject('public', dedicated=False),
|
2019-02-19 15:49:09 +01:00
|
|
|
Subproject('game_launch', singlebin=True),
|
2019-03-21 15:47:16 +01:00
|
|
|
Subproject('ref_gl'),
|
2019-05-06 03:11:12 +02:00
|
|
|
# Subproject('ref_soft'),
|
2019-02-19 15:49:09 +01:00
|
|
|
Subproject('mainui'),
|
|
|
|
Subproject('vgui_support'),
|
2019-08-09 02:07:56 +02:00
|
|
|
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('-T', '--build-type', action='store', dest='BUILD_TYPE', default = None,
|
2018-12-13 06:08:03 +01:00
|
|
|
help = 'build type: debug, release or none(custom flags)')
|
2018-11-18 21:04:30 +01:00
|
|
|
|
2019-03-26 14:25:54 +01:00
|
|
|
grp.add_option('-d', '--dedicated', action = 'store_true', dest = 'DEDICATED', default = False,
|
2018-05-28 17:17:25 +02:00
|
|
|
help = 'build Xash Dedicated Server(XashDS)')
|
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-02-19 15:49:09 +01:00
|
|
|
help = 'build single "xash" binary instead of xash.dll/libxash.so (forced for dedicated)')
|
|
|
|
|
2019-03-26 14:25:54 +01:00
|
|
|
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
|
2018-05-28 17:17:25 +02:00
|
|
|
help = 'allow targetting 64-bit engine')
|
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,
|
2018-05-29 00:02:32 +02:00
|
|
|
help = 'install like Windows build, ignore prefix, useful for development')
|
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-02-18 19:25:26 +01:00
|
|
|
help = 'build engine and renderers with BSP2 map support(recommended for Quake, breaks compability!)')
|
2019-07-27 14:36:24 +02:00
|
|
|
|
2019-04-10 23:15:48 +02:00
|
|
|
opt.load('subproject')
|
2019-02-18 19:25:26 +01:00
|
|
|
|
2019-04-10 23:15:48 +02:00
|
|
|
opt.add_subproject(subdirs())
|
2019-02-19 15:49:09 +01:00
|
|
|
|
2019-09-11 18:59:59 +02:00
|
|
|
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install')
|
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-06-17 13:30:59 +02:00
|
|
|
|
2019-09-27 23:23:21 +02:00
|
|
|
def filter_cflags(conf, flags, required_flags, cxx):
|
|
|
|
supported_flags = []
|
2019-09-27 23:36:08 +02:00
|
|
|
check_flags = required_flags + ['-Werror']
|
2019-09-27 23:23:21 +02:00
|
|
|
conf.msg('Detecting supported flags for %s' % ('C++' if cxx else 'C'),'...')
|
|
|
|
|
|
|
|
for flag in flags:
|
|
|
|
conf.start_msg('Checking for %s' % flag)
|
|
|
|
try:
|
|
|
|
if cxx:
|
2019-09-27 23:36:08 +02:00
|
|
|
conf.check_cxx(cxxflags = [flag] + check_flags)
|
2019-09-27 23:23:21 +02:00
|
|
|
else:
|
2019-09-27 23:36:08 +02:00
|
|
|
conf.check_cc(cflags = [flag] + check_flags)
|
2019-09-27 23:23:21 +02:00
|
|
|
except conf.errors.ConfigurationError:
|
|
|
|
conf.end_msg('no', color='YELLOW')
|
|
|
|
else:
|
|
|
|
conf.end_msg('yes')
|
|
|
|
supported_flags.append(flag)
|
|
|
|
|
|
|
|
return supported_flags
|
|
|
|
|
2018-05-28 17:17:25 +02:00
|
|
|
def configure(conf):
|
2019-06-06 02:26:45 +02:00
|
|
|
conf.load('fwgslib reconfigure')
|
2018-11-18 14:04:52 +01:00
|
|
|
conf.start_msg('Build type')
|
|
|
|
if conf.options.BUILD_TYPE == None:
|
|
|
|
conf.end_msg('not set', color='RED')
|
2019-03-26 14:25:54 +01:00
|
|
|
conf.fatal('Please set a build type, for example "-T release"')
|
2019-04-11 19:19:40 +02:00
|
|
|
elif not conf.options.BUILD_TYPE in ['fast', 'release', 'debug', 'nooptimize', 'sanitize', 'none']:
|
2018-11-18 14:04:52 +01:00
|
|
|
conf.end_msg(conf.options.BUILD_TYPE, color='RED')
|
|
|
|
conf.fatal('Invalid build type. Valid are "debug", "release" or "none"')
|
|
|
|
conf.end_msg(conf.options.BUILD_TYPE)
|
|
|
|
|
2019-04-11 19:19:40 +02:00
|
|
|
# -march=native should not be used
|
|
|
|
if conf.options.BUILD_TYPE == 'fast':
|
2019-07-09 01:27:59 +02:00
|
|
|
Logs.warn('WARNING: \'fast\' build type should not be used in release builds')
|
2019-04-11 19:19:40 +02:00
|
|
|
|
2019-04-10 23:15:48 +02:00
|
|
|
conf.load('subproject')
|
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-06-26 15:41:58 +02:00
|
|
|
conf.load('msvc msvcfix msdev msvs')
|
2019-09-11 17:47:44 +02:00
|
|
|
conf.load('xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install')
|
2018-06-17 13:30:59 +02:00
|
|
|
|
2019-05-28 03:12:02 +02:00
|
|
|
# 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')
|
|
|
|
|
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-05-06 03:11:12 +02:00
|
|
|
conf.options.ALLOW64 = True # skip pointer length check
|
|
|
|
conf.options.NO_VGUI = True # skip vgui
|
|
|
|
conf.options.NANOGL = True
|
|
|
|
conf.options.GLWES = True
|
|
|
|
conf.options.GL = False
|
|
|
|
|
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
|
|
|
|
if conf.env.DEST_OS in ['win32', 'linux', 'darwin'] and conf.env.DEST_CPU in ['x86_64']:
|
|
|
|
conf.env.BIT32_ALLOW64 = conf.options.ALLOW64
|
|
|
|
if not conf.env.BIT32_ALLOW64:
|
|
|
|
Logs.info('WARNING: will build engine for 32-bit target')
|
|
|
|
else:
|
|
|
|
conf.env.BIT32_ALLOW64 = True
|
|
|
|
conf.env.BIT32_MANDATORY = not conf.env.BIT32_ALLOW64
|
2019-05-12 02:03:34 +02:00
|
|
|
conf.load('force_32bit')
|
2019-09-19 16:07:41 +02:00
|
|
|
if conf.env.DEST_OS != 'android' and not conf.options.DEDICATED:
|
2019-05-12 02:03:34 +02:00
|
|
|
conf.load('sdl2')
|
2018-12-13 06:13:27 +01:00
|
|
|
|
2018-11-18 14:04:52 +01:00
|
|
|
linker_flags = {
|
2018-11-18 21:04:30 +01:00
|
|
|
'common': {
|
2018-12-13 06:08:03 +01:00
|
|
|
'msvc': ['/DEBUG'], # always create PDB, doesn't affect result binaries
|
2018-12-17 00:35:37 +01:00
|
|
|
'gcc': ['-Wl,--no-undefined']
|
2019-04-11 19:19:40 +02:00
|
|
|
},
|
|
|
|
'sanitize': {
|
2019-07-11 02:59:20 +02:00
|
|
|
'clang': ['-fsanitize=undefined', '-fsanitize=address'],
|
2019-04-11 19:19:40 +02:00
|
|
|
'gcc': ['-fsanitize=undefined', '-fsanitize=address'],
|
2018-11-18 14:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compiler_c_cxx_flags = {
|
2018-11-18 21:04:30 +01:00
|
|
|
'common': {
|
2019-06-12 23:49:27 +02:00
|
|
|
# disable thread-safe local static initialization for C++11 code, as it cause crashes on Windows XP
|
2019-07-06 23:15:52 +02:00
|
|
|
'msvc': ['/D_USING_V110_SDK71_', '/Zi', '/FS', '/Zc:threadSafeInit-', '/MT'],
|
2019-09-27 23:23:21 +02:00
|
|
|
'clang': ['-g', '-gdwarf-2', '-fvisibility=hidden'],
|
|
|
|
'gcc': ['-g', '-fvisibility=hidden']
|
2019-04-11 19:19:40 +02:00
|
|
|
},
|
|
|
|
'fast': {
|
|
|
|
'msvc': ['/O2', '/Oy'], #todo: check /GL /LTCG
|
|
|
|
'gcc': ['-Ofast', '-march=native', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer'],
|
2019-07-11 02:59:20 +02:00
|
|
|
'clang': ['-Ofast', '-march=native'],
|
2019-04-11 19:19:40 +02:00
|
|
|
'default': ['-O3']
|
2018-11-18 14:04:52 +01:00
|
|
|
},
|
|
|
|
'release': {
|
2019-04-11 19:19:40 +02:00
|
|
|
'msvc': ['/O2'],
|
2018-11-18 14:04:52 +01:00
|
|
|
'default': ['-O3']
|
|
|
|
},
|
|
|
|
'debug': {
|
2019-04-11 19:19:40 +02:00
|
|
|
'msvc': ['/O1'],
|
|
|
|
'gcc': ['-Og'],
|
|
|
|
'default': ['-O1']
|
|
|
|
},
|
|
|
|
'sanitize': {
|
|
|
|
'msvc': ['/Od', '/RTC1'],
|
|
|
|
'gcc': ['-Og', '-fsanitize=undefined', '-fsanitize=address'],
|
2019-07-26 16:10:47 +02:00
|
|
|
'clang': ['-O0', '-fsanitize=undefined', '-fsanitize=address'],
|
|
|
|
'default': ['-O0']
|
2019-04-11 19:19:40 +02:00
|
|
|
},
|
|
|
|
'nooptimize': {
|
|
|
|
'msvc': ['/Od'],
|
2018-11-18 14:04:52 +01:00
|
|
|
'default': ['-O0']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-27 23:23:21 +02:00
|
|
|
compiler_optional_flags = [
|
|
|
|
'-fdiagnostics-color=always',
|
|
|
|
'-Werror=implicit-function-declaration',
|
|
|
|
'-Werror=int-conversion',
|
|
|
|
'-Werror=return-type',
|
|
|
|
'-Werror=parentheses',
|
|
|
|
]
|
|
|
|
|
|
|
|
cflags = conf.get_flags_by_type(compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC)
|
2019-09-27 23:59:09 +02:00
|
|
|
if conf.env.COMPILER_CC == 'msvc':
|
|
|
|
conf.env.append_unique('CFLAGS', cflags)
|
|
|
|
conf.env.append_unique('CXXFLAGS', cflags)
|
|
|
|
else:
|
|
|
|
conf.check_cc(cflags=cflags, msg= 'Checking for required C flags')
|
|
|
|
conf.check_cxx(cxxflags=cflags, msg= 'Checking for required C++ flags')
|
2019-09-27 23:23:21 +02:00
|
|
|
|
2019-09-27 23:59:09 +02:00
|
|
|
conf.env.append_unique('CFLAGS', cflags + filter_cflags(conf, compiler_optional_flags, cflags, False))
|
|
|
|
conf.env.append_unique('CXXFLAGS', cflags + filter_cflags(conf, compiler_optional_flags, cflags, True))
|
|
|
|
|
2019-06-06 02:26:45 +02:00
|
|
|
conf.env.append_unique('LINKFLAGS', conf.get_flags_by_type(
|
2019-07-09 01:27:59 +02:00
|
|
|
linker_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
|
2018-10-24 19:12:32 +02:00
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
conf.env.DEDICATED = conf.options.DEDICATED
|
2019-02-19 15:49:09 +01:00
|
|
|
# we don't need game launcher on dedicated
|
|
|
|
conf.env.SINGLE_BINARY = conf.options.SINGLE_BINARY or conf.env.DEDICATED
|
2018-12-13 06:08:03 +01:00
|
|
|
if conf.env.DEST_OS == 'linux':
|
2018-12-16 15:10:01 +01:00
|
|
|
conf.check_cc( lib='dl' )
|
2018-11-05 03:57:32 +01:00
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
if conf.env.DEST_OS != 'win32':
|
2019-09-19 16:07:41 +02:00
|
|
|
if not conf.env.LIB_M: # HACK: already added in xcompile!
|
|
|
|
conf.check_cc( lib='m' )
|
|
|
|
|
|
|
|
if conf.env.DEST_OS != 'android': # Android has pthread directly in libc
|
2018-12-20 07:48:22 +01:00
|
|
|
conf.check_cc( lib='pthread' )
|
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
|
2018-12-16 15:10:01 +01:00
|
|
|
conf.check_cc( lib='user32' )
|
|
|
|
conf.check_cc( lib='shell32' )
|
|
|
|
conf.check_cc( lib='gdi32' )
|
|
|
|
conf.check_cc( lib='advapi32' )
|
|
|
|
conf.check_cc( lib='dbghelp' )
|
|
|
|
conf.check_cc( lib='psapi' )
|
2019-06-29 21:01:32 +02:00
|
|
|
conf.check_cc( lib='ws2_32' )
|
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-03-21 15:47:16 +01:00
|
|
|
if(not conf.options.WIN_INSTALL and
|
2019-09-19 16:07:41 +02:00
|
|
|
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-01-13 14:46:50 +01:00
|
|
|
conf.env.append_unique('DEFINES', 'XASH_BUILD_COMMIT="{0}"'.format(conf.env.GIT_VERSION if conf.env.GIT_VERSION else 'notset'))
|
2018-11-18 23:19:24 +01:00
|
|
|
|
2018-05-28 17:17:25 +02:00
|
|
|
for i in SUBDIRS:
|
2019-02-19 15:49:09 +01:00
|
|
|
if conf.env.SINGLE_BINARY and i.singlebin:
|
|
|
|
continue
|
|
|
|
|
2019-09-19 16:07:41 +02:00
|
|
|
if conf.env.DEST_OS == 'android' and i.singlebin:
|
2019-05-06 03:38:11 +02:00
|
|
|
continue
|
|
|
|
|
2019-03-03 01:38:02 +01:00
|
|
|
if conf.env.DEDICATED and i.dedicated:
|
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-02-19 15:49:09 +01:00
|
|
|
for i in SUBDIRS:
|
|
|
|
if bld.env.SINGLE_BINARY and i.singlebin:
|
|
|
|
continue
|
|
|
|
|
2019-09-19 16:07:41 +02:00
|
|
|
if bld.env.DEST_OS == 'android' and i.singlebin:
|
2019-05-06 03:38:11 +02:00
|
|
|
continue
|
|
|
|
|
2019-03-03 01:38:02 +01:00
|
|
|
if bld.env.DEDICATED and i.dedicated:
|
2019-02-19 15:49:09 +01:00
|
|
|
continue
|
|
|
|
|
2019-04-10 23:15:48 +02:00
|
|
|
bld.add_subproject(i.name)
|