no need for feature, it's in common various AC_HELP_STRING changes
[platform/upstream/gst-plugins-good.git] / m4 / gst-alsa.m4
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>
5 dnl Last modification: 07/01/2001
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  (this has no effect, as yet)
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
22 dnl
23 dnl Get the cflags and libraries for alsa
24 dnl
25 AC_ARG_WITH(alsa-prefix,
26   AC_HELP_STRING([--with-alsa-prefix=PFX],
27                  [prefix where Alsa library is installed(optional)]),
28   [alsa_prefix="$withval"], [alsa_prefix=""])
29
30 AC_ARG_WITH(alsa-inc-prefix,
31   AC_HELP_STRING([--with-alsa-inc-prefix=PFX],
32                  [prefix where include libraries are (optional)]),
33   [alsa_inc_prefix="$withval"], [alsa_inc_prefix=""])
34
35 dnl FIXME: this is not yet implemented
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])
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
57 ALSA_LIBS="$ALSA_LIBS -lasound -lm -ldl"
58 LIBS=`echo $LIBS | sed 's/-lm//'`
59 LIBS=`echo $LIBS | sed 's/-ldl//'`
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 <sys/asoundlib.h>
79 ], [
80 void main(void)
81 {
82 /* ensure backward compatibility */
83 #if !defined(SND_LIB_MAJOR) && defined(SOUNDLIB_VERSION_MAJOR)
84 #define SND_LIB_MAJOR SOUNDLIB_VERSION_MAJOR
85 #endif
86 #if !defined(SND_LIB_MINOR) && defined(SOUNDLIB_VERSION_MINOR)
87 #define SND_LIB_MINOR SOUNDLIB_VERSION_MINOR
88 #endif
89 #if !defined(SND_LIB_SUBMINOR) && defined(SOUNDLIB_VERSION_SUBMINOR)
90 #define SND_LIB_SUBMINOR SOUNDLIB_VERSION_SUBMINOR
91 #endif
92
93 #  if(SND_LIB_MAJOR > $alsa_min_major_version)
94   exit(0);
95 #  else
96 #    if(SND_LIB_MAJOR < $alsa_min_major_version)
97 #       error not present
98 #    endif
99
100 #   if(SND_LIB_MINOR > $alsa_min_minor_version)
101   exit(0);
102 #   else
103 #     if(SND_LIB_MINOR < $alsa_min_minor_version)
104 #          error not present
105 #      endif
106
107 #      if(SND_LIB_SUBMINOR < $alsa_min_micro_version)
108 #        error not present
109 #      endif
110 #    endif
111 #  endif
112 exit(0);
113 }
114 ],
115   [AC_MSG_RESULT(found.)],
116   [AC_MSG_RESULT(not present.)
117    ifelse([$3], , [AC_MSG_ERROR(Sufficiently new version of libasound not found.)])
118    alsa_found=no]
119 )
120 AC_LANG_RESTORE
121
122 dnl Now that we know that we have the right version, let's see if we have the library and not just the headers.
123 AC_CHECK_LIB([asound], [snd_seq_create_event],,
124         [ifelse([$3], , [AC_MSG_ERROR(No linkable libasound was found.)])
125          alsa_found=no]
126 )
127
128 if test "x$alsa_found" = "xyes" ; then
129    ifelse([$2], , :, [$2])
130    LIBS=`echo $LIBS | sed 's/-lasound//g'`
131    LIBS=`echo $LIBS | sed 's/  //'`
132    LIBS="-lasound $LIBS"
133 fi
134 if test "x$alsa_found" = "xno" ; then
135    ifelse([$3], , :, [$3])
136    CFLAGS="$alsa_save_CFLAGS"
137    LDFLAGS="$alsa_save_LDFLAGS"
138    LIBS="$alsa_save_LIBS"
139    ALSA_CFLAGS=""
140    ALSA_LIBS=""
141 fi
142
143 dnl That should be it.  Now just export out symbols:
144 AC_SUBST(ALSA_CFLAGS)
145 AC_SUBST(ALSA_LIBS)
146 ])