2019-05-03 18:19:39 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
# a1batross, mittorn, 2018
|
|
|
|
|
|
|
|
from __future__ import print_function
|
|
|
|
from waflib import Logs
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
sys.path.append(os.path.realpath('scripts/waflib'))
|
|
|
|
|
|
|
|
VERSION = '2.4'
|
|
|
|
APPNAME = 'hlsdk-xash3d'
|
|
|
|
top = '.'
|
|
|
|
|
|
|
|
def options(opt):
|
|
|
|
grp = opt.add_option_group('Common options')
|
|
|
|
|
|
|
|
grp.add_option('-T', '--build-type', action='store', dest='BUILD_TYPE', default = None,
|
|
|
|
help = 'build type: debug, release or none(custom flags)')
|
|
|
|
|
|
|
|
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
|
|
|
|
help = 'allow targetting 64-bit game dlls')
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
grp.add_option('--enable-voicemgr', action = 'store_true', dest = 'VOICEMGR', default = False,
|
|
|
|
help = 'enable voice manager')
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
grp.add_option('--enable-goldsrc-support', action = 'store_true', dest = 'GOLDSRC', default = False,
|
|
|
|
help = 'enable GoldSource engine support')
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
opt.recurse('cl_dll dlls')
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-09-11 19:44:05 +02:00
|
|
|
opt.load('xcompile compiler_cxx compiler_c clang_compilation_database strip_on_install')
|
2019-05-03 18:19:39 +02:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
opt.load('msvc msdev')
|
|
|
|
opt.load('reconfigure')
|
|
|
|
|
|
|
|
|
|
|
|
def configure(conf):
|
|
|
|
# Configuration
|
|
|
|
conf.env.GAMEDIR = 'valve'
|
|
|
|
conf.env.CLIENT_DIR = 'cl_dlls'
|
|
|
|
conf.env.SERVER_DIR = 'dlls'
|
|
|
|
conf.env.SERVER_NAME = 'hl'
|
|
|
|
conf.env.PREFIX = ''
|
|
|
|
|
|
|
|
conf.load('reconfigure')
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02: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 "-T release"')
|
|
|
|
elif not conf.options.BUILD_TYPE in ['fast', 'release', 'debug', 'nooptimize', 'sanitize', '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)
|
|
|
|
|
|
|
|
# -march=native should not be used
|
|
|
|
if conf.options.BUILD_TYPE == 'fast':
|
|
|
|
Logs.warn('WARNING: \'fast\' build type should not be used in release builds')
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
conf.env.VOICEMGR = conf.options.VOICEMGR
|
|
|
|
conf.env.GOLDSRC = conf.options.GOLDSRC
|
|
|
|
|
|
|
|
# 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'
|
|
|
|
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
conf.load('msvc msdev')
|
2019-09-11 19:44:05 +02:00
|
|
|
conf.load('xcompile compiler_c compiler_cxx strip_on_install')
|
2019-05-03 18:19:39 +02:00
|
|
|
|
2019-09-19 16:18:57 +02:00
|
|
|
if conf.env.DEST_OS == 'android':
|
2019-05-06 03:13:09 +02:00
|
|
|
conf.options.ALLOW64 = True
|
|
|
|
conf.options.GOLDSRC = False
|
|
|
|
conf.env.SERVER_NAME = 'server' # can't be any other name, until specified
|
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
# print(conf.options.ALLOW64)
|
|
|
|
|
|
|
|
conf.env.BIT32_MANDATORY = not conf.options.ALLOW64
|
|
|
|
conf.env.BIT32_ALLOW64 = conf.options.ALLOW64
|
|
|
|
conf.load('force_32bit')
|
|
|
|
|
|
|
|
if conf.env.DEST_SIZEOF_VOID_P == 4:
|
|
|
|
Logs.info('NOTE: will build game dlls for 32-bit target')
|
|
|
|
else:
|
|
|
|
Logs.warn('WARNING: 64-bit game dlls may be unstable')
|
|
|
|
|
|
|
|
linker_flags = {
|
|
|
|
'common': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'msvc': ['/DEBUG'], # always create PDB, doesn't affect result binaries
|
|
|
|
'gcc': ['-Wl,--no-undefined']
|
2019-05-03 18:19:39 +02:00
|
|
|
},
|
|
|
|
'sanitize': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'gcc': ['-fsanitize=undefined', '-fsanitize=address'],
|
2019-05-03 18:19:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compiler_c_cxx_flags = {
|
|
|
|
'common': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'msvc': ['/D_USING_V110_SDK71_', '/Zi', '/FS'],
|
2019-05-03 18:19:39 +02:00
|
|
|
'clang': ['-g', '-gdwarf-2'],
|
2019-06-09 02:25:26 +02:00
|
|
|
'gcc': ['-g', '-Werror=implicit-function-declaration', '-fdiagnostics-color=always']
|
2019-05-03 18:19:39 +02:00
|
|
|
},
|
|
|
|
'fast': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'msvc': ['/O2', '/Oy'], #todo: check /GL /LTCG
|
|
|
|
'gcc': ['-Ofast', '-march=native', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer'],
|
2019-05-03 18:19:39 +02:00
|
|
|
'default': ['-O3']
|
|
|
|
},
|
|
|
|
'release': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'msvc': ['/O2'],
|
2019-05-03 18:19:39 +02:00
|
|
|
'default': ['-O3']
|
|
|
|
},
|
|
|
|
'debug': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'msvc': ['/O1'],
|
|
|
|
'gcc': ['-Og'],
|
2019-05-03 18:19:39 +02:00
|
|
|
'default': ['-O1']
|
|
|
|
},
|
|
|
|
'sanitize': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'msvc': ['/Od', '/RTC1'],
|
|
|
|
'gcc': ['-Og', '-fsanitize=undefined', '-fsanitize=address'],
|
2019-05-03 18:19:39 +02:00
|
|
|
'default': ['-O1']
|
|
|
|
},
|
|
|
|
'nooptimize': {
|
2019-06-09 02:25:26 +02:00
|
|
|
'msvc': ['/Od'],
|
2019-05-03 18:19:39 +02:00
|
|
|
'default': ['-O0']
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-06-09 02:25:26 +02:00
|
|
|
conf.env.append_unique('CFLAGS', conf.get_flags_by_type(
|
2019-05-03 18:19:39 +02:00
|
|
|
compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
|
2019-06-09 02:25:26 +02:00
|
|
|
conf.env.append_unique('CXXFLAGS', conf.get_flags_by_type(
|
2019-05-03 18:19:39 +02:00
|
|
|
compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
|
2019-06-09 02:25:26 +02:00
|
|
|
conf.env.append_unique('LINKFLAGS', conf.get_flags_by_type(
|
2019-05-03 18:19:39 +02:00
|
|
|
linker_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC))
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
if conf.env.COMPILER_CC == 'msvc':
|
|
|
|
conf.env.append_unique('DEFINES', ['_CRT_SECURE_NO_WARNINGS','_CRT_NONSTDC_NO_DEPRECATE'])
|
|
|
|
else:
|
|
|
|
conf.env.append_unique('DEFINES', ['stricmp=strcasecmp','strnicmp=strncasecmp','_LINUX','LINUX','_snprintf=snprintf','_vsnprintf=vsnprintf'])
|
2019-05-28 03:17:05 +02:00
|
|
|
cflags = ['-fvisibility=hidden','-Wno-write-strings']
|
2019-05-03 18:19:39 +02:00
|
|
|
conf.env.append_unique('CFLAGS', cflags)
|
2019-05-28 03:17:05 +02:00
|
|
|
conf.env.append_unique('CXXFLAGS', cflags + ['-Wno-invalid-offsetof', '-fno-rtti', '-fno-exceptions'])
|
2019-05-06 03:13:09 +02:00
|
|
|
|
|
|
|
# strip lib from pattern
|
2019-09-20 15:30:59 +02:00
|
|
|
if conf.env.DEST_OS in ['linux', 'darwin']:
|
2019-06-09 02:25:26 +02:00
|
|
|
if conf.env.cshlib_PATTERN.startswith('lib'):
|
|
|
|
conf.env.cshlib_PATTERN = conf.env.cshlib_PATTERN[3:]
|
|
|
|
if conf.env.cxxshlib_PATTERN.startswith('lib'):
|
|
|
|
conf.env.cxxshlib_PATTERN = conf.env.cxxshlib_PATTERN[3:]
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
conf.env.append_unique('DEFINES', 'CLIENT_WEAPONS')
|
2019-05-06 03:13:09 +02:00
|
|
|
|
2019-05-03 18:19:39 +02:00
|
|
|
conf.recurse('cl_dll dlls')
|
|
|
|
|
|
|
|
def build(bld):
|
|
|
|
bld.recurse('cl_dll dlls')
|
|
|
|
|
|
|
|
|
|
|
|
|