]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
DP_PRELOAD_DEPENDENCIES=yes makefile option: when set, link against the libraries...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 20 May 2007 16:02:27 +0000 (16:02 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 20 May 2007 16:02:27 +0000 (16:02 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7322 d7cf8633-e32d-0410-b094-e92efae38249

BSDmakefile
makefile
makefile.inc
sys_shared.c

index 249a2bc960d248f13b649f88cf120e4aea6b0cd4..6514487ef9a43741712a230e9c88ddee520bf731 100644 (file)
@@ -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 #####
 
index 19272f8315aabece2aca056c1201e5642ec032c5..479d62bc0b282cd410dc953692e7b0fbdfc4c239 100644 (file)
--- 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 #####
 
index 3fe68d427b365b997057f6893d04435991ef024c..208759023fb01aa6f0534ff258da38f63c2c77b6 100644 (file)
@@ -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
index f636ff310285ba8a06405f31e96b9f58ba3b271b..64ca6abfb29961211dbfb9854c03b3aa03e412f5 100644 (file)
@@ -1,4 +1,3 @@
-
 #include "quakedef.h"
 # include <time.h>
 #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;