From 3973c870ccf3cea08d3ffae6847c59c6c431cf79 Mon Sep 17 00:00:00 2001 From: Jamie Wilkinson Date: Thu, 4 Jul 2002 00:50:09 +0000 Subject: [PATCH] - Fixed up make install target, so that the dynamic modules are installed into the correct places. - Added libltdl, the libtool dynamic loader to the code, as the libraries are now under libtool control. Libtool and libltdl are evil. - Fixed various paths inside the code to point to PKGLIBDIR for the game and refresher modules, and PKGDATADIR for the game data. - updated .gitignore --- .gitignore | 2 + Makefile.am | 2 +- bootstrap | 17 ++- configure.in | 58 ++++++-- src/Makefile.am | 72 +++++----- src/baseq2/Makefile.am | 3 +- src/ctf/Makefile.am | 3 +- src/files.c | 56 ++++---- src/main.c | 192 +++++++++++-------------- src/r_image.c | 40 +++--- src/rogue/Makefile.am | 3 +- src/vid_so.c | 312 ++++++++++++++++++----------------------- src/xatrix/Makefile.am | 3 +- 13 files changed, 365 insertions(+), 398 deletions(-) diff --git a/.gitignore b/.gitignore index d163664..8c6eb65 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ missing mkinstalldirs stamp-* compile +libltdl +ltmain.sh diff --git a/Makefile.am b/Makefile.am index 5f22dd1..5d0d11c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,3 @@ # $Id$ -SUBDIRS = src +SUBDIRS = libltdl src diff --git a/bootstrap b/bootstrap index 815ac9c..49d4252 100755 --- a/bootstrap +++ b/bootstrap @@ -17,16 +17,25 @@ if [ "$1" = "clean" ]; then fi find . -name Makefile.in -print0 | xargs -r0 rm -f rm -f aclocal.m4 install-sh missing mkinstalldirs \ - stamp-h.in tags configure config.* \ - compile depcomp stamp-h - rm -rf autom4te.cache + stamp-* tags configure config.* \ + compile depcomp ltmain.sh + rm -rf autom4te.cache libltdl find . -name '*~' -print0 | xargs -r0 rm -f + find . -name '*.rej' -print0 | xargs -r0 rm -f + find . -name '*.orig' -print0 | xargs -r0 rm -f else + VERSION=`automake --version |head| sed 's/automake (GNU automake) //'` + MAJOR=`echo $VERSION | cut -f1 -d.` + MINOR=`echo $VERSION | cut -f2 -d.` + if test "$MAJOR" -ge "1" -a "$MINOR" -ge "6"; then aclocal autoheader + libtoolize --copy --ltdl --automake automake --foreign --add-missing --copy autoconf - + else + echo "Need automake version 1.6 or higher" + fi fi diff --git a/configure.in b/configure.in index ffd7e53..f405c89 100644 --- a/configure.in +++ b/configure.in @@ -1,10 +1,11 @@ dnl $Id$ dnl Process this file with autoconf to produce a configure script. -dnl usual stuff -AC_PREREQ(2.50) -AC_INIT(src/main.c) +dnl stick the revision info into the resulting configure script AC_REVISION($Revision$) dnl +AC_PREREQ(2.50) + +AC_INIT(src/main.c) AM_CONFIG_HEADER(config.h) dnl get the build and target hosts @@ -23,8 +24,14 @@ dnl Checks for programs dnl ------------------- AC_PROG_CC -#AC_PROG_RANLIB -#AC_PROG_LIBTOOL + +dnl libtool is evil +AC_LIBTOOL_DLOPEN +AC_LIBLTDL_CONVENIENCE +AC_PROG_LIBTOOL +AC_CONFIG_SUBDIRS(libltdl) +AC_SUBST(INCLTDL) +AC_SUBST(LIBLTDL) HAVE_MASM="" AC_SUBST(HAVE_MASM) @@ -271,8 +278,9 @@ dnl ----------------------------- #AC_CHECK_FUNCS([bzero floor getcwd gethostbyname getmntent getpagesize gettimeofday memmove memset mkdir munmap pow putenv select socket sqrt strcasecmp strchr strdup strerror strrchr strstr]) AC_FUNC_VA_COPY AC_FUNC__VA_COPY -AC_CHECK_FUNCS(dlopen) +dnl Check for dynamic loader -- needed for the GL refreshers +AC_CHECK_FUNCS(dlopen) DL_LIBS="" if test "x$ac_cv_func_dlopen" != "xyes"; then AC_CHECK_LIB(dl, @@ -331,6 +339,25 @@ fi AM_CONDITIONAL(DO_XATRIX, test "$DO_XATRIX" = "yes") AM_CONDITIONAL(DO_ROGUE, test "$DO_ROGUE" = "yes") +dnl ---------------------- +dnl Fill in path variables +dnl ---------------------- + +dnl $libdir usually gets set to ${exec_prefix}/lib, +dnl $exec_prefix is likely to be "NONE" +dnl Autoconf usually sets pkglibdir correctly in the Makefile, but not in +dnl the configure script :( +eval tmp_libdir="$libdir" +if test "x$tmp_libdir" != "xNONE/lib"; then + eval PKGLIBDIR="$libdir/$PACKAGE" +else + eval PKGLIBDIR="$prefix/lib/$PACKAGE" +fi +AC_DEFINE_UNQUOTED(PKGLIBDIR, "$PKGLIBDIR", [Define this to the path containing the dynamic modules (\${exec-prefix}/lib/quake2/)]) + +eval PKGDATADIR="$datadir/$PACKAGE" +AC_DEFINE_UNQUOTED(PKGDATADIR, "$PKGDATADIR", [Define this to the path containing the game data (\${prefix}/share/quake2/)]) + dnl --------------------------------- dnl Work out what refreshers to build dnl --------------------------------- @@ -338,32 +365,32 @@ dnl --------------------------------- VID_REFS="" if test "x$HAVE_SVGALIB" = xyes; then - VID_REFS="$VID_REFS ref_soft.so" + VID_REFS="$VID_REFS ref_soft.la" BUILD_SOFT="yes" fi if test "x$HAVE_X" = xyes; then - VID_REFS="$VID_REFS ref_softx.so" + VID_REFS="$VID_REFS ref_softx.la" BUILD_SOFTX="yes" fi if test "x$HAVE_SDL" = xyes; then - VID_REFS="$VID_REFS ref_softsdl.so" + VID_REFS="$VID_REFS ref_softsdl.la" BUILD_SOFTSDL="yes" fi if test "x$HAVE_X" = xyes -a "x$HAVE_OPENGL" = xyes; then - VID_REFS="$VID_REFS ref_glx.so" + VID_REFS="$VID_REFS ref_glx.la" BUILD_GLX="yes" fi if test "x$HAVE_X" = xyes -a "x$HAVE_GLIDE" = xyes -a "x$HAVE_SVGALIB" = xyes; then - VIDREFS="$VID_REFS ref_fxgl.so" - BUILD_FXGL="yes" + VID_REFS="$VID_REFS ref_tdfx.la" + BUILD_TDFX="yes" fi if test "x$HAVE_X" = xyes -a "x$HAVE_OPENGL" = xyes -a "x$HAVE_SDL" = xyes; then - VID_REFS="$VID_REFS ref_sdlgl.so" + VID_REFS="$VID_REFS ref_sdlgl.la" BUILD_SDLGL="yes" fi @@ -371,7 +398,7 @@ AM_CONDITIONAL(BUILD_SOFT, test "x$BUILD_SOFT" = xyes) AM_CONDITIONAL(BUILD_SOFTX, test "x$BUILD_SOFTX" = xyes) AM_CONDITIONAL(BUILD_SOFTSDL, test "x$BUILD_SOFTSDL" = xyes) AM_CONDITIONAL(BUILD_GLX, test "x$BUILD_GLX" = xyes) -AM_CONDITIONAL(BUILD_FXGL, test "x$BUILD_FXGL" = xyes) +AM_CONDITIONAL(BUILD_TDFX, test "x$BUILD_TDFX" = xyes) AM_CONDITIONAL(BUILD_SDLGL, test "x$BUILD_SDLGL" = xyes) AC_SUBST(VID_REFS) @@ -390,6 +417,7 @@ AC_CONFIG_FILES([ ]) AC_OUTPUT +VID_REFS=`echo $VID_REFS | sed -e 's/ref_//g' -e 's/\.la//g'` AC_MSG_RESULT([ - Video refreshers: ${VID_REFS- no} + Video refreshers: ${VID_REFS- none} ]) diff --git a/src/Makefile.am b/src/Makefile.am index 04cf803..412cb78 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,10 +2,14 @@ SUBDIRS = . baseq2 ctf xatrix rogue -bin_PROGRAMS = quake2 @VID_REFS@ +ALL_CFLAGS = -Wall -Werror -pipe +AM_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) +#AM_LDFLAGS = -shared -EXTRA_PROGRAMS = ref_soft.so ref_softx.so ref_softsdl.so \ - ref_glx.so ref_sdlgl.so ref_fxgl.so +bin_PROGRAMS = quake2 +pkglib_PROGRAMS = @VID_REFS@ +EXTRA_PROGRAMS = ref_soft.la ref_softx.la ref_softsdl.la \ + ref_glx.la ref_sdlgl.la ref_tdfx.la # Common source files REF_GL_COMMON = q_sh.c q_shared.c glob.c qgl.c \ @@ -48,66 +52,54 @@ quake2_SOURCES = main.c q_sh.c vid_menu.c vid_so.c glob.c net_udp.c \ m_flash.c # \ # #snd_mixa.S - -quake2_LDFLAGS = -lm -pthread @DL_LIBS@ - -#AM_CFLAGS = -Wall -Werror -pipe -I/usr/X11R6/include $(shell sdl-config --cflags) -DOPENGL -fPIC -AM_CFLAGS = -Wall -Werror -pipe +quake2_CFLAGS = $(ALL_CFLAGS) @INCLTDL@ +quake2_LDFLAGS = -lm -pthread +quake2_LDADD = @LIBLTDL@ # ref_glx if BUILD_GLX -ref_glx_so_SOURCES = $(REF_GL_COMMON) gl_glx.c -ref_glx_so_CFLAGS = -fPIC @X_CFLAGS@ @OPENGL_CFLAGS@ -ref_glx_so_LDFLAGS = -shared -#ref_glx_so_LDADD = -L/usr/X11R6/lib -lX11 -lXext -lXxf86dga -lXxf86vm -lGL -ref_glx_so_LDADD = @X_PRE_LIBS@ @X_LIBS@ @XTRA_LIBS@ @X_EXTRA_LIBS@ @OPENGL_LIBS@ +ref_glx_la_SOURCES = $(REF_GL_COMMON) gl_glx.c +ref_glx_la_CFLAGS = $(ALL_CFLAGS) -fPIC @X_CFLAGS@ @OPENGL_CFLAGS@ +ref_glx_la_LDADD = @X_PRE_LIBS@ @X_LIBS@ @XTRA_LIBS@ @X_EXTRA_LIBS@ @OPENGL_LIBS@ @DL_LIBS@ endif -# ref_fxgl -if BUILD_FXGL -ref_fxgl_so_SOURCES = $(REF_GL_COMMON) rw_in_svgalib.c gl_fxmesa.c -ref_fxgl_so_CFLAGS = -fPIC @GLIDE_CFLAGS@ @X_CFLAGS@ @SVGALIB_CFLAGS@ -#ref_fxgl_so_LDFLAGS = -shared -L/usr/local/glide/lib -L/usr/X11R6/lib -L/usr/local/lib -lX11 -lXext -lGL -lvga -#ref_fxgl_so_LDFADD = -L/usr/local/glide/lib -L/usr/X11R6/lib -L/usr/local/lib -lX11 -lXext -lGL -lvga -ref_fxgl_so_LDFLAGS = -shared -ref_fxgl_so_LDADD = @GLIDE_LIBS@ @X_LIBS@ @SVGALIB_LIBS@ +# ref_tdfx +if BUILD_TDFX +ref_tdfx_la_SOURCES = $(REF_GL_COMMON) rw_in_svgalib.c gl_fxmesa.c +ref_tdfx_la_CFLAGS = $(ALL_CFLAGS) -fPIC @GLIDE_CFLAGS@ @X_CFLAGS@ @SVGALIB_CFLAGS@ +ref_tdfx_la_LDADD = @GLIDE_LIBS@ @X_LIBS@ @SVGALIB_LIBS@ endif # ref_sdlgl if BUILD_SDLGL -ref_sdlgl_so_SOURCES = $(REF_GL_COMMON) rw_sdl.c -ref_sdlgl_so_CFLAGS = -fPIC -DOPENGL @SDL_CFLAGS@ @OPENGL_CFLAGS@ -ref_sdlgl_so_LDFLAGS = -shared -ref_sdlgl_so_LDADD = @SDL_LIBS@ @OPENGL_LIBS@ +ref_sdlgl_la_SOURCES = $(REF_GL_COMMON) rw_sdl.c +ref_sdlgl_la_CFLAGS = $(ALL_CFLAGS) -fPIC -DOPENGL @SDL_CFLAGS@ @OPENGL_CFLAGS@ +ref_sdlgl_la_LDADD = @SDL_LIBS@ @OPENGL_LIBS@ endif # ref_soft if BUILD_SOFT if ASM_ARCH -SOFT_ASM=$(REF_SOFT_ASM) d_copy.S +DCOPY_S = d_copy.S else -SOFT_ASM=$(REF_SOFT_ASM) +DCOPY_S = endif -ref_soft_so_SOURCES = $(REF_SOFT_COMMON) $(SOFT_ASM) \ +ref_soft_la_SOURCES = $(REF_SOFT_COMMON) $(REF_SOFT_ASM) $(DCOPY_S) \ rw_svgalib.c rw_in_svgalib.c -ref_soft_so_CFLAGS = -fPIC @SVGALIB_CFLAGS@ -ref_soft_so_LDFLAGS = -shared -ref_soft_so_LDADD = @SVGALIB_LIBS@ +ref_soft_la_CFLAGS = $(ALL_CFLAGS) -fPIC @SVGALIB_CFLAGS@ +ref_soft_la_LDADD = @SVGALIB_LIBS@ endif # ref_softx if BUILD_SOFTX -ref_softx_so_SOURCES = $(REF_SOFT_COMMON) $(REF_SOFT_ASM) rw_x11.c -ref_softx_so_CFLAGS = -fPIC @X_CFLAGS@ -ref_softx_so_LDFLAGS = -shared -#ref_softx_so_LDADD = -L/usr/X11R6/lib -lX11 -lXext -lXxf86dga -lXxf86vm -ref_softx_so_LDADD = @X_PRE_LIBS@ @X_LIBS@ @XTRA_LIBS@ @X_EXTRA_LIBS@ +ref_softx_la_SOURCES = $(REF_SOFT_COMMON) $(REF_SOFT_ASM) rw_x11.c +ref_softx_la_CFLAGS = $(ALL_CFLAGS) -fPIC @X_CFLAGS@ +ref_softx_la_LDADD = @X_PRE_LIBS@ @X_LIBS@ @XTRA_LIBS@ @X_EXTRA_LIBS@ endif # ref_softsdl if BUILD_SOFTSDL -ref_softsdl_so_SOURCES = $(REF_SOFT_COMMON) $(REF_SOFT_ASM) rw_sdl.c -ref_softsdl_so_CFLAGS = -fPIC @SDL_CFLAGS@ -ref_softsdl_so_LDFLAGS = -shared -ref_softsdl_so_LDADD = @SDL_LIBS@ +ref_softsdl_la_SOURCES = $(REF_SOFT_COMMON) $(REF_SOFT_ASM) rw_sdl.c +ref_softsdl_la_CFLAGS = $(ALL_CFLAGS) -fPIC @SDL_CFLAGS@ +ref_softsdl_la_LDADD = @SDL_LIBS@ endif diff --git a/src/baseq2/Makefile.am b/src/baseq2/Makefile.am index 24c8d04..1cbf087 100644 --- a/src/baseq2/Makefile.am +++ b/src/baseq2/Makefile.am @@ -2,7 +2,8 @@ # Process this file with automake to create Makefile.in -bin_PROGRAMS = game.so +pkglibdir=$(libdir)/@PACKAGE@/baseq2 +pkglib_PROGRAMS = game.so game_so_SOURCES = g_ai.c \ p_client.c \ g_chase.c \ diff --git a/src/ctf/Makefile.am b/src/ctf/Makefile.am index 2dd67b6..5a13156 100644 --- a/src/ctf/Makefile.am +++ b/src/ctf/Makefile.am @@ -1,6 +1,7 @@ # $Id$ -bin_PROGRAMS = game.so +pkglibdir=$(libdir)/@PACKAGE@/ctf +pkglib_PROGRAMS = game.so game_so_SOURCES = \ g_ai.c \ g_chase.c \ diff --git a/src/files.c b/src/files.c index 7a3d2d9..e0402d0 100644 --- a/src/files.c +++ b/src/files.c @@ -1,22 +1,30 @@ -/* -Copyright (C) 1997-2001 Id Software, Inc. +/* $Id$ + * + * quake filesystem + * + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (c) 2002 The Quakeforge Project. + * + * 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 2 + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ -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 2 -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. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif #include "qcommon.h" @@ -31,15 +39,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // OEM //#define PAK0_CHECKSUM 0x78e135c -/* -============================================================================= - -QUAKE FILESYSTEM - -============================================================================= -*/ - - // // in memory // @@ -907,7 +906,8 @@ void FS_InitFilesystem (void) // // add baseq2 to search path // - FS_AddGameDirectory (va("%s/"BASEDIRNAME, fs_basedir->string) ); + /*FS_AddGameDirectory (va("%s/"BASEDIRNAME, fs_basedir->string) );*/ + FS_AddGameDirectory(PKGDATADIR"/"BASEDIRNAME); // // then add a '.quake2/baseq2' directory in home directory by default diff --git a/src/main.c b/src/main.c index fedb10c..f5e6de8 100644 --- a/src/main.c +++ b/src/main.c @@ -53,9 +53,8 @@ #include #endif -#ifdef HAVE_DLOPEN -# include -#endif +/* libtool dynamic loader */ +#include /* merged from sys_bsd.c -- jaq */ #ifndef RTLD_NOW @@ -119,12 +118,12 @@ void Sys_Printf (char *fmt, ...) { } } -void Sys_Quit (void) -{ - CL_Shutdown (); - Qcommon_Shutdown (); - fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY); - _exit(0); +void Sys_Quit (void) { + CL_Shutdown(); + Qcommon_Shutdown(); + lt_dlexit(); + fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY); + _exit(0); } void Sys_Init(void) @@ -223,89 +222,61 @@ char *Sys_ConsoleInput(void) /*****************************************************************************/ -static void *game_library; +static lt_dlhandle game_library = NULL; +typedef game_export_t * gameapi_t(game_import_t *); -/* -================= -Sys_UnloadGame -================= -*/ -void Sys_UnloadGame (void) -{ - if (game_library) - dlclose (game_library); - game_library = NULL; +void Sys_UnloadGame(void) { + if (game_library) + lt_dlclose(game_library); + game_library = NULL; } -/* -================= -Sys_GetGameAPI +/* Loads the game dll */ +void *Sys_GetGameAPI (void *parms) { + gameapi_t * GetGameAPI; + cvar_t * gamename; + char path[MAX_OSPATH]; + char * str_p; + + setreuid(getuid(), getuid()); + setegid(getgid()); + + if (game_library) + Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); -Loads the game dll -================= -*/ -void *Sys_GetGameAPI (void *parms) -{ - game_export_t *(*GetGameAPI) (game_import_t *); + gamename = Cvar_Get("gamedir", BASEDIRNAME, CVAR_LATCH|CVAR_SERVERINFO); - char name[MAX_OSPATH]; - char *path; - char *str_p; - - /* relnev 0.9 added -- jaq */ - FILE * fp; - - const char * gamename = "game.so"; - - setreuid(getuid(), getuid()); - setegid(getgid()); - - if (game_library) - Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame"); - - Com_Printf("------- Loading %s -------\n", gamename); - - // now run through the search paths - path = NULL; - while (1) - { - path = FS_NextPath (path); - if (!path) - return NULL; // couldn't find one anywhere - snprintf (name, MAX_OSPATH, "%s/%s", path, gamename); - - /* relnev 0.9 added -- jaq */ - /* skip it if it just doesn't exist */ - fp = fopen(name, "rb"); - if (fp == NULL) - continue; - fclose(fp); - - game_library = dlopen(name, RTLD_NOW); - if (game_library) { - Com_MDPrintf ("LoadLibrary (%s)\n",name); - break; - } else { - Com_MDPrintf ("LoadLibrary (%s)\n", name); - str_p = strchr(dlerror(), ':'); // skip the path (already shown) - if (str_p != NULL) { - Com_MDPrintf (" **"); - while (*str_p) - Com_MDPrintf ("%c", *(++str_p)); - Com_MDPrintf ("\n"); - } - } + Com_Printf("------- Loading %s -------\n", gamename->string); + + /* set the module search path */ + snprintf(path, MAX_OSPATH, ".:"PKGLIBDIR"/%s", gamename->string); + lt_dlsetsearchpath(path); + + /* load the module */ + game_library = lt_dlopenext("game.so"); + + if (game_library) { + Com_MDPrintf("LoadLibrary (%s)\n", gamename->string); + } else { + Com_MDPrintf("LoadLibrary (%s)\n", gamename->string); + //str_p = strchr(lt_dlerror(), ':'); // skip the path (already shown) + str_p = (char *) lt_dlerror(); + if (str_p != NULL) { + Com_MDPrintf (" **"); + while (*str_p) + Com_MDPrintf ("%c", *(++str_p)); + Com_MDPrintf ("\n"); } - - GetGameAPI = (game_export_t * (*)(game_import_t *)) dlsym(game_library, "GetGameAPI"); - - if (!GetGameAPI) - { - Sys_UnloadGame (); - return NULL; - } - - return GetGameAPI (parms); + } + + GetGameAPI = (gameapi_t *) lt_dlsym(game_library, "GetGameAPI"); + + if (!GetGameAPI) { + Sys_UnloadGame (); + return NULL; + } + + return GetGameAPI(parms); } /*****************************************************************************/ @@ -327,38 +298,37 @@ void Sys_SendKeyEvents (void) /*****************************************************************************/ -int main (int argc, char **argv) -{ - int time, oldtime, newtime; +int main (int argc, char **argv) { + int time, oldtime, newtime; - // go back to real user for config loads - saved_euid = geteuid(); - seteuid(getuid()); + /* go back to real user for config loads */ + saved_euid = geteuid(); + seteuid(getuid()); - /* relnev 0.9 added -- jaq */ - printf("QuakeIIForge %s\n", VERSION); + printf("QuakeIIForge %s\n", VERSION); - Qcommon_Init(argc, argv); + /* initialiase libltdl */ + lt_dlinit(); + + Qcommon_Init(argc, argv); - /* sys_irix.c had this and the fcntl line 3 lines down commented out */ + /* sys_irix.c had this and the fcntl line 3 lines down commented out */ + fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY); + + nostdout = Cvar_Get("nostdout", "0", 0); + if (!nostdout->value) fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY); - nostdout = Cvar_Get("nostdout", "0", 0); - if (!nostdout->value) { - fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY); -// printf ("Linux Quake -- Version %0.3f\n", LINUX_VERSION); - } - + /* main loop */ oldtime = Sys_Milliseconds (); - while (1) - { -// find time spent rendering last frame - do { - newtime = Sys_Milliseconds (); - time = newtime - oldtime; - } while (time < 1); - Qcommon_Frame (time); - oldtime = newtime; + while (1) { + /* find time spent rendering last frame */ + do { + newtime = Sys_Milliseconds(); + time = newtime - oldtime; + } while (time < 1); + Qcommon_Frame(time); + oldtime = newtime; } } diff --git a/src/r_image.c b/src/r_image.c index f65c2d4..77429d2 100644 --- a/src/r_image.c +++ b/src/r_image.c @@ -1,22 +1,24 @@ -/* -Copyright (C) 1997-2001 Id Software, Inc. - -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 2 -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. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ +/* $Id$ + * + * Copyright (C) 1997-2001 Id Software, Inc. + * Copyright (c) 2002 The Quakeforge Project. + * + * 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 2 + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ #include "r_local.h" diff --git a/src/rogue/Makefile.am b/src/rogue/Makefile.am index 4be5a96..cce2874 100644 --- a/src/rogue/Makefile.am +++ b/src/rogue/Makefile.am @@ -1,7 +1,8 @@ # $Id$ if DO_ROGUE -bin_PROGRAMS = game.so +pkglibdir=$(libdir)/@PACKAGE@/rogue +pkglib_PROGRAMS = game.so game_so_SOURCES = dm_ball.c dm_tag.c \ g_ai.c g_chase.c g_cmds.c g_combat.c g_func.c \ diff --git a/src/vid_so.c b/src/vid_so.c index 16aeab4..33b3ea2 100644 --- a/src/vid_so.c +++ b/src/vid_so.c @@ -42,7 +42,11 @@ #include #include +/* libtool dynamic loader */ +#include + /* merged in from bsd -- jaq */ +/* #ifndef RTLD_NOW #define RTLD_NOW RTLD_LAZY #endif @@ -54,6 +58,7 @@ #ifdef __OpenBSD__ #define dlsym(X, Y) dlsym(X, "_"##Y) #endif +*/ #include "client.h" #include "rw.h" @@ -62,9 +67,11 @@ refexport_t re; /* merged from irix/vid_so.c -- jaq */ +/* #ifdef REF_HARD_LINKED refexport_t GetRefAPI(refimport_t rimp); #endif +*/ // Console variables that we need to access from this module cvar_t *vid_gamma; @@ -75,7 +82,7 @@ cvar_t *vid_fullscreen; // Global variables used internally by this module viddef_t viddef; // global video state; used by other modules -void *reflib_library; // Handle to refresh DLL +lt_dlhandle reflib_library = NULL; // Handle to refresh DLL qboolean reflib_active = 0; #define VID_NUM_MODES ( sizeof( vid_modes ) / sizeof( vid_modes[0] ) ) @@ -213,9 +220,13 @@ void VID_FreeReflib (void) if (RW_IN_Shutdown_fp) RW_IN_Shutdown_fp(); /* merged from irix/vid_so.c -- jaq */ +/* #ifndef REF_HARD_LINKED - dlclose(reflib_library); +*/ + lt_dlclose(reflib_library); +/* #endif +*/ } KBD_Init_fp = NULL; @@ -239,193 +250,142 @@ void VID_FreeReflib (void) VID_LoadRefresh ============== */ -qboolean VID_LoadRefresh( char *name ) -{ - refimport_t ri; -/* from irix/vid_so.c -- jaq */ -#ifndef REF_HARD_LINKED - GetRefAPI_t GetRefAPI; -#endif - char fn[MAX_OSPATH]; - char *path; - struct stat st; - extern uid_t saved_euid; +qboolean VID_LoadRefresh(char * name) { + refimport_t ri; + GetRefAPI_t GetRefAPI; + extern uid_t saved_euid; - if ( reflib_active ) - { - if (KBD_Close_fp) - KBD_Close_fp(); - if (RW_IN_Shutdown_fp) - RW_IN_Shutdown_fp(); - KBD_Close_fp = NULL; - RW_IN_Shutdown_fp = NULL; - re.Shutdown(); - VID_FreeReflib (); - } + /* clean up a previous reflib */ + if (reflib_active) { + if (KBD_Close_fp) + KBD_Close_fp(); + if (RW_IN_Shutdown_fp) + RW_IN_Shutdown_fp(); + KBD_Close_fp = NULL; + RW_IN_Shutdown_fp = NULL; + re.Shutdown(); + VID_FreeReflib (); + } -/* from irix/vid_so.c -- jaq */ -#ifndef REF_HARD_LINKED + Com_Printf( "------- Loading %s -------\n", name ); - Com_Printf( "------- Loading %s -------\n", name ); + //regain root + seteuid(saved_euid); - //regain root - seteuid(saved_euid); + lt_dlsetsearchpath(".:"PKGLIBDIR); - path = Cvar_Get ("basedir", ".", CVAR_NOSET)->string; + // permission checking + if (strstr(name, "softx") == NULL && + strstr(name, "glx") == NULL && + strstr(name, "softsdl") == NULL && + strstr(name, "sdlgl") == NULL && + strstr(name, "fxgl") == NULL) { /* ref_soft doesn't require root */ + /* + if (st.st_uid != 0) { + Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name); + return false; + } + if ((st.st_mode & 0777) & ~0700) { + Com_Printf( "LoadLibrary(\"%s\") failed: invalid permissions, must be 700 for security considerations\n", name); + return false; + } + */ + } else { + /* ref_soft requires we give up root now */ + setreuid(getuid(), getuid()); + setegid(getgid()); + } + + if ((reflib_library = lt_dlopenext(name)) == 0) { + Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name , lt_dlerror()); + return false; + } + + Com_Printf( "LoadLibrary(\"%s\")\n", name ); + + ri.Cmd_AddCommand = Cmd_AddCommand; + ri.Cmd_RemoveCommand = Cmd_RemoveCommand; + ri.Cmd_Argc = Cmd_Argc; + ri.Cmd_Argv = Cmd_Argv; + ri.Cmd_ExecuteText = Cbuf_ExecuteText; + ri.Con_Printf = VID_Printf; + ri.Sys_Error = VID_Error; + ri.FS_LoadFile = FS_LoadFile; + ri.FS_FreeFile = FS_FreeFile; + ri.FS_Gamedir = FS_Gamedir; + ri.Cvar_Get = Cvar_Get; + ri.Cvar_Set = Cvar_Set; + ri.Cvar_SetValue = Cvar_SetValue; + ri.Vid_GetModeInfo = VID_GetModeInfo; + ri.Vid_MenuInit = VID_MenuInit; + ri.Vid_NewWindow = VID_NewWindow; + + if ((GetRefAPI = (GetRefAPI_t) lt_dlsym(reflib_library, "GetRefAPI")) == 0) + Com_Error(ERR_FATAL, "dlsym failed on %s", name); + + re = GetRefAPI( ri ); + + if (re.api_version != API_VERSION) { + VID_FreeReflib (); + Com_Error (ERR_FATAL, "%s has incompatible api_version", name); + } + + /* Init IN (Mouse) */ + in_state.IN_CenterView_fp = IN_CenterView; + in_state.Key_Event_fp = Do_Key_Event; + in_state.viewangles = cl.viewangles; + in_state.in_strafe_state = &in_strafe.state; - snprintf (fn, MAX_OSPATH, "%s/%s", path, name ); - - if (stat(fn, &st) == -1) { - Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name, strerror(errno)); - return false; - } - - // permission checking - if (strstr(fn, "softx") == NULL && - strstr(fn, "glx") == NULL && - strstr(fn, "softsdl") == NULL && - strstr(fn, "sdlgl") == NULL && - strstr(fn, "fxgl") == NULL) { // softx doesn't require root -#if 0 - if (st.st_uid != 0) { - Com_Printf( "LoadLibrary(\"%s\") failed: ref is not owned by root\n", name); - return false; - } - if ((st.st_mode & 0777) & ~0700) { - Com_Printf( "LoadLibrary(\"%s\") failed: invalid permissions, must be 700 for security considerations\n", name); - return false; - } -#endif - } else { - // softx requires we give up root now - setreuid(getuid(), getuid()); - setegid(getgid()); - } + if ((RW_IN_Init_fp = (void (*)(in_state_t *)) lt_dlsym(reflib_library, "RW_IN_Init")) == NULL || + (RW_IN_Shutdown_fp = (void(*)(void)) lt_dlsym(reflib_library, "RW_IN_Shutdown")) == NULL || + (RW_IN_Activate_fp = (void(*)(qboolean)) lt_dlsym(reflib_library, "RW_IN_Activate")) == NULL || + (RW_IN_Commands_fp = (void(*)(void)) lt_dlsym(reflib_library, "RW_IN_Commands")) == NULL || + (RW_IN_Move_fp = (void(*)(usercmd_t *)) lt_dlsym(reflib_library, "RW_IN_Move")) == NULL || + (RW_IN_Frame_fp = (void(*)(void)) lt_dlsym(reflib_library, "RW_IN_Frame")) == NULL) + Sys_Error("No RW_IN functions in REF.\n"); + + /* this one is optional */ + RW_Sys_GetClipboardData_fp = (char*(*)(void)) lt_dlsym(reflib_library, "RW_Sys_GetClipboardData"); + + Real_IN_Init(); - if ( ( reflib_library = dlopen( fn, RTLD_LAZY | RTLD_GLOBAL ) ) == 0 ) - { - Com_Printf( "LoadLibrary(\"%s\") failed: %s\n", name , dlerror()); - return false; - } - - Com_Printf( "LoadLibrary(\"%s\")\n", fn ); -#endif /* REF_HARD_LINKED */ - - ri.Cmd_AddCommand = Cmd_AddCommand; - ri.Cmd_RemoveCommand = Cmd_RemoveCommand; - ri.Cmd_Argc = Cmd_Argc; - ri.Cmd_Argv = Cmd_Argv; - ri.Cmd_ExecuteText = Cbuf_ExecuteText; - ri.Con_Printf = VID_Printf; - ri.Sys_Error = VID_Error; - ri.FS_LoadFile = FS_LoadFile; - ri.FS_FreeFile = FS_FreeFile; - ri.FS_Gamedir = FS_Gamedir; - ri.Cvar_Get = Cvar_Get; - ri.Cvar_Set = Cvar_Set; - ri.Cvar_SetValue = Cvar_SetValue; - ri.Vid_GetModeInfo = VID_GetModeInfo; - ri.Vid_MenuInit = VID_MenuInit; - ri.Vid_NewWindow = VID_NewWindow; - -#ifndef REF_HARD_LINKED - if ( ( GetRefAPI = (GetRefAPI_t) dlsym( reflib_library, "GetRefAPI" ) ) == 0 ) - Com_Error( ERR_FATAL, "dlsym failed on %s", name ); -#endif - - re = GetRefAPI( ri ); - - if (re.api_version != API_VERSION) - { - VID_FreeReflib (); - Com_Error (ERR_FATAL, "%s has incompatible api_version", name); - } - - /* Init IN (Mouse) */ - in_state.IN_CenterView_fp = IN_CenterView; - in_state.Key_Event_fp = Do_Key_Event; - in_state.viewangles = cl.viewangles; - in_state.in_strafe_state = &in_strafe.state; - -#ifndef REF_HARD_LINKED - if ((RW_IN_Init_fp = (void (*)(in_state_t *)) dlsym(reflib_library, "RW_IN_Init")) == NULL || - (RW_IN_Shutdown_fp = (void(*)(void)) dlsym(reflib_library, "RW_IN_Shutdown")) == NULL || - (RW_IN_Activate_fp = (void(*)(qboolean)) dlsym(reflib_library, "RW_IN_Activate")) == NULL || - (RW_IN_Commands_fp = (void(*)(void)) dlsym(reflib_library, "RW_IN_Commands")) == NULL || - (RW_IN_Move_fp = (void(*)(usercmd_t *)) dlsym(reflib_library, "RW_IN_Move")) == NULL || - (RW_IN_Frame_fp = (void(*)(void)) dlsym(reflib_library, "RW_IN_Frame")) == NULL) - Sys_Error("No RW_IN functions in REF.\n"); - - /* this one is optional */ - RW_Sys_GetClipboardData_fp = (char*(*)(void)) dlsym(reflib_library, "RW_Sys_GetClipboardData"); - - Real_IN_Init(); -#else /* ref-hard-linked */ - { - void RW_IN_Init(in_state_t *in_state_p); - void RW_IN_Shutdown(void); - void RW_IN_Commands (void); - void RW_IN_Move (usercmd_t *cmd); - void RW_IN_Frame (void); - void RW_IN_Activate(void); - - RW_IN_Init_fp = RW_IN_Init; - RW_IN_Shutdown_fp = RW_IN_Shutdown; - RW_IN_Activate_fp = (void(*)(qboolean))RW_IN_Activate; - RW_IN_Commands_fp = RW_IN_Commands; - RW_IN_Move_fp = RW_IN_Move; - RW_IN_Frame_fp = RW_IN_Frame; - } -#endif - - if ( re.Init( 0, 0 ) == -1 ) - { - re.Shutdown(); - VID_FreeReflib (); - return false; - } + if (re.Init(0, 0) == -1) { + re.Shutdown(); + VID_FreeReflib (); + return false; + } /* merged in from irix/vid_so.c */ +/* #ifdef __sgi - /* give up root now */ - setreuid(getuid(), getuid()); - setegid(getgid()); + give up root now + setreuid(getuid(), getuid()); + setegid(getgid()); #endif +*/ - /* Init KBD */ -#ifndef REF_HARD_LINKED - if ((KBD_Init_fp = (void(*)(Key_Event_fp_t)) dlsym(reflib_library, "KBD_Init")) == NULL || - (KBD_Update_fp = (void(*)(void)) dlsym(reflib_library, "KBD_Update")) == NULL || - (KBD_Close_fp = (void(*)(void)) dlsym(reflib_library, "KBD_Close")) == NULL) - Sys_Error("No KBD functions in REF.\n"); -#else - { - void KBD_Init(void); - void KBD_Update(void); - void KBD_Close(void); + /* Init KBD */ + if ((KBD_Init_fp = (void(*)(Key_Event_fp_t)) lt_dlsym(reflib_library, "KBD_Init")) == NULL || + (KBD_Update_fp = (void(*)(void)) lt_dlsym(reflib_library, "KBD_Update")) == NULL || + (KBD_Close_fp = (void(*)(void)) lt_dlsym(reflib_library, "KBD_Close")) == NULL) + Sys_Error("No KBD functions in REF.\n"); - KBD_Init_fp = (void(*)(Key_Event_fp_t))KBD_Init; - KBD_Update_fp = KBD_Update; - KBD_Close_fp = KBD_Close; - } -#endif - KBD_Init_fp(Do_Key_Event); - - /* for some reason irix has this swapped with elsewhere, kinda dodgy, needs - * cleaning */ -#ifndef __sgi - Key_ClearStates(); - - // give up root now - setreuid(getuid(), getuid()); - setegid(getgid()); -#else - Real_IN_Init(); -#endif - - Com_Printf( "------------------------------------\n"); - reflib_active = true; - return true; + KBD_Init_fp(Do_Key_Event); + + /* for some reason irix has this swapped with elsewhere, kinda dodgy, needs + * cleaning */ + Key_ClearStates(); + + // give up root now + setreuid(getuid(), getuid()); + setegid(getgid()); + /* sgi + Real_IN_Init(); + */ + + Com_Printf( "------------------------------------\n"); + reflib_active = true; + return true; } /* diff --git a/src/xatrix/Makefile.am b/src/xatrix/Makefile.am index dd78d16..47613de 100644 --- a/src/xatrix/Makefile.am +++ b/src/xatrix/Makefile.am @@ -1,7 +1,8 @@ # $Id$ if DO_XATRIX -bin_PROGRAMS = game.so +pkglibdir=$(libdir)/@PACKAGE@/xatrix +pkglib_PROGRAMS = game.so game_so_SOURCES = g_ai.c g_chase.c g_cmds.c g_combat.c g_func.c \ g_items.c g_main.c g_misc.c g_monster.c g_phys.c \