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