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