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#include <stdlib.h> 89]], [[ 90/* ensure backward compatibility */ 91#if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR) 92#define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR 93#endif 94#if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR) 95#define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR 96#endif 97#if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR) 98#define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR 99#endif 100 101# if(SND_LIB_MAJOR > $alsa_min_major_version) 102 exit(0); 103# else 104# if(SND_LIB_MAJOR < $alsa_min_major_version) 105# error not present 106# endif 107 108# if(SND_LIB_MINOR > $alsa_min_minor_version) 109 exit(0); 110# else 111# if(SND_LIB_MINOR < $alsa_min_minor_version) 112# error not present 113# endif 114 115# if(SND_LIB_SUBMINOR < $alsa_min_micro_version) 116# error not present 117# endif 118# endif 119# endif 120exit(0); 121]])], 122 [AC_MSG_RESULT(found.)], 123 [AC_MSG_RESULT(not present.) 124 ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)]) 125 alsa_found=no] 126) 127AC_LANG_POP([C]) 128 129AC_LANG_PUSH([C]) 130AC_MSG_CHECKING([for libatopology (sound headers version > 1.1.9)]) 131AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 132#include <alsa/asoundlib.h> 133#include <alsa/topology.h> 134#include <stdlib.h> 135]], [[ 136/* ensure backward compatibility */ 137#if !defined(SND_LIB_VERSION) 138#define SND_LIB_VERSION 0 139#endif 140#if SND_LIB_VERSION > 0x00010109 141 exit(0); 142#else 143# error not present 144#endif 145exit(0); 146]])], 147 [AC_MSG_RESULT(yes) 148 enable_atopology="yes"], 149 [AC_MSG_RESULT(no)] 150) 151AC_LANG_POP([C]) 152fi 153 154dnl Now that we know that we have the right version, let's see if we have the library and not just the headers. 155if test "x$enable_alsatest" = "xyes"; then 156AC_CHECK_LIB([asound], [snd_ctl_open],, 157 [ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)]) 158 alsa_found=no] 159) 160if test "x$enable_atopology" = "xyes"; then 161alsa_topology_found=yes 162alsa_save_LIBS2="$LIBS" 163AC_CHECK_LIB([atopology], [snd_tplg_new],, 164 [ifelse([$3], , [AC_MSG_ERROR(No linkable libatopology was found.)]) 165 alsa_topology_found=no, 166] 167) 168LIBS="$alsa_save_LIBS2" 169fi 170else 171if test "x$enable_atopology" = "xyes"; then 172 alsa_topology_found=yes 173fi 174fi 175 176if test "x$alsa_found" = "xyes" ; then 177 ifelse([$2], , :, [$2]) 178 LIBS=`echo $LIBS | sed 's/-lasound//g'` 179 LIBS=`echo $LIBS | sed 's/ //'` 180 LIBS="-lasound $LIBS" 181fi 182if test "x$alsa_found" = "xno" ; then 183 ifelse([$3], , :, [$3]) 184 CFLAGS="$alsa_save_CFLAGS" 185 LDFLAGS="$alsa_save_LDFLAGS" 186 LIBS="$alsa_save_LIBS" 187 ALSA_CFLAGS="" 188 ALSA_LIBS="" 189 ALSA_TOPOLOGY_LIBS="" 190fi 191 192dnl add the alsa topology library; must be at the end 193AC_MSG_CHECKING(for ALSA topology LDFLAGS) 194if test "x$alsa_topology_found" = "xyes"; then 195 ALSA_TOPOLOGY_LIBS="$ALSA_TOPOLOGY_LIBS -latopology" 196fi 197AC_MSG_RESULT($ALSA_TOPOLOGY_LIBS) 198 199dnl That should be it. Now just export out symbols: 200AC_SUBST(ALSA_CFLAGS) 201AC_SUBST(ALSA_LIBS) 202AC_SUBST(ALSA_TOPOLOGY_LIBS) 203]) 204