blob: e26d0a8b3df834fa6a79fc9d5ddf50a2bdb8c0e8 [file] [log] [blame]
Josh Coalsonbfeec742002-06-28 23:45:53 +00001# Configure paths for libFLAC
2# "Inspired" by ogg.m4
3
4dnl AM_PATH_LIBFLAC([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
Josh Coalson03a68872006-10-25 00:44:26 +00005dnl Test for libFLAC, and define LIBFLAC_CFLAGS, LIBFLAC_LIBS, LIBFLAC_LIBDIR
Josh Coalsonbfeec742002-06-28 23:45:53 +00006dnl
Josh Coalsona9414542004-07-20 01:24:48 +00007AC_DEFUN([AM_PATH_LIBFLAC],
Josh Coalsonbfeec742002-06-28 23:45:53 +00008[dnl
9dnl Get the cflags and libraries
10dnl
11AC_ARG_WITH(libFLAC,[ --with-libFLAC=PFX Prefix where libFLAC is installed (optional)], libFLAC_prefix="$withval", libFLAC_prefix="")
12AC_ARG_WITH(libFLAC-libraries,[ --with-libFLAC-libraries=DIR Directory where libFLAC library is installed (optional)], libFLAC_libraries="$withval", libFLAC_libraries="")
13AC_ARG_WITH(libFLAC-includes,[ --with-libFLAC-includes=DIR Directory where libFLAC header files are installed (optional)], libFLAC_includes="$withval", libFLAC_includes="")
14AC_ARG_ENABLE(libFLACtest, [ --disable-libFLACtest Do not try to compile and run a test libFLAC program],, enable_libFLACtest=yes)
15
16 if test "x$libFLAC_libraries" != "x" ; then
Josh Coalson03a68872006-10-25 00:44:26 +000017 LIBFLAC_LIBDIR="$libFLAC_libraries"
Josh Coalsonbfeec742002-06-28 23:45:53 +000018 elif test "x$libFLAC_prefix" != "x" ; then
Josh Coalson03a68872006-10-25 00:44:26 +000019 LIBFLAC_LIBDIR="$libFLAC_prefix/lib"
Josh Coalsonbfeec742002-06-28 23:45:53 +000020 elif test "x$prefix" != "xNONE" ; then
Josh Coalson03a68872006-10-25 00:44:26 +000021 LIBFLAC_LIBDIR="$libdir"
Josh Coalsonbfeec742002-06-28 23:45:53 +000022 fi
23
Josh Coalson03a68872006-10-25 00:44:26 +000024 LIBFLAC_LIBS="-L$LIBFLAC_LIBDIR -lFLAC $OGG_LIBS -lm"
Josh Coalsonbfeec742002-06-28 23:45:53 +000025
26 if test "x$libFLAC_includes" != "x" ; then
27 LIBFLAC_CFLAGS="-I$libFLAC_includes"
28 elif test "x$libFLAC_prefix" != "x" ; then
29 LIBFLAC_CFLAGS="-I$libFLAC_prefix/include"
30 elif test "$prefix" != "xNONE"; then
31 LIBFLAC_CFLAGS="-I$prefix/include"
32 fi
33
34 AC_MSG_CHECKING(for libFLAC)
35 no_libFLAC=""
36
37
38 if test "x$enable_libFLACtest" = "xyes" ; then
39 ac_save_CFLAGS="$CFLAGS"
Josh Coalson39eb4712002-07-01 20:37:39 +000040 ac_save_CXXFLAGS="$CXXFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000041 ac_save_LIBS="$LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +000042 ac_save_LDPATH="$LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000043 CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
Josh Coalson39eb4712002-07-01 20:37:39 +000044 CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000045 LIBS="$LIBS $LIBFLAC_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +000046 LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000047dnl
48dnl Now check if the installed libFLAC is sufficiently new.
49dnl
50 rm -f conf.libFLACtest
51 AC_TRY_RUN([
52#include <stdio.h>
53#include <stdlib.h>
54#include <string.h>
55#include <FLAC/format.h>
56
57int main ()
58{
59 system("touch conf.libFLACtest");
60 return 0;
61}
62
63],, no_libFLAC=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
64 CFLAGS="$ac_save_CFLAGS"
Josh Coalson03a68872006-10-25 00:44:26 +000065 CXXFLAGS="$ac_save_CXXFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000066 LIBS="$ac_save_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +000067 LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000068 fi
69
70 if test "x$no_libFLAC" = "x" ; then
71 AC_MSG_RESULT(yes)
72 ifelse([$1], , :, [$1])
73 else
74 AC_MSG_RESULT(no)
75 if test -f conf.libFLACtest ; then
76 :
77 else
78 echo "*** Could not run libFLAC test program, checking why..."
79 CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
Josh Coalson03a68872006-10-25 00:44:26 +000080 CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000081 LIBS="$LIBS $LIBFLAC_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +000082 LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000083 AC_TRY_LINK([
84#include <stdio.h>
85#include <FLAC/format.h>
86], [ return 0; ],
87 [ echo "*** The test program compiled, but did not run. This usually means"
88 echo "*** that the run-time linker is not finding libFLAC or finding the wrong"
89 echo "*** version of libFLAC. If it is not finding libFLAC, you'll need to set your"
90 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
91 echo "*** to the installed location Also, make sure you have run ldconfig if that"
92 echo "*** is required on your system"
93 echo "***"
94 echo "*** If you have an old version installed, it is best to remove it, although"
95 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
96 [ echo "*** The test program failed to compile or link. See the file config.log for the"
97 echo "*** exact error that occured. This usually means libFLAC was incorrectly installed"
98 echo "*** or that you have moved libFLAC since it was installed. In the latter case, you"
99 echo "*** may want to edit the libFLAC-config script: $LIBFLAC_CONFIG" ])
100 CFLAGS="$ac_save_CFLAGS"
Josh Coalson03a68872006-10-25 00:44:26 +0000101 CXXFLAGS="$ac_save_CXXFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +0000102 LIBS="$ac_save_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +0000103 LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +0000104 fi
105 LIBFLAC_CFLAGS=""
Josh Coalson03a68872006-10-25 00:44:26 +0000106 LIBFLAC_LIBDIR=""
Josh Coalsonbfeec742002-06-28 23:45:53 +0000107 LIBFLAC_LIBS=""
108 ifelse([$2], , :, [$2])
109 fi
110 AC_SUBST(LIBFLAC_CFLAGS)
Josh Coalson03a68872006-10-25 00:44:26 +0000111 AC_SUBST(LIBFLAC_LIBDIR)
Josh Coalsonbfeec742002-06-28 23:45:53 +0000112 AC_SUBST(LIBFLAC_LIBS)
113 rm -f conf.libFLACtest
114])