From: divverent Date: Sun, 20 May 2007 16:02:27 +0000 (+0000) Subject: DP_PRELOAD_DEPENDENCIES=yes makefile option: when set, link against the libraries... X-Git-Tag: xonotic-v0.1.0preview~3133 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=3a466b8a6397138a30c965e4a7f75e181d6f0181;hp=00d8da42f76d5e04a9d11e0deaac38391132808a DP_PRELOAD_DEPENDENCIES=yes makefile option: when set, link against the libraries needed using -l dynamically so they won't get loaded at runtime using dlopen git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7322 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/BSDmakefile b/BSDmakefile index 249a2bc9..6514487e 100644 --- a/BSDmakefile +++ b/BSDmakefile @@ -75,6 +75,14 @@ CFLAGS_FS=-DDP_FS_BASEDIR='\"$(DP_FS_BASEDIR)\"' CFLAGS_FS= .endif +CFLAGS_PRELOAD= +.ifdef DP_PRELOAD_DEPENDENCIES +LDFLAGS_CL+=$(LDFLAGS_UNIXCL_PRELOAD) +LDFLAGS_SV+=$(LDFLAGS_UNIXSV_PRELOAD) +LDFLAGS_SDL+=$(LDFLAGS_UNIXSDL_PRELOAD) +CFLAGS_PRELOAD=$(CFLAGS_UNIX_PRELOAD) +.endif + ##### BSD Make specific definitions ##### diff --git a/makefile b/makefile index 19272f83..479d62bc 100644 --- a/makefile +++ b/makefile @@ -163,7 +163,6 @@ ifeq ($(DP_MAKE_TARGET), mingw) EXE_SDLNEXUIZ=$(EXE_WINSDLNEXUIZ) endif - ##### Sound configuration ##### ifndef DP_SOUND_API @@ -216,6 +215,17 @@ else CFLAGS_FS= endif +CFLAGS_PRELOAD= +ifneq ($(DP_MAKE_TARGET), mingw) +ifdef DP_PRELOAD_DEPENDENCIES +# DP_PRELOAD_DEPENDENCIES: when set, link against the libraries needed using -l +# dynamically so they won't get loaded at runtime using dlopen + LDFLAGS_CL+=$(LDFLAGS_UNIXCL_PRELOAD) + LDFLAGS_SV+=$(LDFLAGS_UNIXSV_PRELOAD) + LDFLAGS_SDL+=$(LDFLAGS_UNIXSDL_PRELOAD) + CFLAGS_PRELOAD=$(CFLAGS_UNIX_PRELOAD) +endif +endif ##### GNU Make specific definitions ##### diff --git a/makefile.inc b/makefile.inc index 3fe68d42..20875902 100644 --- a/makefile.inc +++ b/makefile.inc @@ -138,7 +138,7 @@ OBJ_SDL= builddate.c sys_sdl.o vid_sdl.o $(OBJ_SND_COMMON) snd_sdl.o cd_sdl.o $( # Compilation -CFLAGS_COMMON=$(CFLAGS_MAKEDEP) $(CFLAGS_FS) -Wall -Wsign-compare -Wdeclaration-after-statement +CFLAGS_COMMON=$(CFLAGS_MAKEDEP) $(CFLAGS_PRELOAD) $(CFLAGS_FS) -Wall -Wsign-compare -Wdeclaration-after-statement CFLAGS_DEBUG=-ggdb CFLAGS_PROFILE=-g -pg -ggdb CFLAGS_RELEASE= @@ -165,6 +165,10 @@ OBJ_GLX= builddate.c sys_linux.o vid_glx.o $(OBJ_SOUND) $(OBJ_CD) $(OBJ_COMMON) LDFLAGS_UNIXCOMMON=-lm LDFLAGS_UNIXCL=-L$(UNIX_X11LIBPATH) -lX11 -lXext -lXxf86dga -lXxf86vm $(LIB_SOUND) +LDFLAGS_UNIXCL_PRELOAD=-lz -ljpeg -lpng -lvorbis -lvorbisfile -lcurl +LDFLAGS_UNIXSV_PRELOAD=-lz -lcurl +LDFLAGS_UNIXSDL_PRELOAD=-lz -ljpeg -lpng -lvorbis -lvorbisfile -lcurl +CFLAGS_UNIX_PRELOAD=-DPREFER_PRELOAD LDFLAGS_UNIXSDL=`$(SDL_CONFIG) --libs` EXE_UNIXCL=darkplaces-glx diff --git a/sys_shared.c b/sys_shared.c index f636ff31..64ca6abf 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -1,4 +1,3 @@ - #include "quakedef.h" # include #ifndef WIN32 @@ -41,6 +40,25 @@ qboolean Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllf if (handle == NULL) return false; +#ifndef WIN32 +#ifdef PREFER_PRELOAD + dllhandle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); + if(dllhandle) + { + for (func = fcts; func && func->name != NULL; func++) + if (!(*func->funcvariable = (void *) Sys_GetProcAddress (dllhandle, func->name))) + { + dlclose(dllhandle); + goto notfound; + } + Con_Printf ("All of %s's functions were already linked in! Not loading dynamically...\n", dllnames[0]); + *handle = dllhandle; + return true; + } +notfound: +#endif +#endif + // Initializations for (func = fcts; func && func->name != NULL; func++) *func->funcvariable = NULL;