mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-11-10 20:49:01 +01:00
Merge branch 'lib' of https://github.com/FWGS/xash3d-fwgs
This commit is contained in:
commit
22dc5b7416
@ -51,4 +51,12 @@ GNU General Public License for more details.
|
||||
#define MSGBOX_ANDROID 2
|
||||
#define MSGBOX_WIN32 3
|
||||
|
||||
|
||||
// library loading (XASH_LIB)
|
||||
#define LIB_NULL 0
|
||||
#define LIB_POSIX 1
|
||||
#define LIB_WIN32 2
|
||||
#define LIB_STATIC 3
|
||||
|
||||
|
||||
#endif /* BACKENDS_H */
|
||||
|
@ -123,6 +123,15 @@ SETUP BACKENDS DEFINITIONS
|
||||
#endif // !XASH_WIN32
|
||||
#endif
|
||||
|
||||
#ifdef XASH_STATIC_LIBS
|
||||
#define XASH_LIB LIB_STATIC
|
||||
#define XASH_INTERNAL_GAMELIBS
|
||||
#elif defined _WIN32
|
||||
#define XASH_LIB LIB_WIN32
|
||||
#else
|
||||
#define XASH_LIB LIB_POSIX
|
||||
#endif
|
||||
|
||||
//
|
||||
// fallback to NULL
|
||||
//
|
||||
@ -138,6 +147,7 @@ SETUP BACKENDS DEFINITIONS
|
||||
#define XASH_INPUT INPUT_NULL
|
||||
#endif // XASH_INPUT
|
||||
|
||||
|
||||
/*
|
||||
=========================================================================
|
||||
|
||||
|
101
engine/platform/misc/lib_static.c
Normal file
101
engine/platform/misc/lib_static.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
lib_static.c - static linking support
|
||||
Copyright (C) 2018 Flying With Gauss
|
||||
|
||||
This program is free software: you can redistribute it and/sor modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "platform/platform.h"
|
||||
|
||||
#if XASH_LIB == LIB_STATIC
|
||||
#ifdef XASH_NO_LIBDL
|
||||
|
||||
void *dlsym(void *handle, const char *symbol )
|
||||
{
|
||||
Con_DPrintf( "dlsym( %p, \"%s\" ): stub\n", handle, symbol );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *dlopen(const char *name, int flag )
|
||||
{
|
||||
Con_DPrintf( "dlopen( \"%s\", %d ): stub\n", name, flag );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int dlclose(void *handle)
|
||||
{
|
||||
Con_DPrintf( "dlsym( %p ): stub\n", handle );
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *dlerror( void )
|
||||
{
|
||||
return "Loading ELF libraries not supported in this build!\n";
|
||||
}
|
||||
|
||||
int dladdr( const void *addr, void *info )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif // XASH_NO_LIBDL
|
||||
|
||||
|
||||
typedef struct table_s
|
||||
{
|
||||
const char *name;
|
||||
void *pointer;
|
||||
} table_t;
|
||||
|
||||
|
||||
#include "generated_library_tables.h"
|
||||
|
||||
static void *Lib_Find(table_t *tbl, const char *name )
|
||||
{
|
||||
while( tbl->name )
|
||||
{
|
||||
if( !Q_strcmp( tbl->name, name) )
|
||||
return tbl->pointer;
|
||||
tbl++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *COM_LoadLibrary( const char *dllname, int build_ordinals_table, qboolean directpath )
|
||||
{
|
||||
return Lib_Find(libs, dllname);
|
||||
}
|
||||
|
||||
void COM_FreeLibrary( void *hInstance )
|
||||
{
|
||||
// impossible
|
||||
}
|
||||
|
||||
void *COM_GetProcAddress( void *hInstance, const char *name )
|
||||
{
|
||||
return Lib_Find( hInstance, name );
|
||||
}
|
||||
|
||||
void *COM_FunctionFromName( void *hInstance, const char *pName )
|
||||
{
|
||||
return Lib_Find( hInstance, pName );
|
||||
}
|
||||
|
||||
|
||||
const char *COM_NameForFunction( void *hInstance, void *function )
|
||||
{
|
||||
#ifdef XASH_ALLOW_SAVERESTORE_OFFSETS
|
||||
return COM_OffsetNameForFunction( function );
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
@ -13,9 +13,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "build.h"
|
||||
#if !XASH_WIN32 // see win_lib.c
|
||||
#define _GNU_SOURCE
|
||||
#include "platform/platform.h"
|
||||
#if XASH_LIB == LIB_POSIX
|
||||
|
||||
|
||||
#include "common.h"
|
||||
#include "library.h"
|
||||
|
@ -12,8 +12,8 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include "platform/platform.h"
|
||||
#if XASH_LIB == LIB_WIN32
|
||||
#include "common.h"
|
||||
#include "library.h"
|
||||
|
||||
|
@ -23,7 +23,10 @@ def options(opt):
|
||||
help = 'enable custom swap allocator. For devices with no swap support')
|
||||
|
||||
grp.add_option('--enable-legacy-sdl', action = 'store_true', dest = 'SDL12', default = False,
|
||||
help = 'enable using SDL1.2 instead of SDL2(not recommended) [default: %default')
|
||||
help = 'enable using SDL1.2 instead of SDL2(not recommended) [default: %default]')
|
||||
|
||||
grp.add_option('--enable-static-binary', action = 'store_true', dest = 'STATIC', default = False,
|
||||
help = 'build static binary(not recommended, --single-binary required) [default: %default]')
|
||||
|
||||
opt.load('sdl2')
|
||||
|
||||
@ -56,10 +59,15 @@ def configure(conf):
|
||||
if conf.options.USE_SELECT == None:
|
||||
conf.options.USE_SELECT = conf.options.DEDICATED
|
||||
|
||||
if conf.options.STATIC:
|
||||
conf.env.STATIC = True
|
||||
conf.define('XASH_NO_LIBDL',1)
|
||||
|
||||
if not conf.env.DEST_OS in ['win32', 'android'] and not conf.options.NO_ASYNC_RESOLVE:
|
||||
conf.load('pthreads')
|
||||
conf.check_pthread_flag()
|
||||
|
||||
conf.define_cond('XASH_STATIC_LIBS', conf.env.STATIC_LINKING)
|
||||
conf.define_cond('XASH_CUSTOM_SWAP', conf.options.CUSTOM_SWAP)
|
||||
conf.define_cond('SINGLE_BINARY', conf.env.SINGLE_BINARY)
|
||||
conf.define_cond('XASH_NO_ASYNC_NS_RESOLVE', conf.options.NO_ASYNC_RESOLVE)
|
||||
@ -81,7 +89,9 @@ def build(bld):
|
||||
|
||||
# basic build: dedicated only, no dependencies
|
||||
if bld.env.DEST_OS != 'win32':
|
||||
libs += [ 'DL' , 'M' , 'RT', 'PTHREAD', 'ASOUND']
|
||||
libs += [ 'M', 'RT', 'PTHREAD', 'ASOUND']
|
||||
if not bld.env.STATIC:
|
||||
libs += ['DL']
|
||||
source += bld.path.ant_glob(['platform/posix/*.c'])
|
||||
else:
|
||||
libs += ['USER32', 'SHELL32', 'GDI32', 'ADVAPI32', 'DBGHELP', 'PSAPI', 'WS2_32' ]
|
||||
@ -91,7 +101,11 @@ def build(bld):
|
||||
source += bld.path.ant_glob(['platform/linux/*.c'])
|
||||
|
||||
if bld.get_define('XASH_CUSTOM_SWAP'):
|
||||
source += bld.path.ant_glob(['platform/swap/*.c'])
|
||||
source += bld.path.ant_glob(['platform/misc/kmalloc.c', 'platform/misc/sbrk.c'])
|
||||
|
||||
if bld.env.STATIC_LINKING:
|
||||
source += bld.path.ant_glob(['platform/misc/lib_static.c'])
|
||||
is_cxx_link = True
|
||||
|
||||
if bld.env.HAVE_SDL2:
|
||||
libs.append('SDL2')
|
||||
@ -118,7 +132,10 @@ def build(bld):
|
||||
|
||||
if bld.env.SINGLE_BINARY:
|
||||
install_path = bld.env.BINDIR
|
||||
features = ['c', 'cxxprogram' if is_cxx_link else 'cprogram']
|
||||
program = 'cxxprogram' if is_cxx_link else 'cprogram'
|
||||
if bld.env.STATIC:
|
||||
program += '_static'
|
||||
features = ['c', program]
|
||||
else:
|
||||
install_path = bld.env.LIBDIR
|
||||
features = ['c', 'cxxshlib' if is_cxx_link else 'cshlib']
|
||||
|
2
ref_gl/exports.txt
Normal file
2
ref_gl/exports.txt
Normal file
@ -0,0 +1,2 @@
|
||||
GetRefAPI
|
||||
GetRefHumanReadableName
|
115
scripts/waifulib/xshlib.py
Normal file
115
scripts/waifulib/xshlib.py
Normal file
@ -0,0 +1,115 @@
|
||||
# encoding: utf-8
|
||||
# xshlib.py -- advanced linking utils
|
||||
# Copyright (C) 2019 mittorn
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
from waflib import Logs, Utils, TaskGen, Task
|
||||
from waflib.Tools import ccroot, c, cxx
|
||||
|
||||
MAIN_BINARY = 'xash'
|
||||
|
||||
def options(opt):
|
||||
opt.add_option('--static-linking', action='store', dest='STATIC_LINKING', default=None)
|
||||
|
||||
def configure(conf):
|
||||
if conf.options.STATIC_LINKING:
|
||||
conf.find_program('ld')
|
||||
conf.find_program('objcopy')
|
||||
conf.env.STATIC_LINKING = conf.options.STATIC_LINKING
|
||||
conf.add_os_flags('LD_RELOCATABLE_FLAGS')
|
||||
|
||||
def build(bld):
|
||||
if bld.env.STATIC_LINKING:
|
||||
apply_static(MAIN_BINARY,*bld.env.STATIC_LINKING.split(','))
|
||||
|
||||
class objcopy_relocatable_lib(Task.Task):
|
||||
"remove all exports except of lib_${NAME}_exports"
|
||||
no_errcheck_out = True
|
||||
run_str = '${OBJCOPY} -G lib_${NAME}_exports ${SRC[0].abspath()} ${TGT[0].abspath()}'
|
||||
def keyword(self):
|
||||
return 'ObjCopy'
|
||||
|
||||
class xshlib(ccroot.link_task):
|
||||
"make relocatable library"
|
||||
no_errcheck_out = True
|
||||
run_str = '${LD} -r -o ${TGT[0].abspath()} ${LD_RELOCATABLE_FLAGS} ${CCLNK_SRC_F}${SRC}'
|
||||
|
||||
def add_target(self, target):
|
||||
"create objcopy task for target"
|
||||
if not self.env.LD_RELOCATABLE_FLAGS:
|
||||
self.env.LD_RELOCATABLE_FLAGS = []
|
||||
if '-m32' in self.env.LINKFLAGS:
|
||||
self.env.LD_RELOCATABLE_FLAGS.append('-melf_i386')
|
||||
|
||||
base = self.generator.path
|
||||
target_unstripped = base.find_or_declare('%s.unstripped.o'% target)
|
||||
target_stripped = base.find_or_declare('%s.o'% target)
|
||||
|
||||
self.set_outputs(target_unstripped)
|
||||
self.generator.objcopy_task= self.generator.create_task('objcopy_relocatable_lib', target_unstripped, target_stripped)
|
||||
self.generator.objcopy_task.env['NAME'] = target
|
||||
|
||||
class cprogram_static(c.cprogram):
|
||||
"build static c program"
|
||||
run_str = '${LINK_CC} -static ${LINKFLAGS} ${CCLNK_SRC_F}${SRC} ${CCLNK_TGT_F}${TGT[0].abspath()} ${RPATH_ST:RPATH} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${FRAMEWORK_ST:FRAMEWORK} ${ARCH_ST:ARCH} ${STLIB_MARKER} ${STLIBPATH_ST:STLIBPATH} ${STLIB_ST:STLIB} ${STLIB_MARKER} ${LIBPATH_ST:LIBPATH} ${LIB_ST:LIB} ${LDFLAGS}'
|
||||
|
||||
class cxxprogram_static(cxx.cxxprogram):
|
||||
"build static cxx program"
|
||||
run_str = '${LINK_CXX} -static ${LINKFLAGS} ${CXXLNK_SRC_F}${SRC} ${CXXLNK_TGT_F}${TGT[0].abspath()} ${RPATH_ST:RPATH} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${FRAMEWORK_ST:FRAMEWORK} ${ARCH_ST:ARCH} ${STLIB_MARKER} ${STLIBPATH_ST:STLIBPATH} ${STLIB_ST:STLIB} ${STLIB_MARKER} ${LIBPATH_ST:LIBPATH} ${LIB_ST:LIB} ${LDFLAGS}'
|
||||
|
||||
# usevars are same
|
||||
ccroot.USELIB_VARS['cprogram_static'] = ccroot.USELIB_VARS['cxxprogram_static'] = ccroot.USELIB_VARS['cxxprogram']
|
||||
|
||||
def apply_static(main, *reloc):
|
||||
"apply xshlib tasks and generate files"
|
||||
|
||||
def write_libraries_list(out_node):
|
||||
"generate library list"
|
||||
|
||||
libraries = reloc
|
||||
externs = '\n'.join(['extern table_t lib_%s_exports[];' % e for e in libraries])
|
||||
table = '\n'.join(['{ "%s", &lib_%s_exports },' % (e, e) for e in libraries])
|
||||
out_node.write('%s\nstruct {const char *name;void *func;} libs[] = {\n%s\n{0,0}\n};\n' % (externs, table ))
|
||||
|
||||
|
||||
def write_export_list(name,in_node, out_node):
|
||||
"generate exports list for library"
|
||||
|
||||
exports = in_node.read().split('\n')
|
||||
externs = '\n'.join(['extern void %s;' % e for e in exports])
|
||||
table = '\n'.join(['{ "%s", &%s },' % (e, e) for e in exports])
|
||||
out_node.write('%s\nstruct {const char *name;void *func;} lib_%s_exports[] = {\n%s\n{0,0}\n};\n' % (externs, name, table ))
|
||||
|
||||
@TaskGen.feature('cshlib', 'cxxshlib')
|
||||
@TaskGen.before('process_source', 'propogate_uselib_vars')
|
||||
def apply_xshlib(self):
|
||||
"apply xshlib feature and inject link_helper.c to sources"
|
||||
if self.name in reloc:
|
||||
for k in ('cshlib', 'cxxshlib'):
|
||||
if k in self.features:
|
||||
self.features.remove(k)
|
||||
self.features.append('xshlib')
|
||||
in_node = self.path.get_src().make_node('exports.txt')
|
||||
bldnode = self.path.get_bld()
|
||||
bldnode.mkdir()
|
||||
out_node = bldnode.make_node('link_helper.c')
|
||||
write_export_list(self.name,in_node, out_node)
|
||||
self.source = Utils.to_list(self.source) + [out_node]
|
||||
|
||||
@TaskGen.feature('cshlib', 'cxxshlib', 'cprogram', 'cxxprogram', 'cprogram_static', 'cxxprogram_static')
|
||||
@TaskGen.before('process_source')
|
||||
def add_deps(self):
|
||||
"add all relocatable objects to main binary source list"
|
||||
if self.name == main:
|
||||
write_libraries_list(self.path.get_bld().make_node('generated_library_tables.h'))
|
||||
|
||||
for t in reloc:
|
||||
self.source += [self.bld.get_tgen_by_name(t).objcopy_task.outputs[0]]
|
40
wscript
40
wscript
@ -18,13 +18,22 @@ class Subproject:
|
||||
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
|
||||
mandatory = False
|
||||
|
||||
def __init__(self, name, dedicated=True, singlebin=False):
|
||||
def __init__(self, name, dedicated=True, singlebin=False, mandatory = False):
|
||||
self.name = name
|
||||
self.dedicated = dedicated
|
||||
self.singlebin = singlebin
|
||||
self.mandatory = mandatory
|
||||
|
||||
def is_enabled(self, ctx):
|
||||
if not self.mandatory:
|
||||
if self.name in ctx.env.IGNORE_PROJECTS:
|
||||
self.ignore = True
|
||||
|
||||
if self.ignore:
|
||||
return False
|
||||
|
||||
if ctx.env.SINGLE_BINARY and self.singlebin:
|
||||
return False
|
||||
|
||||
@ -37,13 +46,15 @@ class Subproject:
|
||||
return True
|
||||
|
||||
SUBDIRS = [
|
||||
Subproject('public', dedicated=False),
|
||||
Subproject('public', dedicated=False, mandatory = True),
|
||||
Subproject('game_launch', singlebin=True),
|
||||
Subproject('ref_gl'),
|
||||
#rsw Subproject('ref_soft'),
|
||||
Subproject('ref_gl',),
|
||||
Subproject('ref_soft'),
|
||||
Subproject('mainui'),
|
||||
Subproject('vgui_support'),
|
||||
Subproject('engine', dedicated=False),
|
||||
Subproject('stub/server', dedicated=False),
|
||||
Subproject('stub/client'),
|
||||
Subproject('engine', dedicated=False, mandatory = False),
|
||||
]
|
||||
|
||||
def subdirs():
|
||||
@ -82,11 +93,20 @@ def options(opt):
|
||||
grp.add_option('--enable-magx', action = 'store_true', dest = 'MAGX', default = False,
|
||||
help = 'enable targetting for MotoMAGX phones [default: %default]')
|
||||
|
||||
grp.add_option('--ignore-projects', action = 'store', dest = 'IGNORE_PROJECTS', default = None,
|
||||
help = 'disable selected projects from build [default: %default]')
|
||||
|
||||
opt.load('subproject')
|
||||
|
||||
opt.add_subproject(subdirs())
|
||||
for i in SUBDIRS:
|
||||
if not i.mandatory and not opt.path.find_node(i.name+'/wscript'):
|
||||
i.ignore = True
|
||||
continue
|
||||
|
||||
opt.load('xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test')
|
||||
opt.add_subproject(i.name)
|
||||
|
||||
|
||||
opt.load('xshlib xcompile compiler_cxx compiler_c sdl2 clang_compilation_database strip_on_install waf_unit_test')
|
||||
if sys.platform == 'win32':
|
||||
opt.load('msvc msdev msvs')
|
||||
opt.load('reconfigure')
|
||||
@ -95,6 +115,9 @@ def configure(conf):
|
||||
enforce_pic = True # modern defaults
|
||||
valid_build_types = ['fastnative', 'fast', 'release', 'debug', 'nooptimize', 'sanitize', 'none']
|
||||
conf.load('fwgslib reconfigure')
|
||||
if conf.options.IGNORE_PROJECTS:
|
||||
conf.env.IGNORE_PROJECTS = conf.options.IGNORE_PROJECTS.split(',')
|
||||
|
||||
conf.start_msg('Build type')
|
||||
if conf.options.BUILD_TYPE == None:
|
||||
conf.end_msg('not set', color='RED')
|
||||
@ -115,7 +138,7 @@ def configure(conf):
|
||||
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
|
||||
if sys.platform == 'win32':
|
||||
conf.load('msvc msvc_pdb msdev msvs')
|
||||
conf.load('subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install waf_unit_test')
|
||||
conf.load('xshlib subproject xcompile compiler_c compiler_cxx gitversion clang_compilation_database strip_on_install waf_unit_test')
|
||||
|
||||
try:
|
||||
conf.env.CC_VERSION[0]
|
||||
@ -363,6 +386,7 @@ def configure(conf):
|
||||
conf.add_subproject(i.name)
|
||||
|
||||
def build(bld):
|
||||
bld.load('xshlib')
|
||||
for i in SUBDIRS:
|
||||
if not i.is_enabled(bld):
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user