1# Configure paths for libvorbis
2# Jack Moffitt <jack@icecast.org> 10-21-2000
3# Shamelessly stolen from Owen Taylor and Manish Singh
4# thomasvs added check for vorbis_bitrate_addblock which is new in rc3
5# thomasvs added check for OV_ECTL_RATEMANAGE_SET which is new in 1.0 final
6
7dnl XIPH_PATH_VORBIS([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
8dnl Test for libvorbis, and define VORBIS_CFLAGS and VORBIS_LIBS
9dnl
10AC_DEFUN([XIPH_PATH_VORBIS],
11[dnl
12dnl Get the cflags and libraries
13dnl
14AC_ARG_WITH(vorbis,[  --with-vorbis=PFX   Prefix where libvorbis is installed (optional)], vorbis_prefix="$withval", vorbis_prefix="")
15AC_ARG_WITH(vorbis-libraries,[  --with-vorbis-libraries=DIR   Directory where libvorbis library is installed (optional)], vorbis_libraries="$withval", vorbis_libraries="")
16AC_ARG_WITH(vorbis-includes,[  --with-vorbis-includes=DIR   Directory where libvorbis header files are installed (optional)], vorbis_includes="$withval", vorbis_includes="")
17AC_ARG_ENABLE(vorbistest, [  --disable-vorbistest       Do not try to compile and run a test Vorbis program],, enable_vorbistest=yes)
18
19  if test "x$vorbis_libraries" != "x" ; then
20    VORBIS_LIBS="-L$vorbis_libraries"
21  elif test "x$vorbis_prefix" != "x" ; then
22    VORBIS_LIBS="-L$vorbis_prefix/lib"
23  elif test "x$prefix" != "xNONE"; then
24    VORBIS_LIBS="-L$prefix/lib"
25  fi
26
27  VORBIS_LIBS="$VORBIS_LIBS -lvorbis -lm"
28  VORBISFILE_LIBS="-lvorbisfile"
29  VORBISENC_LIBS="-lvorbisenc"
30
31  if test "x$vorbis_includes" != "x" ; then
32    VORBIS_CFLAGS="-I$vorbis_includes"
33  elif test "x$vorbis_prefix" != "x" ; then
34    VORBIS_CFLAGS="-I$vorbis_prefix/include"
35  elif test "x$prefix" != "xNONE"; then
36    VORBIS_CFLAGS="-I$prefix/include"
37  fi
38
39
40  AC_MSG_CHECKING(for Vorbis)
41  no_vorbis=""
42
43
44  if test "x$enable_vorbistest" = "xyes" ; then
45    ac_save_CFLAGS="$CFLAGS"
46    ac_save_LIBS="$LIBS"
47    CFLAGS="$CFLAGS $VORBIS_CFLAGS $OGG_CFLAGS"
48    LIBS="$LIBS $VORBIS_LIBS $VORBISENC_LIBS $OGG_LIBS"
49dnl
50dnl Now check if the installed Vorbis is sufficiently new.
51dnl
52      rm -f conf.vorbistest
53      AC_TRY_RUN([
54#include <stdio.h>
55#include <stdlib.h>
56#include <string.h>
57#include <vorbis/codec.h>
58#include <vorbis/vorbisenc.h>
59
60int main ()
61{
62    vorbis_block 	vb;
63    vorbis_dsp_state	vd;
64    vorbis_info		vi;
65
66    vorbis_info_init (&vi);
67    vorbis_encode_init (&vi, 2, 44100, -1, 128000, -1);
68    vorbis_analysis_init (&vd, &vi);
69    vorbis_block_init (&vd, &vb);
70    /* this function was added in 1.0rc3, so this is what we're testing for */
71    vorbis_bitrate_addblock (&vb);
72
73    /* this define was added in 1.0 final */
74#ifdef OV_ECTL_RATEMANAGE_SET
75    system("touch conf.vorbistest");
76    return 0;
77#else
78    return -1;
79#endif
80}
81
82],, no_vorbis=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
83       CFLAGS="$ac_save_CFLAGS"
84       LIBS="$ac_save_LIBS"
85  fi
86
87  if test "x$no_vorbis" = "x" ; then
88     AC_MSG_RESULT(yes)
89     ifelse([$1], , :, [$1])
90  else
91     AC_MSG_RESULT(no)
92     if test -f conf.vorbistest ; then
93       :
94     else
95       echo "*** Could not run Vorbis test program, checking why..."
96       CFLAGS="$CFLAGS $VORBIS_CFLAGS"
97       LIBS="$LIBS $VORBIS_LIBS $OGG_LIBS"
98       AC_TRY_LINK([
99#include <stdio.h>
100#include <vorbis/codec.h>
101],     [ return 0; ],
102       [ echo "*** The test program compiled, but did not run. This usually means"
103       echo "*** that the run-time linker is not finding Vorbis or finding the wrong"
104       echo "*** version of Vorbis. If it is not finding Vorbis, you'll need to set your"
105       echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
106       echo "*** to the installed location  Also, make sure you have run ldconfig if that"
107       echo "*** is required on your system"
108       echo "***"
109       echo "*** If you have an old version installed, it is best to remove it, although"
110       echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
111       [ echo "*** The test program failed to compile or link. See the file config.log for the"
112       echo "*** exact error that occured. This usually means Vorbis was incorrectly installed"
113       echo "*** or that you have moved Vorbis since it was installed." ])
114       CFLAGS="$ac_save_CFLAGS"
115       LIBS="$ac_save_LIBS"
116     fi
117     VORBIS_CFLAGS=""
118     VORBIS_LIBS=""
119     VORBISFILE_LIBS=""
120     VORBISENC_LIBS=""
121     ifelse([$2], , :, [$2])
122  fi
123  AC_SUBST(VORBIS_CFLAGS)
124  AC_SUBST(VORBIS_LIBS)
125  AC_SUBST(VORBISFILE_LIBS)
126  AC_SUBST(VORBISENC_LIBS)
127  rm -f conf.vorbistest
128])
129