blob: da7354e988c9d200279621424781d23caf38c22c [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
Erik de Castro Lopoc08b6792012-02-13 19:39:55 +110017 LIBFLAC_LIBS="-L$libFLAC_libraries"
18 elif test "x$libFLAC_prefix" = "xno" || test "x$libFLAC_prefix" = "xyes" ; then
19 LIBFLAC_LIBS=""
Josh Coalsonbfeec742002-06-28 23:45:53 +000020 elif test "x$libFLAC_prefix" != "x" ; then
Erik de Castro Lopoc08b6792012-02-13 19:39:55 +110021 LIBFLAC_LIBS="-L$libFLAC_prefix/lib"
22 elif test "x$prefix" != "xNONE"; then
23 LIBFLAC_LIBS="-L$prefix/lib"
Josh Coalsonbfeec742002-06-28 23:45:53 +000024 fi
25
Erik de Castro Lopoc08b6792012-02-13 19:39:55 +110026 if test "x$libFLAC_prefix" != "xno" ; then
27 LIBFLAC_LIBS="$LIBFLAC_LIBS -lFLAC $OGG_LIBS -lm"
28 fi
Josh Coalsonbfeec742002-06-28 23:45:53 +000029
30 if test "x$libFLAC_includes" != "x" ; then
31 LIBFLAC_CFLAGS="-I$libFLAC_includes"
32 elif test "x$libFLAC_prefix" != "x" ; then
33 LIBFLAC_CFLAGS="-I$libFLAC_prefix/include"
34 elif test "$prefix" != "xNONE"; then
Josh Coalson32e85a72006-11-13 06:42:51 +000035 LIBFLAC_CFLAGS=""
Josh Coalsonbfeec742002-06-28 23:45:53 +000036 fi
37
38 AC_MSG_CHECKING(for libFLAC)
39 no_libFLAC=""
40
41
42 if test "x$enable_libFLACtest" = "xyes" ; then
43 ac_save_CFLAGS="$CFLAGS"
Josh Coalson39eb4712002-07-01 20:37:39 +000044 ac_save_CXXFLAGS="$CXXFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000045 ac_save_LIBS="$LIBS"
Josh Coalson60a43f02007-06-14 05:25:35 +000046 ac_save_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000047 CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
Josh Coalson39eb4712002-07-01 20:37:39 +000048 CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000049 LIBS="$LIBS $LIBFLAC_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +000050 LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000051dnl
52dnl Now check if the installed libFLAC is sufficiently new.
53dnl
54 rm -f conf.libFLACtest
55 AC_TRY_RUN([
56#include <stdio.h>
57#include <stdlib.h>
58#include <string.h>
59#include <FLAC/format.h>
60
61int main ()
62{
63 system("touch conf.libFLACtest");
64 return 0;
65}
66
67],, no_libFLAC=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
68 CFLAGS="$ac_save_CFLAGS"
Josh Coalson03a68872006-10-25 00:44:26 +000069 CXXFLAGS="$ac_save_CXXFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000070 LIBS="$ac_save_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +000071 LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000072 fi
73
74 if test "x$no_libFLAC" = "x" ; then
75 AC_MSG_RESULT(yes)
76 ifelse([$1], , :, [$1])
77 else
78 AC_MSG_RESULT(no)
79 if test -f conf.libFLACtest ; then
80 :
81 else
82 echo "*** Could not run libFLAC test program, checking why..."
83 CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
Josh Coalson03a68872006-10-25 00:44:26 +000084 CXXFLAGS="$CXXFLAGS $LIBFLAC_CFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +000085 LIBS="$LIBS $LIBFLAC_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +000086 LD_LIBRARY_PATH="$LIBFLAC_LIBDIR:$LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +000087 AC_TRY_LINK([
88#include <stdio.h>
89#include <FLAC/format.h>
90], [ return 0; ],
91 [ echo "*** The test program compiled, but did not run. This usually means"
92 echo "*** that the run-time linker is not finding libFLAC or finding the wrong"
93 echo "*** version of libFLAC. If it is not finding libFLAC, you'll need to set your"
94 echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
95 echo "*** to the installed location Also, make sure you have run ldconfig if that"
96 echo "*** is required on your system"
97 echo "***"
98 echo "*** If you have an old version installed, it is best to remove it, although"
99 echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
100 [ echo "*** The test program failed to compile or link. See the file config.log for the"
101 echo "*** exact error that occured. This usually means libFLAC was incorrectly installed"
102 echo "*** or that you have moved libFLAC since it was installed. In the latter case, you"
103 echo "*** may want to edit the libFLAC-config script: $LIBFLAC_CONFIG" ])
104 CFLAGS="$ac_save_CFLAGS"
Josh Coalson03a68872006-10-25 00:44:26 +0000105 CXXFLAGS="$ac_save_CXXFLAGS"
Josh Coalsonbfeec742002-06-28 23:45:53 +0000106 LIBS="$ac_save_LIBS"
Josh Coalson03a68872006-10-25 00:44:26 +0000107 LD_LIBRARY_PATH="$ac_save_LD_LIBRARY_PATH"
Josh Coalsonbfeec742002-06-28 23:45:53 +0000108 fi
109 LIBFLAC_CFLAGS=""
Josh Coalson03a68872006-10-25 00:44:26 +0000110 LIBFLAC_LIBDIR=""
Josh Coalsonbfeec742002-06-28 23:45:53 +0000111 LIBFLAC_LIBS=""
112 ifelse([$2], , :, [$2])
113 fi
114 AC_SUBST(LIBFLAC_CFLAGS)
Josh Coalson03a68872006-10-25 00:44:26 +0000115 AC_SUBST(LIBFLAC_LIBDIR)
Josh Coalsonbfeec742002-06-28 23:45:53 +0000116 AC_SUBST(LIBFLAC_LIBS)
117 rm -f conf.libFLACtest
118])