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