mittorn
5 years ago
12 changed files with 261 additions and 16 deletions
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
#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 |
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
GetRefAPI |
||||
GetRefHumanReadableName |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
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 |
||||
|
||||
def build(bld): |
||||
if bld.env.STATIC_LINKING: |
||||
apply_static(MAIN_BINARY,*bld.env.STATIC_LINKING.split(',')) |
||||
|
||||
|
||||
class objcopy(Task.Task): |
||||
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): |
||||
no_errcheck_out = True |
||||
run_str = '${LD} -r -o ${TGT[0].abspath()} -melf_i386 ${CCLNK_SRC_F}${SRC}' |
||||
def add_target(self, target): |
||||
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', target_unstripped, target_stripped) |
||||
self.generator.objcopy_task.env['NAME'] = target |
||||
print self.generator.name |
||||
# def run(self): |
||||
# xshlib.run(self) |
||||
# objcopy.run(self) |
||||
|
||||
|
||||
class cprogram_static(c.cprogram): |
||||
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): |
||||
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}' |
||||
|
||||
ccroot.USELIB_VARS['cprogram_static'] = ccroot.USELIB_VARS['cxxprogram_static'] = ccroot.USELIB_VARS['cxxprogram'] |
||||
|
||||
|
||||
@TaskGen.feature('xshlib') |
||||
@TaskGen.after('apply_link') |
||||
def add_objcopy_task(self): |
||||
if getattr(self, 'link_task', None): |
||||
exe_node = self.link_task.outputs[0] |
||||
self.create_task('objcopy', self.link_task.outputs[0], self.link_task.outputs[1]) |
||||
|
||||
|
||||
|
||||
def apply_static(main, *reloc): |
||||
def write_libraries_list(out_node): |
||||
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): |
||||
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') |
||||
def add_link_helper(self): |
||||
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): |
||||
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]] |
Loading…
Reference in new issue