alsa.m4 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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@perex.cz>
  5. dnl Last modification: $Id: alsa.m4,v 1.24 2004/09/15 18:48:07 tiwai Exp $
  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=
  10. dnl --disable-alsatest
  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
  15. AC_DEFUN([AM_PATH_ALSA],
  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. dnl
  22. dnl Get the cflags and libraries for alsa
  23. dnl
  24. AC_ARG_WITH(alsa-prefix,
  25. [ --with-alsa-prefix=PFX Prefix where Alsa library is installed(optional)],
  26. [alsa_prefix="$withval"], [alsa_prefix=""])
  27. AC_ARG_WITH(alsa-inc-prefix,
  28. [ --with-alsa-inc-prefix=PFX Prefix where include libraries are (optional)],
  29. [alsa_inc_prefix="$withval"], [alsa_inc_prefix=""])
  30. dnl FIXME: this is not yet implemented
  31. AC_ARG_ENABLE(alsatest,
  32. [ --disable-alsatest Do not try to compile and run a test Alsa program],
  33. [enable_alsatest="$enableval"],
  34. [enable_alsatest=yes])
  35. dnl Add any special include directories
  36. AC_MSG_CHECKING(for ALSA CFLAGS)
  37. if test "$alsa_inc_prefix" != "" ; then
  38. ALSA_CFLAGS="$ALSA_CFLAGS -I$alsa_inc_prefix"
  39. CFLAGS="$CFLAGS -I$alsa_inc_prefix"
  40. fi
  41. AC_MSG_RESULT($ALSA_CFLAGS)
  42. dnl add any special lib dirs
  43. AC_MSG_CHECKING(for ALSA LDFLAGS)
  44. if test "$alsa_prefix" != "" ; then
  45. ALSA_LIBS="$ALSA_LIBS -L$alsa_prefix"
  46. LDFLAGS="$LDFLAGS $ALSA_LIBS"
  47. fi
  48. dnl add the alsa library
  49. ALSA_LIBS="$ALSA_LIBS -lasound -lm -ldl -lpthread"
  50. LIBS="$ALSA_LIBS $LIBS"
  51. AC_MSG_RESULT($ALSA_LIBS)
  52. dnl Check for a working version of libasound that is of the right version.
  53. if test "x$enable_alsatest" = "xyes"; then
  54. min_alsa_version=ifelse([$1], ,0.1.1,$1)
  55. AC_MSG_CHECKING(for libasound headers version >= $min_alsa_version)
  56. no_alsa=""
  57. alsa_min_major_version=`echo $min_alsa_version | \
  58. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
  59. alsa_min_minor_version=`echo $min_alsa_version | \
  60. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
  61. alsa_min_micro_version=`echo $min_alsa_version | \
  62. sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
  63. AC_LANG_SAVE
  64. AC_LANG_C
  65. AC_TRY_COMPILE([
  66. #include <alsa/asoundlib.h>
  67. ], [
  68. /* ensure backward compatibility */
  69. #if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR)
  70. #define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR
  71. #endif
  72. #if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR)
  73. #define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR
  74. #endif
  75. #if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR)
  76. #define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR
  77. #endif
  78. # if(SND_LIB_MAJOR > $alsa_min_major_version)
  79. exit(0);
  80. # else
  81. # if(SND_LIB_MAJOR < $alsa_min_major_version)
  82. # error not present
  83. # endif
  84. # if(SND_LIB_MINOR > $alsa_min_minor_version)
  85. exit(0);
  86. # else
  87. # if(SND_LIB_MINOR < $alsa_min_minor_version)
  88. # error not present
  89. # endif
  90. # if(SND_LIB_SUBMINOR < $alsa_min_micro_version)
  91. # error not present
  92. # endif
  93. # endif
  94. # endif
  95. exit(0);
  96. ],
  97. [AC_MSG_RESULT(found.)],
  98. [AC_MSG_RESULT(not present.)
  99. ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)])
  100. alsa_found=no]
  101. )
  102. AC_LANG_RESTORE
  103. fi
  104. dnl Now that we know that we have the right version, let's see if we have the library and not just the headers.
  105. if test "x$enable_alsatest" = "xyes"; then
  106. AC_CHECK_LIB([asound], [snd_ctl_open],,
  107. [ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)])
  108. alsa_found=no]
  109. )
  110. fi
  111. if test "x$alsa_found" = "xyes" ; then
  112. ifelse([$2], , :, [$2])
  113. LIBS=`echo $LIBS | sed 's/-lasound//g'`
  114. LIBS=`echo $LIBS | sed 's/ //'`
  115. LIBS="-lasound $LIBS"
  116. fi
  117. if test "x$alsa_found" = "xno" ; then
  118. ifelse([$3], , :, [$3])
  119. CFLAGS="$alsa_save_CFLAGS"
  120. LDFLAGS="$alsa_save_LDFLAGS"
  121. LIBS="$alsa_save_LIBS"
  122. ALSA_CFLAGS=""
  123. ALSA_LIBS=""
  124. fi
  125. dnl That should be it. Now just export out symbols:
  126. AC_SUBST(ALSA_CFLAGS)
  127. AC_SUBST(ALSA_LIBS)
  128. ])