add autoconf m4 files
[platform/upstream/flac.git] / src / libFLAC / libFLAC.m4
1 # Configure paths for libFLAC
2 # "Inspired" by ogg.m4
3
4 dnl AM_PATH_LIBFLAC([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
5 dnl Test for libFLAC, and define LIBFLAC_CFLAGS and LIBFLAC_LIBS
6 dnl
7 AC_DEFUN(AM_PATH_LIBFLAC,
8 [dnl 
9 dnl Get the cflags and libraries
10 dnl
11 AC_ARG_WITH(libFLAC,[  --with-libFLAC=PFX   Prefix where libFLAC is installed (optional)], libFLAC_prefix="$withval", libFLAC_prefix="")
12 AC_ARG_WITH(libFLAC-libraries,[  --with-libFLAC-libraries=DIR   Directory where libFLAC library is installed (optional)], libFLAC_libraries="$withval", libFLAC_libraries="")
13 AC_ARG_WITH(libFLAC-includes,[  --with-libFLAC-includes=DIR   Directory where libFLAC header files are installed (optional)], libFLAC_includes="$withval", libFLAC_includes="")
14 AC_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
17     LIBFLAC_LIBS="-L$libFLAC_libraries"
18   elif test "x$libFLAC_prefix" != "x" ; then
19     LIBFLAC_LIBS="-L$libFLAC_prefix/lib"
20   elif test "x$prefix" != "xNONE" ; then
21     LIBFLAC_LIBS="-L$prefix/lib"
22   fi
23
24   LIBFLAC_LIBS="$LIBFLAC_LIBS -lFLAC"
25
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"
40     ac_save_LIBS="$LIBS"
41     CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
42     LIBS="$LIBS $LIBFLAC_LIBS"
43 dnl
44 dnl Now check if the installed libFLAC is sufficiently new.
45 dnl
46       rm -f conf.libFLACtest
47       AC_TRY_RUN([
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include <string.h>
51 #include <FLAC/format.h>
52
53 int main ()
54 {
55   system("touch conf.libFLACtest");
56   return 0;
57 }
58
59 ],, no_libFLAC=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
60        CFLAGS="$ac_save_CFLAGS"
61        LIBS="$ac_save_LIBS"
62   fi
63
64   if test "x$no_libFLAC" = "x" ; then
65      AC_MSG_RESULT(yes)
66      ifelse([$1], , :, [$1])     
67   else
68      AC_MSG_RESULT(no)
69      if test -f conf.libFLACtest ; then
70        :
71      else
72        echo "*** Could not run libFLAC test program, checking why..."
73        CFLAGS="$CFLAGS $LIBFLAC_CFLAGS"
74        LIBS="$LIBS $LIBFLAC_LIBS"
75        AC_TRY_LINK([
76 #include <stdio.h>
77 #include <FLAC/format.h>
78 ],     [ return 0; ],
79        [ echo "*** The test program compiled, but did not run. This usually means"
80        echo "*** that the run-time linker is not finding libFLAC or finding the wrong"
81        echo "*** version of libFLAC. If it is not finding libFLAC, you'll need to set your"
82        echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
83        echo "*** to the installed location  Also, make sure you have run ldconfig if that"
84        echo "*** is required on your system"
85        echo "***"
86        echo "*** If you have an old version installed, it is best to remove it, although"
87        echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
88        [ echo "*** The test program failed to compile or link. See the file config.log for the"
89        echo "*** exact error that occured. This usually means libFLAC was incorrectly installed"
90        echo "*** or that you have moved libFLAC since it was installed. In the latter case, you"
91        echo "*** may want to edit the libFLAC-config script: $LIBFLAC_CONFIG" ])
92        CFLAGS="$ac_save_CFLAGS"
93        LIBS="$ac_save_LIBS"
94      fi
95      LIBFLAC_CFLAGS=""
96      LIBFLAC_LIBS=""
97      ifelse([$2], , :, [$2])
98   fi
99   AC_SUBST(LIBFLAC_CFLAGS)
100   AC_SUBST(LIBFLAC_LIBS)
101   rm -f conf.libFLACtest
102 ])