acinclude/alsa.m4
changeset 3342 3da232c5980a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/acinclude/alsa.m4	Sun Oct 04 20:44:04 2009 +0000
     1.3 @@ -0,0 +1,145 @@
     1.4 +##############################################################################
     1.5 +dnl Configure Paths for Alsa
     1.6 +dnl Some modifications by Richard Boulton <richard-alsa@tartarus.org>
     1.7 +dnl Christopher Lansdown <lansdoct@cs.alfred.edu>
     1.8 +dnl Jaroslav Kysela <perex@suse.cz>
     1.9 +dnl Last modification: alsa.m4,v 1.23 2004/01/16 18:14:22 tiwai Exp
    1.10 +dnl AM_PATH_ALSA([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
    1.11 +dnl Test for libasound, and define ALSA_CFLAGS and ALSA_LIBS as appropriate.
    1.12 +dnl enables arguments --with-alsa-prefix=
    1.13 +dnl                   --with-alsa-enc-prefix=
    1.14 +dnl                   --disable-alsatest
    1.15 +dnl
    1.16 +dnl For backwards compatibility, if ACTION_IF_NOT_FOUND is not specified,
    1.17 +dnl and the alsa libraries are not found, a fatal AC_MSG_ERROR() will result.
    1.18 +dnl
    1.19 +AC_DEFUN([AM_PATH_ALSA],
    1.20 +[dnl Save the original CFLAGS, LDFLAGS, and LIBS
    1.21 +alsa_save_CFLAGS="$CFLAGS"
    1.22 +alsa_save_LDFLAGS="$LDFLAGS"
    1.23 +alsa_save_LIBS="$LIBS"
    1.24 +alsa_found=yes
    1.25 +
    1.26 +dnl
    1.27 +dnl Get the cflags and libraries for alsa
    1.28 +dnl
    1.29 +AC_ARG_WITH(alsa-prefix,
    1.30 +[  --with-alsa-prefix=PFX  Prefix where Alsa library is installed(optional)],
    1.31 +[alsa_prefix="$withval"], [alsa_prefix=""])
    1.32 +
    1.33 +AC_ARG_WITH(alsa-inc-prefix,
    1.34 +[  --with-alsa-inc-prefix=PFX  Prefix where include libraries are (optional)],
    1.35 +[alsa_inc_prefix="$withval"], [alsa_inc_prefix=""])
    1.36 +
    1.37 +dnl FIXME: this is not yet implemented
    1.38 +AC_ARG_ENABLE(alsatest,
    1.39 +[  --disable-alsatest      Do not try to compile and run a test Alsa program],
    1.40 +[enable_alsatest="$enableval"],
    1.41 +[enable_alsatest=yes])
    1.42 +
    1.43 +dnl Add any special include directories
    1.44 +AC_MSG_CHECKING(for ALSA CFLAGS)
    1.45 +if test "$alsa_inc_prefix" != "" ; then
    1.46 +	ALSA_CFLAGS="$ALSA_CFLAGS -I$alsa_inc_prefix"
    1.47 +	CFLAGS="$CFLAGS -I$alsa_inc_prefix"
    1.48 +fi
    1.49 +AC_MSG_RESULT($ALSA_CFLAGS)
    1.50 +
    1.51 +dnl add any special lib dirs
    1.52 +AC_MSG_CHECKING(for ALSA LDFLAGS)
    1.53 +if test "$alsa_prefix" != "" ; then
    1.54 +	ALSA_LIBS="$ALSA_LIBS -L$alsa_prefix"
    1.55 +	LDFLAGS="$LDFLAGS $ALSA_LIBS"
    1.56 +fi
    1.57 +
    1.58 +dnl add the alsa library
    1.59 +ALSA_LIBS="$ALSA_LIBS -lasound -lm -ldl -lpthread"
    1.60 +LIBS=`echo $LIBS | sed 's/-lm//'`
    1.61 +LIBS=`echo $LIBS | sed 's/-ldl//'`
    1.62 +LIBS=`echo $LIBS | sed 's/-lpthread//'`
    1.63 +LIBS=`echo $LIBS | sed 's/  //'`
    1.64 +LIBS="$ALSA_LIBS $LIBS"
    1.65 +AC_MSG_RESULT($ALSA_LIBS)
    1.66 +
    1.67 +dnl Check for a working version of libasound that is of the right version.
    1.68 +min_alsa_version=ifelse([$1], ,0.1.1,$1)
    1.69 +AC_MSG_CHECKING(for libasound headers version >= $min_alsa_version)
    1.70 +no_alsa=""
    1.71 +    alsa_min_major_version=`echo $min_alsa_version | \
    1.72 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
    1.73 +    alsa_min_minor_version=`echo $min_alsa_version | \
    1.74 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
    1.75 +    alsa_min_micro_version=`echo $min_alsa_version | \
    1.76 +           sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
    1.77 +
    1.78 +AC_LANG_SAVE
    1.79 +AC_LANG_C
    1.80 +AC_TRY_COMPILE([
    1.81 +#include <alsa/asoundlib.h>
    1.82 +], [
    1.83 +/* ensure backward compatibility */
    1.84 +#if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR)
    1.85 +#define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR
    1.86 +#endif
    1.87 +#if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR)
    1.88 +#define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR
    1.89 +#endif
    1.90 +#if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR)
    1.91 +#define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR
    1.92 +#endif
    1.93 +
    1.94 +#  if(SND_LIB_MAJOR > $alsa_min_major_version)
    1.95 +  exit(0);
    1.96 +#  else
    1.97 +#    if(SND_LIB_MAJOR < $alsa_min_major_version)
    1.98 +#       error not present
    1.99 +#    endif
   1.100 +
   1.101 +#   if(SND_LIB_MINOR > $alsa_min_minor_version)
   1.102 +  exit(0);
   1.103 +#   else
   1.104 +#     if(SND_LIB_MINOR < $alsa_min_minor_version)
   1.105 +#          error not present
   1.106 +#      endif
   1.107 +
   1.108 +#      if(SND_LIB_SUBMINOR < $alsa_min_micro_version)
   1.109 +#        error not present
   1.110 +#      endif
   1.111 +#    endif
   1.112 +#  endif
   1.113 +exit(0);
   1.114 +],
   1.115 +  [AC_MSG_RESULT(found.)],
   1.116 +  [AC_MSG_RESULT(not present.)
   1.117 +   ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)])
   1.118 +   alsa_found=no]
   1.119 +)
   1.120 +AC_LANG_RESTORE
   1.121 +
   1.122 +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.123 +if test "x$enable_alsatest" = "xyes"; then
   1.124 +AC_CHECK_LIB([asound], [snd_ctl_open],,
   1.125 +	[ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)])
   1.126 +	 alsa_found=no]
   1.127 +)
   1.128 +fi
   1.129 +
   1.130 +if test "x$alsa_found" = "xyes" ; then
   1.131 +   ifelse([$2], , :, [$2])
   1.132 +   LIBS=`echo $LIBS | sed 's/-lasound//g'`
   1.133 +   LIBS=`echo $LIBS | sed 's/  //'`
   1.134 +   LIBS="-lasound $LIBS"
   1.135 +fi
   1.136 +if test "x$alsa_found" = "xno" ; then
   1.137 +   ifelse([$3], , :, [$3])
   1.138 +   CFLAGS="$alsa_save_CFLAGS"
   1.139 +   LDFLAGS="$alsa_save_LDFLAGS"
   1.140 +   LIBS="$alsa_save_LIBS"
   1.141 +   ALSA_CFLAGS=""
   1.142 +   ALSA_LIBS=""
   1.143 +fi
   1.144 +
   1.145 +dnl That should be it.  Now just export out symbols:
   1.146 +AC_SUBST(ALSA_CFLAGS)
   1.147 +AC_SUBST(ALSA_LIBS)
   1.148 +])