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
|
|
|
|
|
|
|
|
sys.path.append(os.path.realpath('scripts/waflib'))
|
|
|
|
# print(sys.path)
|
|
|
|
import fwgslib
|
2018-05-28 17:17:25 +02:00
|
|
|
|
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 = [
|
|
|
|
Subproject('engine', dedicated=False),
|
|
|
|
Subproject('game_launch', singlebin=True),
|
|
|
|
Subproject('mainui'),
|
|
|
|
Subproject('vgui_support'),
|
|
|
|
]
|
|
|
|
|
|
|
|
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-02-19 14:33:14 +01:00
|
|
|
grp.add_option(
|
2018-12-13 06:08:03 +01:00
|
|
|
'--build-type', action='store', type='string', dest='BUILD_TYPE', default = None,
|
|
|
|
help = 'build type: debug, release or none(custom flags)')
|
2018-11-18 21:04:30 +01:00
|
|
|
|
2019-02-19 14:33:14 +01:00
|
|
|
grp.add_option(
|
2018-06-17 13:30:59 +02:00
|
|
|
'--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-02-19 15:49:09 +01:00
|
|
|
grp.add_option(
|
|
|
|
'--single-binary', action = 'store_true', dest = 'SINGLE_BINARY', default = False,
|
|
|
|
help = 'build single "xash" binary instead of xash.dll/libxash.so (forced for dedicated)')
|
|
|
|
|
2019-02-19 14:33:14 +01:00
|
|
|
grp.add_option(
|
2018-06-17 13:30:59 +02:00
|
|
|
'--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-02-19 14:33:14 +01:00
|
|
|
grp.add_option(
|
2018-05-29 00:02:32 +02:00
|
|
|
'--win-style-install', action = 'store_true', dest = 'WIN_INSTALL', default = False,
|
|
|
|
help = 'install like Windows build, ignore prefix, useful for development')
|
2018-12-13 06:13:27 +01:00
|
|
|
|
2019-02-19 15:49:09 +01:00
|
|
|
grp.add_option(
|
|
|
|
'--skip-subprojects', action='store', type = 'string', dest = 'SKIP_SUBDIRS', default=None,
|
|
|
|
help = 'don\'t recurse into specified subprojects. Current subdirs: ' + str(subdirs()))
|
|
|
|
|
|
|
|
for i in SUBDIRS:
|
|
|
|
if not os.path.isfile(os.path.join(i.name, 'wscript')):
|
|
|
|
# HACKHACK: this way we get warning message right in the help
|
|
|
|
# so this just becomes more noticeable
|
|
|
|
opt.add_option_group('Cannot find wscript in ' + i.name + '. You probably missed submodule update')
|
|
|
|
else: opt.recurse(i.name)
|
|
|
|
|
2019-02-19 14:33:14 +01:00
|
|
|
opt.load('xcompile compiler_cxx compiler_c')
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
opt.load('msvc msvs')
|
2018-06-17 13:30:59 +02:00
|
|
|
|
2019-02-19 15:49:09 +01:00
|
|
|
def set_ignored_subdirs(subdirs):
|
|
|
|
for i in SUBDIRS:
|
|
|
|
if i.ignore:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if i.name in subdirs:
|
|
|
|
i.ignore = True
|
|
|
|
|
2018-05-28 17:17:25 +02:00
|
|
|
def configure(conf):
|
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')
|
|
|
|
conf.fatal('Please set a build type, for example "--build-type=release"')
|
|
|
|
elif not conf.options.BUILD_TYPE in ['release', 'debug', 'none']:
|
|
|
|
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-02-19 15:49:09 +01:00
|
|
|
# skip some subdirectories, if requested
|
|
|
|
if conf.options.SKIP_SUBDIRS:
|
|
|
|
skip_subdirs = conf.options.SKIP_SUBDIRS.split(',')
|
|
|
|
set_ignored_subdirs(skip_subdirs)
|
|
|
|
|
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
|
2019-01-13 14:46:12 +01:00
|
|
|
conf.load('xcompile compiler_c compiler_cxx gitversion clang_compilation_database')
|
2018-06-17 13:30:59 +02:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
conf.load('msvc msvs')
|
|
|
|
|
2018-12-20 07:48:22 +01:00
|
|
|
# print(conf.options.ALLOW64)
|
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
conf.env.BIT32_MANDATORY = not conf.options.ALLOW64
|
|
|
|
conf.env.BIT32_ALLOW64 = conf.options.ALLOW64
|
|
|
|
conf.load('force_32bit')
|
2018-12-13 06:13:27 +01:00
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
if conf.env.DEST_SIZEOF_VOID_P == 4:
|
|
|
|
Logs.info('NOTE: will build engine for 32-bit target')
|
|
|
|
else:
|
|
|
|
Logs.warn('WARNING: 64-bit engine may be unstable')
|
2018-10-24 19:12:32 +02: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']
|
2018-11-18 14:04:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compiler_c_cxx_flags = {
|
2018-11-18 21:04:30 +01:00
|
|
|
'common': {
|
|
|
|
'msvc': ['/D_USING_V110_SDK71_'],
|
2019-01-07 01:59:56 +01:00
|
|
|
'default': ['-g', '-Werror=implicit-function-declaration']
|
2018-11-18 14:04:52 +01:00
|
|
|
},
|
|
|
|
'release': {
|
2018-11-18 21:04:30 +01:00
|
|
|
'msvc': ['/Zi', '/O2'],
|
2018-11-18 14:04:52 +01:00
|
|
|
'default': ['-O3']
|
|
|
|
},
|
|
|
|
'debug': {
|
2018-11-18 21:04:30 +01:00
|
|
|
'msvc': ['/Z7'],
|
2018-11-18 14:04:52 +01:00
|
|
|
'clang': ['-O0', '-gdwarf-2'],
|
|
|
|
'default': ['-O0']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 06:08:03 +01:00
|
|
|
conf.env.append_unique('CFLAGS', fwgslib.get_flags_by_type(
|
2018-11-18 14:04:52 +01:00
|
|
|
compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
|
2018-12-13 06:08:03 +01:00
|
|
|
conf.env.append_unique('CXXFLAGS', fwgslib.get_flags_by_type(
|
2018-11-18 14:04:52 +01:00
|
|
|
compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
|
2018-12-13 06:08:03 +01:00
|
|
|
conf.env.append_unique('LINKFLAGS', fwgslib.get_flags_by_type(
|
2018-11-18 14:04:52 +01: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':
|
2018-12-16 15:10:01 +01:00
|
|
|
conf.check_cc( lib='m' )
|
2018-12-20 07:48:22 +01:00
|
|
|
if conf.env.DEST_OS2 != 'android':
|
|
|
|
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' )
|
2018-10-24 19:12:32 +02:00
|
|
|
|
|
|
|
|
2018-05-29 00:02:32 +02:00
|
|
|
# indicate if we are packaging for Linux/BSD
|
|
|
|
if(not conf.options.WIN_INSTALL and
|
|
|
|
conf.env.DEST_OS != 'win32' and
|
|
|
|
conf.env.DEST_OS != 'darwin'):
|
|
|
|
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
|
|
|
|
|
|
|
|
if conf.env.DEDICATED and not i.dedicated:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if i.ignore:
|
|
|
|
continue
|
|
|
|
|
|
|
|
conf.setenv(i.name, conf.env) # derive new env from global one
|
|
|
|
conf.env.ENVNAME = i.name
|
|
|
|
conf.msg(msg='--> ' + i.name, result='in progress', color='BLUE')
|
2018-05-28 17:17:25 +02:00
|
|
|
# configure in standalone env
|
2019-02-19 15:49:09 +01:00
|
|
|
conf.recurse(i.name)
|
|
|
|
conf.msg(msg='<-- ' + i.name, result='done', color='BLUE')
|
2018-05-28 17:17:25 +02:00
|
|
|
conf.setenv('')
|
|
|
|
|
|
|
|
def build(bld):
|
2019-02-19 15:49:09 +01:00
|
|
|
for i in SUBDIRS:
|
|
|
|
if bld.env.SINGLE_BINARY and i.singlebin:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if bld.env.DEDICATED and not i.dedicated:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if i.ignore:
|
|
|
|
continue
|
|
|
|
|
|
|
|
bld.recurse(i.name)
|