diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/Makefile.am freeciv-test/client/Makefile.am --- freeciv-cvs/client/Makefile.am Sat May 4 19:17:29 2002 +++ freeciv-test/client/Makefile.am Fri Jun 21 18:50:22 2002 @@ -27,6 +27,19 @@ ALL_SDL_FILES=audio_sdl.c audio_sdl.h ALL_WINMM_FILES=audio_winmm.c audio_winmm.h +SO_FLAGS=-shared -fPIC -DPIC + +if PLUGINS +if ESD +ESD_SO=audio_esd.so +endif +if SDL +SDL_SO=audio_sdl.so +endif +if WINMM +WINMM_SO=audio_winmm.so +endif +else if ESD ESD_FILES=$(ALL_ESD_FILES) endif @@ -36,6 +49,7 @@ if WINMM WINMM_FILES=$(ALL_WINMM_FILES) endif +endif EXTRA_DIST= gui-mui/autogroupclass.c \ gui-mui/autogroupclass.h \ @@ -121,9 +135,22 @@ bin_PROGRAMS = civclient INCLUDES = -I$(srcdir)/include -I$(top_srcdir)/common -I../intl -I$(srcdir)/agents @SOUND_CFLAGS@ +CLEANFILES = $(ESD_SO) $(SDL_SO) $(WINMM_SO) ## Above, note -I../intl instead of -I$(top_srdir/intl) is deliberate. +if PLUGINS +noinst_DATA = $(ESD_SO) $(SDL_SO) $(WINMM_SO) + +audio_esd.so : audio_esd.c + $(COMPILE) $(SO_FLAGS) -o $@ $< @ESD_LIBS@ + +audio_sdl.so : audio_sdl.c + $(COMPILE) $(SO_FLAGS) -o $@ $< @SDL_LIBS@ +else +SOUND_LIBS = @SOUND_LIBS@ +endif + civclient_SOURCES = $(ESD_FILES) $(SDL_FILES) $(WINMM_FILES) \ attribute.h \ attribute.c \ @@ -163,4 +190,4 @@ civclient_LDADD = @gui_sources@/libguiclient.a \ ../common/libcivcommon.a @INTLLIBS@ @gui_sources@/libguiclient.a \ ../common/libcivcommon.a @CLIENT_LIBS@ agents/libagents.a \ - @CLIENT_LIBS@ @SOUND_LIBS@ + @CLIENT_LIBS@ $(SOUND_LIBS) diff -Nur -Xfreecivdiff.ignore freeciv-cvs/client/audio.c freeciv-test/client/audio.c --- freeciv-cvs/client/audio.c Fri May 24 12:55:15 2002 +++ freeciv-test/client/audio.c Fri Jun 21 17:12:06 2002 @@ -16,8 +16,13 @@ #endif #include +#include #include +#ifdef PLUGINS +#include +#endif + #include "support.h" #include "fcintl.h" #include "log.h" @@ -26,6 +31,7 @@ #include "registry.h" #include "audio_none.h" +#ifndef PLUGINS #ifdef ESD #include "audio_esd.h" #endif @@ -37,9 +43,12 @@ #ifdef WINMM #include "audio_winmm.h" #endif +#endif #include "audio.h" +typedef void (*PluginInitFunc)(void); + #define MAX_NUM_PLUGINS 3 /* keep it open throughout */ @@ -97,6 +106,37 @@ return TRUE; } +#ifdef PLUGINS +static void dlopen_plugin(const char *modname) +{ + char symname[200]; + char filename[200]; + void *modpt; + + sz_strlcpy(filename, "client/"); + sz_strlcat(filename, modname); + sz_strlcat(filename, ".so"); + + modpt = dlopen(filename, RTLD_NOW); + if (!modpt) { + fprintf(stderr, _("Could not load plugin %s: %s\n"), filename, dlerror()); + } else { + PluginInitFunc modsym; + + sz_strlcpy(symname, modname); + sz_strlcat(symname, "_init"); + + modsym = dlsym(modpt, symname); + if (!modsym) { + fprintf(stderr, _("Could not find plugin init function %s: %s\n"), + symname, dlerror()); + } else { + modsym(); + } + } +} +#endif + /************************************************************************** Initialize base audio system. Note that this function is called very early at the client startup. So for example logging isn't available. @@ -107,6 +147,11 @@ assert(num_plugins_used == 1); selected_plugin = 0; +#ifdef PLUGINS + dlopen_plugin("audio_esd"); + dlopen_plugin("audio_sdl"); + dlopen_plugin("audio_winmm"); +#else #ifdef ESD audio_esd_init(); #endif @@ -115,6 +160,7 @@ #endif #ifdef WINMM audio_winmm_init(); +#endif #endif } diff -Nur -Xfreecivdiff.ignore freeciv-cvs/configure.ac freeciv-test/configure.ac --- freeciv-cvs/configure.ac Wed Jun 12 12:51:12 2002 +++ freeciv-test/configure.ac Fri Jun 21 17:49:50 2002 @@ -144,6 +144,11 @@ WITH_EFENCE=1 ) +AC_ARG_ENABLE(plugins, + [ --disable-plugins do not use dynamic plugins ], + [ plugins="$enableval" ], [ plugins="probe" ] +) + dnl Checks for programs. AC_PROG_AWK AC_PROG_CC @@ -584,6 +589,20 @@ AC_CHECK_FUNCS(fileno gethostname getpwuid gettimeofday inet_aton \ select snooze strerror strcasecmp strncasecmp \ strlcat strlcpy strstr usleep vsnprintf uname) + +if test -z "$GCC"; then + plugins="no" +fi + +if test "$plugins" != "no" ; then + AC_SEARCH_LIBS(dlopen, dl) + AC_CHECK_FUNC(dlopen, [plugins="yes"], [plugins="no"]) +fi + +if test "$plugins" = "yes" ; then + AC_DEFINE(PLUGINS, 1, [Define if using dynamically-loaded plugins]) +fi +AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes") dnl The use of both AC_FUNC_VSNPRINTF and AC_CHECK_FUNCS(vsnprintf) is dnl deliberate. diff -Nur -Xfreecivdiff.ignore freeciv-cvs/configure.in freeciv-test/configure.in --- freeciv-cvs/configure.in Wed Jun 12 12:51:12 2002 +++ freeciv-test/configure.in Fri Jun 21 17:49:32 2002 @@ -143,6 +143,11 @@ WITH_EFENCE=1 ) +AC_ARG_ENABLE(plugins, + [ --disable-plugins do not use dynamic plugins ], + [ plugins="$enableval" ], [ plugins="probe" ] +) + dnl Checks for programs. AC_PROG_AWK AC_PROG_CC @@ -578,6 +583,20 @@ AC_CHECK_FUNCS(fileno gethostname getpwuid gettimeofday inet_aton \ select snooze strerror strcasecmp strncasecmp \ strlcat strlcpy strstr usleep vsnprintf uname) + +if test -z "$GCC"; then + plugins="no" +fi + +if test "$plugins" != "no" ; then + AC_SEARCH_LIBS(dlopen, dl) + AC_CHECK_FUNC(dlopen, [plugins="yes"], [plugins="no"]) +fi + +if test "$plugins" = "yes" ; then + AC_DEFINE(PLUGINS, 1, [Define if using dynamically-loaded plugins]) +fi +AM_CONDITIONAL(PLUGINS, test "$plugins" = "yes") dnl The use of both AC_FUNC_VSNPRINTF and AC_CHECK_FUNCS(vsnprintf) is dnl deliberate. diff -Nur -Xfreecivdiff.ignore freeciv-cvs/m4/sound.m4 freeciv-test/m4/sound.m4 --- freeciv-cvs/m4/sound.m4 Wed Jun 12 09:21:41 2002 +++ freeciv-test/m4/sound.m4 Fri Jun 21 17:10:30 2002 @@ -18,6 +18,7 @@ if test "x$ESD" != "xno"; then SOUND_CFLAGS="$SOUND_CFLAGS $ESD_CFLAGS" SOUND_LIBS="$SOUND_LIBS $ESD_LIBS" + AC_SUBST(ESD_LIBS) AC_DEFINE(ESD, 1, [Esound support]) AC_MSG_CHECKING(building ESOUND support) AC_MSG_RESULT(yes) @@ -34,8 +35,10 @@ AC_MSG_CHECKING(building SDL_mixer support) if test "x$SDL_mixer_h" = "x1"; then if test "x$SDL_mixer" = "xyes"; then + SDL_LIBS="$SDL_LIBS -lSDL_mixer" SOUND_CFLAGS="$SOUND_CFLAGS $SDL_CFLAGS" - SOUND_LIBS="$SOUND_LIBS $SDL_LIBS -lSDL_mixer" + SOUND_LIBS="$SOUND_LIBS $SDL_LIBS" + AC_SUBST(SDL_LIBS) AC_DEFINE(SDL, 1, [SDL_Mixer support]) AC_MSG_RESULT(yes) else