alsa.m4 4.5 KB

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