Date: Tue, 01 Jun 2004 15:27:44 +0300
authorSam Lantinga <slouken@libsdl.org>
Sat, 21 Aug 2004 04:20:00 +0000
changeset 939c7c04f811994
parent 938 fa2ce068b0b6
child 940 bb1588ebe47b
Date: Tue, 01 Jun 2004 15:27:44 +0300
From: Martin_Storsj
Subject: Update for dynamic loading of ALSA

I sent you a patch a few months ago which enables SDL to load ALSA
dynamically. Now I've finally got time to tweak this yet some more. I've
added code from alsa.m4 (from alsa's dev package) to acinclude.m4, and
made the detection of the alsa library name a bit better. I've also
fixed up the loading versioned symbols with dlvsym, so that it falls
back to dlsym.

I wouldn't say the configure script is complete yet, but this is how far
I've come this time, and I'm no expert at those things.
acinclude.m4
configure.in
src/audio/alsa/SDL_alsa_audio.c
     1.1 --- a/acinclude.m4	Sat Aug 21 03:55:12 2004 +0000
     1.2 +++ b/acinclude.m4	Sat Aug 21 04:20:00 2004 +0000
     1.3 @@ -20,6 +20,153 @@
     1.4  ])
     1.5  
     1.6  #
     1.7 +# --- alsa.m4 ---
     1.8 +#
     1.9 +dnl Configure Paths for Alsa
    1.10 +dnl Some modifications by Richard Boulton <richard-alsa@tartarus.org>
    1.11 +dnl Christopher Lansdown <lansdoct@cs.alfred.edu>
    1.12 +dnl Jaroslav Kysela <perex@suse.cz>
    1.13 +dnl Last modification: alsa.m4,v 1.22 2002/05/27 11:14:20 tiwai Exp
    1.14 +dnl AM_PATH_ALSA([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
    1.15 +dnl Test for libasound, and define ALSA_CFLAGS and ALSA_LIBS as appropriate.
    1.16 +dnl enables arguments --with-alsa-prefix=
    1.17 +dnl                   --with-alsa-enc-prefix=
    1.18 +dnl                   --disable-alsatest  (this has no effect, as yet)
    1.19 +dnl
    1.20 +dnl For backwards compatibility, if ACTION_IF_NOT_FOUND is not specified,
    1.21 +dnl and the alsa libraries are not found, a fatal AC_MSG_ERROR() will result.
    1.22 +dnl
    1.23 +AC_DEFUN(AM_PATH_ALSA,
    1.24 +[dnl Save the original CFLAGS, LDFLAGS, and LIBS
    1.25 +alsa_save_CFLAGS="$CFLAGS"
    1.26 +alsa_save_LDFLAGS="$LDFLAGS"
    1.27 +alsa_save_LIBS="$LIBS"
    1.28 +alsa_found=yes
    1.29 +
    1.30 +dnl
    1.31 +dnl Get the cflags and libraries for alsa
    1.32 +dnl
    1.33 +AC_ARG_WITH(alsa-prefix,
    1.34 +[  --with-alsa-prefix=PFX  Prefix where Alsa library is installed(optional)],
    1.35 +[alsa_prefix="$withval"], [alsa_prefix=""])
    1.36 +
    1.37 +AC_ARG_WITH(alsa-inc-prefix,
    1.38 +[  --with-alsa-inc-prefix=PFX  Prefix where include libraries are (optional)],
    1.39 +[alsa_inc_prefix="$withval"], [alsa_inc_prefix=""])
    1.40 +
    1.41 +dnl FIXME: this is not yet implemented
    1.42 +AC_ARG_ENABLE(alsatest,
    1.43 +[  --disable-alsatest      Do not try to compile and run a test Alsa program],
    1.44 +[enable_alsatest=no],
    1.45 +[enable_alsatest=yes])
    1.46 +
    1.47 +dnl Add any special include directories
    1.48 +AC_MSG_CHECKING(for ALSA CFLAGS)
    1.49 +if test "$alsa_inc_prefix" != "" ; then
    1.50 +	ALSA_CFLAGS="$ALSA_CFLAGS -I$alsa_inc_prefix"
    1.51 +	CFLAGS="$CFLAGS -I$alsa_inc_prefix"
    1.52 +fi
    1.53 +AC_MSG_RESULT($ALSA_CFLAGS)
    1.54 +
    1.55 +dnl add any special lib dirs
    1.56 +AC_MSG_CHECKING(for ALSA LDFLAGS)
    1.57 +if test "$alsa_prefix" != "" ; then
    1.58 +	ALSA_LIBS="$ALSA_LIBS -L$alsa_prefix"
    1.59 +	LDFLAGS="$LDFLAGS $ALSA_LIBS"
    1.60 +fi
    1.61 +
    1.62 +dnl add the alsa library
    1.63 +ALSA_LIBS="$ALSA_LIBS -lasound -lm -ldl -lpthread"
    1.64 +LIBS=`echo $LIBS | sed 's/-lm//'`
    1.65 +LIBS=`echo $LIBS | sed 's/-ldl//'`
    1.66 +LIBS=`echo $LIBS | sed 's/-lpthread//'`
    1.67 +LIBS=`echo $LIBS | sed 's/  //'`
    1.68 +LIBS="$ALSA_LIBS $LIBS"
    1.69 +AC_MSG_RESULT($ALSA_LIBS)
    1.70 +
    1.71 +dnl Check for a working version of libasound that is of the right version.
    1.72 +min_alsa_version=ifelse([$1], ,0.1.1,$1)
    1.73 +AC_MSG_CHECKING(for libasound headers version >= $min_alsa_version)
    1.74 +no_alsa=""
    1.75 +    alsa_min_major_version=`echo $min_alsa_version | \
    1.76 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
    1.77 +    alsa_min_minor_version=`echo $min_alsa_version | \
    1.78 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
    1.79 +    alsa_min_micro_version=`echo $min_alsa_version | \
    1.80 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
    1.81 +
    1.82 +AC_LANG_SAVE
    1.83 +AC_LANG_C
    1.84 +AC_TRY_COMPILE([
    1.85 +#include <alsa/asoundlib.h>
    1.86 +], [
    1.87 +/* ensure backward compatibility */
    1.88 +#if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR)
    1.89 +#define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR
    1.90 +#endif
    1.91 +#if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR)
    1.92 +#define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR
    1.93 +#endif
    1.94 +#if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR)
    1.95 +#define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR
    1.96 +#endif
    1.97 +
    1.98 +#  if(SND_LIB_MAJOR > $alsa_min_major_version)
    1.99 +  exit(0);
   1.100 +#  else
   1.101 +#    if(SND_LIB_MAJOR < $alsa_min_major_version)
   1.102 +#       error not present
   1.103 +#    endif
   1.104 +
   1.105 +#   if(SND_LIB_MINOR > $alsa_min_minor_version)
   1.106 +  exit(0);
   1.107 +#   else
   1.108 +#     if(SND_LIB_MINOR < $alsa_min_minor_version)
   1.109 +#          error not present
   1.110 +#      endif
   1.111 +
   1.112 +#      if(SND_LIB_SUBMINOR < $alsa_min_micro_version)
   1.113 +#        error not present
   1.114 +#      endif
   1.115 +#    endif
   1.116 +#  endif
   1.117 +exit(0);
   1.118 +],
   1.119 +  [AC_MSG_RESULT(found.)],
   1.120 +  [AC_MSG_RESULT(not present.)
   1.121 +   ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)])
   1.122 +   alsa_found=no]
   1.123 +)
   1.124 +AC_LANG_RESTORE
   1.125 +
   1.126 +dnl Now that we know that we have the right version, let's see if we have the library and not just the headers.
   1.127 +AC_CHECK_LIB([asound], [snd_ctl_open],,
   1.128 +	[ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)])
   1.129 +	 alsa_found=no]
   1.130 +)
   1.131 +
   1.132 +CFLAGS="$alsa_save_CFLAGS"
   1.133 +LDFLAGS="$alsa_save_LDFLAGS"
   1.134 +LIBS="$alsa_save_LIBS"
   1.135 +if test "x$alsa_found" = "xyes" ; then
   1.136 +   ifelse([$2], , :, [$2])
   1.137 +else
   1.138 +   ifelse([$3], , :, [$3])
   1.139 +   CFLAGS="$alsa_save_CFLAGS"
   1.140 +   LDFLAGS="$alsa_save_LDFLAGS"
   1.141 +   LIBS="$alsa_save_LIBS"
   1.142 +   ALSA_CFLAGS=""
   1.143 +   ALSA_LIBS=""
   1.144 +fi
   1.145 +
   1.146 +dnl That should be it.  Now just export out symbols:
   1.147 +AC_SUBST(ALSA_CFLAGS)
   1.148 +AC_SUBST(ALSA_LIBS)
   1.149 +])
   1.150 +
   1.151 +
   1.152 +
   1.153 +#
   1.154  # --- esd.m4 ---
   1.155  #
   1.156  # Configure paths for ESD
     2.1 --- a/configure.in	Sat Aug 21 03:55:12 2004 +0000
     2.2 +++ b/configure.in	Sat Aug 21 04:20:00 2004 +0000
     2.3 @@ -282,39 +282,53 @@
     2.4  [  --enable-alsa           support the ALSA audio API [default=yes]],
     2.5                    , enable_alsa=yes)
     2.6      if test x$enable_audio = xyes -a x$enable_alsa = xyes; then
     2.7 -        AC_MSG_CHECKING(for ALSA audio support)
     2.8          have_alsa=no
     2.9 -        AC_TRY_COMPILE([
    2.10 -          #include <alsa/asoundlib.h>
    2.11 -        ],[
    2.12 -          #if SND_LIB_VERSION < ((0<<16)|(9<<8)|0)
    2.13 -          #error Your version of ALSA is too old
    2.14 -          #endif
    2.15 -          snd_pcm_t *pcm_handle;
    2.16 -        ],[
    2.17 -        AC_CHECK_LIB(asound, snd_pcm_open, have_alsa=yes)
    2.18 -        ])
    2.19 +        AM_PATH_ALSA(0.9.0, have_alsa=yes)
    2.20          if test x$have_alsa = xyes; then
    2.21              AC_ARG_ENABLE(alsa-shared,
    2.22  [  --enable-alsa-shared     dynamically load ALSA audio support [default=yes]],
    2.23                            , enable_alsa_shared=yes)
    2.24 -            alsa_lib=`ls /usr/lib/libasound.so.* | sed 's/.*\/\(.*\)/\1/; q'`
    2.25 +            if test "x`echo $ALSA_LIBS | grep -- -L`" = "x"; then
    2.26 +                if test "x`ls /usr/lib/libasound.so.* 2> /dev/null`" != "x"; then
    2.27 +                    ALSA_LIBS="-L/usr/lib $ALSA_LIBS"
    2.28 +                else if test "x`ls /usr/local/lib/libasound.so.* 2> /dev/null`" != "x"; then
    2.29 +                    ALSA_LIBS="-L/usr/local/lib $ALSA_LIBS"
    2.30 +                fi; fi
    2.31 +            fi
    2.32 +            alsa_lib_spec=`echo $ALSA_LIBS | sed 's/.*-L\([[^ ]]*\).*/\1\/libasound.so.*/'`
    2.33 +            alsa_lib=`ls $alsa_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
    2.34 +            echo "-- $alsa_lib_spec -> $alsa_lib"
    2.35 +
    2.36              if test x$use_dlopen != xyes && \
    2.37                 test x$enable_alsa_shared = xyes; then
    2.38                  AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
    2.39              fi
    2.40              if test x$use_dlopen = xyes && \
    2.41                 test x$enable_alsa_shared = xyes && test x$alsa_lib != x; then
    2.42 -                CFLAGS="$CFLAGS -DALSA_SUPPORT -DALSA_DYNAMIC=\$(alsa_lib)"
    2.43 +                CFLAGS="$CFLAGS -DALSA_SUPPORT -DALSA_DYNAMIC=\$(alsa_lib) $ALSA_CFLAGS"
    2.44                  AC_SUBST(alsa_lib)
    2.45 +
    2.46 +                AC_MSG_CHECKING(for dlvsym)
    2.47 +                use_dlvsym=no
    2.48 +                AC_TRY_COMPILE([
    2.49 +                  #include <stdio.h>
    2.50 +                  #define __USE_GNU
    2.51 +                  #include <dlfcn.h>
    2.52 +                ],[
    2.53 +                  dlvsym(NULL,"","");
    2.54 +                ],[
    2.55 +                use_dlvsym=yes
    2.56 +                ])
    2.57 +                AC_MSG_RESULT($use_dlvsym);
    2.58 +                if test x$use_dlvsym = xyes; then
    2.59 +                    CFLAGS="$CFLAGS -DUSE_DLVSYM"
    2.60 +                fi
    2.61              else
    2.62 -                CFLAGS="$CFLAGS -DALSA_SUPPORT"
    2.63 -                SYSTEM_LIBS="$SYSTEM_LIBS -lasound"
    2.64 +                CFLAGS="$CFLAGS -DALSA_SUPPORT $ALSA_CFLAGS"
    2.65 +                SYSTEM_LIBS="$SYSTEM_LIBS $ALSA_LIBS"
    2.66              fi
    2.67              AUDIO_SUBDIRS="$AUDIO_SUBDIRS alsa"
    2.68              AUDIO_DRIVERS="$AUDIO_DRIVERS alsa/libaudio_alsa.la"
    2.69 -        else
    2.70 -            AC_MSG_RESULT($have_alsa)
    2.71          fi
    2.72      fi
    2.73  }
     3.1 --- a/src/audio/alsa/SDL_alsa_audio.c	Sat Aug 21 03:55:12 2004 +0000
     3.2 +++ b/src/audio/alsa/SDL_alsa_audio.c	Sat Aug 21 04:20:00 2004 +0000
     3.3 @@ -42,7 +42,9 @@
     3.4  #include "SDL_alsa_audio.h"
     3.5  
     3.6  #ifdef ALSA_DYNAMIC
     3.7 +#ifdef USE_DLVSYM
     3.8  #define __USE_GNU
     3.9 +#endif
    3.10  #include <dlfcn.h>
    3.11  #include "SDL_name.h"
    3.12  #include "SDL_loadso.h"
    3.13 @@ -134,7 +136,11 @@
    3.14  		retval = 0;
    3.15  		for (i = 0; i < SDL_TABLESIZE(alsa_functions); i++) {
    3.16  /*			*alsa_functions[i].func = SDL_LoadFunction(alsa_handle,alsa_functions[i].name);*/
    3.17 +#ifdef USE_DLVSYM
    3.18  			*alsa_functions[i].func = dlvsym(alsa_handle,alsa_functions[i].name,"ALSA_0.9");
    3.19 +			if (!*alsa_functions[i].func)
    3.20 +#endif
    3.21 +				*alsa_functions[i].func = dlsym(alsa_handle,alsa_functions[i].name);
    3.22  			if (!*alsa_functions[i].func) {
    3.23  				retval = -1;
    3.24  				UnloadALSALibrary();