1dnl Configure Paths for Alsa 2dnl Some modifications by Richard Boulton <richard-alsa@tartarus.org> 3dnl Christopher Lansdown <lansdoct@cs.alfred.edu> 4dnl Jaroslav Kysela <perex@perex.cz> 5dnl Last modification: $Id: alsa.m4,v 1.24 2004/09/15 18:48:07 tiwai Exp $ 6dnl 7dnl AM_PATH_ALSA([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) 8dnl Test for libasound, and define ALSA_CFLAGS, ALSA_LIBS and 9dnl ALSA_TOPOLOGY_LIBS as appropriate. 10dnl 11dnl enables arguments --with-alsa-prefix= 12dnl --with-alsa-inc-prefix= 13dnl --disable-alsatest 14dnl 15dnl For backwards compatibility, if ACTION_IF_NOT_FOUND is not specified, 16dnl and the alsa libraries are not found, a fatal AC_MSG_ERROR() will result. 17dnl 18 19AC_DEFUN([AM_PATH_ALSA], 20[dnl Save the original CFLAGS, LDFLAGS, and LIBS 21alsa_save_CFLAGS="$CFLAGS" 22alsa_save_LDFLAGS="$LDFLAGS" 23alsa_save_LIBS="$LIBS" 24alsa_found=yes 25alsa_topology_found=no 26 27dnl 28dnl Get the cflags and libraries for alsa 29dnl 30AC_ARG_WITH(alsa-prefix, 31 AS_HELP_STRING([--with-alsa-prefix=PFX], [Prefix where Alsa library is installed(optional)]), 32 [alsa_prefix="$withval"], [alsa_prefix=""]) 33 34AC_ARG_WITH(alsa-inc-prefix, 35 AS_HELP_STRING([--with-alsa-inc-prefix=PFX], [Prefix where include libraries are (optional)]), 36 [alsa_inc_prefix="$withval"], [alsa_inc_prefix=""]) 37 38AC_ARG_ENABLE(alsa-topology, 39 AS_HELP_STRING([--enable-alsatopology], [Force to use the Alsa topology library]), 40 [enable_atopology="$enableval"], 41 [enable_atopology=no]) 42 43AC_ARG_ENABLE(alsatest, 44 AS_HELP_STRING([--disable-alsatest], [Do not try to compile and run a test Alsa program]), 45 [enable_alsatest="$enableval"], 46 [enable_alsatest=yes]) 47 48dnl Add any special include directories 49AC_MSG_CHECKING(for ALSA CFLAGS) 50if test "$alsa_inc_prefix" != "" ; then 51 ALSA_CFLAGS="$ALSA_CFLAGS -I$alsa_inc_prefix" 52 CFLAGS="$CFLAGS -I$alsa_inc_prefix" 53fi 54AC_MSG_RESULT($ALSA_CFLAGS) 55 56AC_CHECK_LIB(c, dlopen, LIBDL="", [AC_CHECK_LIB(dl, dlopen, LIBDL="-ldl")]) 57 58dnl add any special lib dirs 59AC_MSG_CHECKING(for ALSA LDFLAGS) 60if test "$alsa_prefix" != "" ; then 61 ALSA_LIBS="$ALSA_LIBS -L$alsa_prefix" 62 LDFLAGS="$LDFLAGS $ALSA_LIBS" 63fi 64 65dnl add the alsa library 66ALSA_LIBS="$ALSA_LIBS -lasound -lm $LIBDL -lpthread" 67LIBS="$ALSA_LIBS $LIBS" 68AC_MSG_RESULT($ALSA_LIBS) 69 70dnl Check for a working version of libasound that is of the right version. 71if test "x$enable_alsatest" = "xyes"; then 72 73AC_MSG_CHECKING([required libasound headers version]) 74min_alsa_version=ifelse([$1], , 0.1.1, $1) 75no_alsa="" 76 alsa_min_major_version=`echo $min_alsa_version | \ 77 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` 78 alsa_min_minor_version=`echo $min_alsa_version | \ 79 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` 80 alsa_min_micro_version=`echo $min_alsa_version | \ 81 sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` 82AC_MSG_RESULT($alsa_min_major_version.$alsa_min_minor_version.$alsa_min_micro_version) 83 84AC_LANG_PUSH([C]) 85AC_MSG_CHECKING([for libasound headers version >= $alsa_min_major_version.$alsa_min_minor_version.$alsa_min_micro_version ($min_alsa_version)]) 86AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 87#include <alsa/asoundlib.h> 88]], [[ 89/* ensure backward compatibility */ 90#if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR) 91#define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR 92#endif 93#if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR) 94#define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR 95#endif 96#if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR) 97#define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR 98#endif 99 100# if(SND_LIB_MAJOR > $alsa_min_major_version) 101 exit(0); 102# else 103# if(SND_LIB_MAJOR < $alsa_min_major_version) 104# error not present 105# endif 106 107# if(SND_LIB_MINOR > $alsa_min_minor_version) 108 exit(0); 109# else 110# if(SND_LIB_MINOR < $alsa_min_minor_version) 111# error not present 112# endif 113 114# if(SND_LIB_SUBMINOR < $alsa_min_micro_version) 115# error not present 116# endif 117# endif 118# endif 119exit(0); 120]])], 121 [AC_MSG_RESULT(found.)], 122 [AC_MSG_RESULT(not present.) 123 ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)]) 124 alsa_found=no] 125) 126AC_LANG_POP([C]) 127 128AC_LANG_PUSH([C]) 129AC_MSG_CHECKING([for libatopology (sound headers version > 1.1.9)]) 130AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 131#include <alsa/asoundlib.h> 132#include <alsa/topology.h> 133]], [[ 134/* ensure backward compatibility */ 135#if !defined(SND_LIB_VERSION) 136#define SND_LIB_VERSION 0 137#endif 138#if SND_LIB_VERSION > 0x00010109 139 exit(0); 140#else 141# error not present 142#endif 143exit(0); 144]])], 145 [AC_MSG_RESULT(yes) 146 enable_atopology="yes"], 147 [AC_MSG_RESULT(no)] 148) 149AC_LANG_POP([C]) 150fi 151 152dnl Now that we know that we have the right version, let's see if we have the library and not just the headers. 153if test "x$enable_alsatest" = "xyes"; then 154AC_CHECK_LIB([asound], [snd_ctl_open],, 155 [ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)]) 156 alsa_found=no] 157) 158if test "x$enable_atopology" = "xyes"; then 159alsa_topology_found=yes 160alsa_save_LIBS2="$LIBS" 161AC_CHECK_LIB([atopology], [snd_tplg_new],, 162 [ifelse([$3], , [AC_MSG_ERROR(No linkable libatopology was found.)]) 163 alsa_topology_found=no, 164] 165) 166LIBS="$alsa_save_LIBS2" 167fi 168else 169if test "x$enable_atopology" = "xyes"; then 170 alsa_topology_found=yes 171fi 172fi 173 174if test "x$alsa_found" = "xyes" ; then 175 ifelse([$2], , :, [$2]) 176 LIBS=`echo $LIBS | sed 's/-lasound//g'` 177 LIBS=`echo $LIBS | sed 's/ //'` 178 LIBS="-lasound $LIBS" 179fi 180if test "x$alsa_found" = "xno" ; then 181 ifelse([$3], , :, [$3]) 182 CFLAGS="$alsa_save_CFLAGS" 183 LDFLAGS="$alsa_save_LDFLAGS" 184 LIBS="$alsa_save_LIBS" 185 ALSA_CFLAGS="" 186 ALSA_LIBS="" 187 ALSA_TOPOLOGY_LIBS="" 188fi 189 190dnl add the alsa topology library; must be at the end 191AC_MSG_CHECKING(for ALSA topology LDFLAGS) 192if test "x$alsa_topology_found" = "xyes"; then 193 ALSA_TOPOLOGY_LIBS="$ALSA_TOPOLOGY_LIBS -latopology" 194fi 195AC_MSG_RESULT($ALSA_TOPOLOGY_LIBS) 196 197dnl That should be it. Now just export out symbols: 198AC_SUBST(ALSA_CFLAGS) 199AC_SUBST(ALSA_LIBS) 200AC_SUBST(ALSA_TOPOLOGY_LIBS) 201]) 202