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