| 1 | ############################################################################## |
| 2 | dnl Configure Paths for Alsa |
| 3 | dnl Some modifications by Richard Boulton <richard-alsa@tartarus.org> |
| 4 | dnl Christopher Lansdown <lansdoct@cs.alfred.edu> |
| 5 | dnl Jaroslav Kysela <perex@suse.cz> |
| 6 | dnl Last modification: alsa.m4,v 1.23 2004/01/16 18:14:22 tiwai Exp |
| 7 | dnl AM_PATH_ALSA([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) |
| 8 | dnl Test for libasound, and define ALSA_CFLAGS and ALSA_LIBS as appropriate. |
| 9 | dnl enables arguments --with-alsa-prefix= |
| 10 | dnl --with-alsa-enc-prefix= |
| 11 | dnl --disable-alsatest |
| 12 | dnl |
| 13 | dnl For backwards compatibility, if ACTION_IF_NOT_FOUND is not specified, |
| 14 | dnl and the alsa libraries are not found, a fatal AC_MSG_ERROR() will result. |
| 15 | dnl |
| 16 | AC_DEFUN([AM_PATH_ALSA], |
| 17 | [dnl Save the original CFLAGS, LDFLAGS, and LIBS |
| 18 | alsa_save_CFLAGS="$CFLAGS" |
| 19 | alsa_save_LDFLAGS="$LDFLAGS" |
| 20 | alsa_save_LIBS="$LIBS" |
| 21 | alsa_found=yes |
| 22 | |
| 23 | dnl |
| 24 | dnl Get the cflags and libraries for alsa |
| 25 | dnl |
| 26 | AC_ARG_WITH(alsa-prefix, |
| 27 | [ --with-alsa-prefix=PFX Prefix where Alsa library is installed(optional)], |
| 28 | [alsa_prefix="$withval"], [alsa_prefix=""]) |
| 29 | |
| 30 | AC_ARG_WITH(alsa-inc-prefix, |
| 31 | [ --with-alsa-inc-prefix=PFX Prefix where include libraries are (optional)], |
| 32 | [alsa_inc_prefix="$withval"], [alsa_inc_prefix=""]) |
| 33 | |
| 34 | dnl FIXME: this is not yet implemented |
| 35 | AC_ARG_ENABLE(alsatest, |
| 36 | [ --disable-alsatest Do not try to compile and run a test Alsa program], |
| 37 | [enable_alsatest="$enableval"], |
| 38 | [enable_alsatest=yes]) |
| 39 | |
| 40 | dnl Add any special include directories |
| 41 | AC_MSG_CHECKING(for ALSA CFLAGS) |
| 42 | if test "$alsa_inc_prefix" != "" ; then |
| 43 | ALSA_CFLAGS="$ALSA_CFLAGS -I$alsa_inc_prefix" |
| 44 | CFLAGS="$CFLAGS -I$alsa_inc_prefix" |
| 45 | fi |
| 46 | AC_MSG_RESULT($ALSA_CFLAGS) |
| 47 | |
| 48 | dnl add any special lib dirs |
| 49 | AC_MSG_CHECKING(for ALSA LDFLAGS) |
| 50 | if test "$alsa_prefix" != "" ; then |
| 51 | ALSA_LIBS="$ALSA_LIBS -L$alsa_prefix" |
| 52 | LDFLAGS="$LDFLAGS $ALSA_LIBS" |
| 53 | fi |
| 54 | |
| 55 | dnl add the alsa library |
| 56 | ALSA_LIBS="$ALSA_LIBS -lasound -lm -ldl -lpthread" |
| 57 | LIBS=`echo $LIBS | sed 's/-lm//'` |
| 58 | LIBS=`echo $LIBS | sed 's/-ldl//'` |
| 59 | LIBS=`echo $LIBS | sed 's/-lpthread//'` |
| 60 | LIBS=`echo $LIBS | sed 's/ //'` |
| 61 | LIBS="$ALSA_LIBS $LIBS" |
| 62 | AC_MSG_RESULT($ALSA_LIBS) |
| 63 | |
| 64 | dnl Check for a working version of libasound that is of the right version. |
| 65 | min_alsa_version=ifelse([$1], ,0.1.1,$1) |
| 66 | AC_MSG_CHECKING(for libasound headers version >= $min_alsa_version) |
| 67 | no_alsa="" |
| 68 | alsa_min_major_version=`echo $min_alsa_version | \ |
| 69 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` |
| 70 | alsa_min_minor_version=`echo $min_alsa_version | \ |
| 71 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` |
| 72 | alsa_min_micro_version=`echo $min_alsa_version | \ |
| 73 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` |
| 74 | |
| 75 | AC_LANG_SAVE |
| 76 | AC_LANG_C |
| 77 | AC_TRY_COMPILE([ |
| 78 | #include <alsa/asoundlib.h> |
| 79 | ], [ |
| 80 | /* ensure backward compatibility */ |
| 81 | #if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR) |
| 82 | #define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR |
| 83 | #endif |
| 84 | #if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR) |
| 85 | #define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR |
| 86 | #endif |
| 87 | #if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR) |
| 88 | #define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR |
| 89 | #endif |
| 90 | |
| 91 | # if(SND_LIB_MAJOR > $alsa_min_major_version) |
| 92 | exit(0); |
| 93 | # else |
| 94 | # if(SND_LIB_MAJOR < $alsa_min_major_version) |
| 95 | # error not present |
| 96 | # endif |
| 97 | |
| 98 | # if(SND_LIB_MINOR > $alsa_min_minor_version) |
| 99 | exit(0); |
| 100 | # else |
| 101 | # if(SND_LIB_MINOR < $alsa_min_minor_version) |
| 102 | # error not present |
| 103 | # endif |
| 104 | |
| 105 | # if(SND_LIB_SUBMINOR < $alsa_min_micro_version) |
| 106 | # error not present |
| 107 | # endif |
| 108 | # endif |
| 109 | # endif |
| 110 | exit(0); |
| 111 | ], |
| 112 | [AC_MSG_RESULT(found.)], |
| 113 | [AC_MSG_RESULT(not present.) |
| 114 | ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)]) |
| 115 | alsa_found=no] |
| 116 | ) |
| 117 | AC_LANG_RESTORE |
| 118 | |
| 119 | dnl Now that we know that we have the right version, let's see if we have the library and not just the headers. |
| 120 | if test "x$enable_alsatest" = "xyes"; then |
| 121 | AC_CHECK_LIB([asound], [snd_ctl_open],, |
| 122 | [ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)]) |
| 123 | alsa_found=no] |
| 124 | ) |
| 125 | fi |
| 126 | |
| 127 | if test "x$alsa_found" = "xyes" ; then |
| 128 | ifelse([$2], , :, [$2]) |
| 129 | LIBS=`echo $LIBS | sed 's/-lasound//g'` |
| 130 | LIBS=`echo $LIBS | sed 's/ //'` |
| 131 | LIBS="-lasound $LIBS" |
| 132 | fi |
| 133 | if test "x$alsa_found" = "xno" ; then |
| 134 | ifelse([$3], , :, [$3]) |
| 135 | CFLAGS="$alsa_save_CFLAGS" |
| 136 | LDFLAGS="$alsa_save_LDFLAGS" |
| 137 | LIBS="$alsa_save_LIBS" |
| 138 | ALSA_CFLAGS="" |
| 139 | ALSA_LIBS="" |
| 140 | fi |
| 141 | |
| 142 | dnl That should be it. Now just export out symbols: |
| 143 | AC_SUBST(ALSA_CFLAGS) |
| 144 | AC_SUBST(ALSA_LIBS) |
| 145 | ]) |