2019-03-19 23:17:46 +01:00
|
|
|
#! /usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
# mittorn, 2018
|
|
|
|
|
2024-04-29 04:29:53 +02:00
|
|
|
from waflib import Logs, Configure
|
2019-03-19 23:17:46 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
top = '.'
|
|
|
|
|
2024-04-29 04:29:53 +02:00
|
|
|
TGMATH_H_TEST = '''#include <tgmath.h>
|
|
|
|
const float val = 2, val2 = 3;
|
|
|
|
int main(void){ return (int)(-asin(val) + cos(val2)); }'''
|
|
|
|
|
|
|
|
STRNCASECMP_TEST = '''#include <string.h>
|
2024-05-03 15:01:24 +02:00
|
|
|
int main(int argc, char **argv) { return strncasecmp(argv[1], argv[2], 10); }'''
|
2024-04-29 04:29:53 +02:00
|
|
|
|
|
|
|
STRCASECMP_TEST = '''#include <string.h>
|
2024-05-03 15:01:24 +02:00
|
|
|
int main(int argc, char **argv) { return strcasecmp(argv[1], argv[2]); }'''
|
2024-04-29 04:29:53 +02:00
|
|
|
|
|
|
|
STRCASESTR_TEST = '''#include <string.h>
|
2024-05-03 15:01:24 +02:00
|
|
|
int main(int argc, char **argv) { argv[0] = strcasestr(argv[1], argv[2]); return 0; }'''
|
2024-04-29 04:29:53 +02:00
|
|
|
|
|
|
|
STRCHRNUL_TEST = '''#include <string.h>
|
2024-05-03 15:01:24 +02:00
|
|
|
int main(int argc, char **argv) { argv[2] = strchrnul(argv[1], 'x'); return 0; }'''
|
2024-04-29 04:29:53 +02:00
|
|
|
|
|
|
|
STRLCPY_TEST = '''#include <string.h>
|
2024-05-03 15:01:24 +02:00
|
|
|
int main(int argc, char **argv) { return strlcpy(argv[1], argv[2], 10); }'''
|
2024-04-29 04:29:53 +02:00
|
|
|
|
|
|
|
STRLCAT_TEST = '''#include <string.h>
|
2024-05-03 15:01:24 +02:00
|
|
|
int main(int argc, char **argv) { return strlcat(argv[1], argv[2], 10); }'''
|
2024-04-29 04:29:53 +02:00
|
|
|
|
|
|
|
ALLOCA_TEST = '''#include <%s>
|
|
|
|
int main(void) { alloca(1); return 0; }'''
|
|
|
|
|
|
|
|
HEADER_TEST = '''#include <%s>
|
|
|
|
int main(void) { return 0; }
|
|
|
|
'''
|
|
|
|
|
2019-03-19 23:17:46 +01:00
|
|
|
def options(opt):
|
|
|
|
# stub
|
|
|
|
return
|
|
|
|
|
2024-04-29 04:29:53 +02:00
|
|
|
def header_frag(header_name):
|
|
|
|
return '#include <%s>' % header_name + EMPTY_PROGRAM
|
|
|
|
|
|
|
|
@Configure.conf
|
|
|
|
def export_define(conf, define, value=1):
|
|
|
|
if not value:
|
|
|
|
return
|
|
|
|
if value is True:
|
|
|
|
value = 1 # so python won't define it as string True
|
|
|
|
|
|
|
|
conf.env.EXPORT_DEFINES_LIST += ['%s=%s' % (define, value)]
|
|
|
|
|
|
|
|
@Configure.conf
|
|
|
|
def simple_check(conf, fragment, msg, mandatory=False, **kw):
|
|
|
|
return conf.check_cc(fragment=fragment, msg='Checking for %s' % msg, mandatory=mandatory, **kw)
|
|
|
|
|
2019-03-19 23:17:46 +01:00
|
|
|
def configure(conf):
|
2024-04-29 04:29:53 +02:00
|
|
|
# private to libpublic
|
2024-03-19 17:30:52 +01:00
|
|
|
conf.load('gitversion')
|
|
|
|
conf.define('XASH_BUILD_COMMIT', conf.env.GIT_VERSION if conf.env.GIT_VERSION else 'unknown-commit')
|
|
|
|
conf.define('XASH_BUILD_BRANCH', conf.env.GIT_BRANCH if conf.env.GIT_BRANCH else 'unknown-branch')
|
2019-03-19 23:17:46 +01:00
|
|
|
|
2024-04-29 04:29:53 +02:00
|
|
|
# need to expose it for everyone using libpublic headers
|
|
|
|
conf.env.EXPORT_DEFINES_LIST = []
|
|
|
|
conf.export_define('_CRT_SILENCE_NONCONFORMING_TGMATH_H', conf.env.COMPILER_CC == 'msvc')
|
|
|
|
conf.export_define('_GNU_SOURCE', conf.env.DEST_OS != 'win32')
|
|
|
|
|
|
|
|
# create temporary uselib that just enables extensions
|
|
|
|
conf.env.DEFINES_export = list(conf.env.EXPORT_DEFINES_LIST)
|
|
|
|
|
|
|
|
# check platform-specific header name for alloca(3)
|
2024-08-17 12:04:38 +02:00
|
|
|
if conf.env.DEST_OS == 'win32':
|
|
|
|
# don't waste time on Win32, it's documented to be always in malloc.h.
|
|
|
|
# (plus test can fail because alloca is underscore-prefixed, e.g. _alloca)
|
|
|
|
conf.export_define('ALLOCA_H', '<malloc.h>')
|
|
|
|
elif conf.simple_check(ALLOCA_TEST % 'alloca.h', msg='alloca in alloca.h'):
|
2024-04-29 04:29:53 +02:00
|
|
|
conf.export_define('ALLOCA_H', '<alloca.h>')
|
|
|
|
elif conf.simple_check(ALLOCA_TEST % 'malloc.h', msg='alloca in malloc.h'):
|
|
|
|
conf.export_define('ALLOCA_H', '<malloc.h>')
|
|
|
|
elif conf.simple_check(ALLOCA_TEST % 'stdlib.h', msg='alloca in stdlib.h'):
|
|
|
|
conf.export_define('ALLOCA_H', '<stdlib.h>')
|
|
|
|
|
|
|
|
conf.export_define('STDINT_H', '<stdint.h>' if conf.simple_check(HEADER_TEST % 'stdint.h', 'stdint.h') else '<pstdint.h>')
|
|
|
|
conf.export_define('HAVE_TGMATH_H', conf.simple_check(TGMATH_H_TEST, 'tgmath.h', use='M werror export'))
|
|
|
|
|
|
|
|
# save some time on Windows, msvc is too slow
|
|
|
|
# these calls must be available with both msvc and mingw
|
|
|
|
if conf.env.DEST_OS == 'win32':
|
|
|
|
conf.export_define('HAVE_STRNICMP')
|
|
|
|
conf.export_define('HAVE_STRICMP')
|
|
|
|
else:
|
|
|
|
# TODO: multicheck for speed
|
|
|
|
def check_libc_extension(frag, msg, define):
|
|
|
|
conf.export_define(define, conf.simple_check(frag, msg, use='werror export'))
|
|
|
|
|
|
|
|
check_libc_extension(STRNCASECMP_TEST, 'strncasecmp', 'HAVE_STRNCASECMP')
|
|
|
|
check_libc_extension(STRCASECMP_TEST, 'strcasecmp', 'HAVE_STRCASECMP')
|
|
|
|
check_libc_extension(STRCASESTR_TEST, 'strcasestr', 'HAVE_STRCASESTR')
|
|
|
|
check_libc_extension(STRCHRNUL_TEST, 'strchrnul', 'HAVE_STRCHRNUL')
|
|
|
|
check_libc_extension(STRLCPY_TEST, 'strlcpy', 'HAVE_STRLCPY')
|
|
|
|
check_libc_extension(STRLCAT_TEST, 'strlcat', 'HAVE_STRLCAT')
|
|
|
|
|
|
|
|
# kill temporary uselib
|
|
|
|
del conf.env.DEFINES_export
|
|
|
|
|
2019-03-19 23:17:46 +01:00
|
|
|
def build(bld):
|
2024-04-29 04:29:53 +02:00
|
|
|
bld(name = 'sdk_includes',
|
|
|
|
export_includes = '. ../common ../pm_shared ../engine',
|
|
|
|
export_defines = bld.env.EXPORT_DEFINES_LIST)
|
|
|
|
|
2022-09-10 18:55:37 +02:00
|
|
|
bld.stlib(source = bld.path.ant_glob('*.c'),
|
2019-03-24 23:25:44 +01:00
|
|
|
target = 'public',
|
2024-01-30 13:04:57 +01:00
|
|
|
use = 'sdk_includes werror',
|
2022-09-10 18:55:37 +02:00
|
|
|
subsystem = bld.env.MSVC_SUBSYSTEM)
|
2023-04-13 18:56:31 +02:00
|
|
|
|
|
|
|
if bld.env.TESTS:
|
|
|
|
tests = {
|
|
|
|
'strings': 'tests/test_strings.c',
|
2023-04-17 18:11:16 +02:00
|
|
|
'build': 'tests/test_build.c',
|
2023-04-26 03:04:20 +02:00
|
|
|
'filebase': 'tests/test_filebase.c',
|
2023-10-28 18:31:17 +02:00
|
|
|
'efp': 'tests/test_efp.c',
|
2024-07-04 05:29:46 +02:00
|
|
|
'atoi': 'tests/test_atoi.c',
|
2024-10-08 02:21:42 +02:00
|
|
|
'parsefile': 'tests/test_parsefile.c',
|
2023-04-13 18:56:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for i in tests:
|
|
|
|
bld.program(features = 'test',
|
|
|
|
source = tests[i],
|
|
|
|
target = 'test_%s' % i,
|
|
|
|
use = 'public',
|
|
|
|
subsystem = bld.env.CONSOLE_SUBSYSTEM,
|
|
|
|
install_path = None)
|