improved error reporting of file errors (uses boost.system's error_code). Now permiss...
[libtorrent.git] / m4 / ax_boost_filesystem-fixed.m4
blobb9b149f799f5abfef0815f2e9af9013d276833e7
1 # ===========================================================================
2 #          http://autoconf-archive.cryp.to/ax_boost_filesystem.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_BOOST_FILESYSTEM
9 # DESCRIPTION
11 #   Test for Filesystem library from the Boost C++ libraries. The macro
12 #   requires a preceding call to AX_BOOST_BASE. Further documentation is
13 #   available at <http://randspringer.de/boost/index.html>.
15 #   This macro calls:
17 #     AC_SUBST(BOOST_FILESYSTEM_LIB)
19 #   And sets:
21 #     HAVE_BOOST_FILESYSTEM
23 # LAST MODIFICATION
25 #   2008-04-12
27 # COPYLEFT
29 #   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
30 #   Copyright (c) 2008 Michael Tindal
31 #   Copyright (c) 2008 Roman Rybalko <libtorrent@romanr.info> (using BOOST_SYSTEM_LIB)
33 #   Copying and distribution of this file, with or without modification, are
34 #   permitted in any medium without royalty provided the copyright notice
35 #   and this notice are preserved.
37 AC_DEFUN([AX_BOOST_FILESYSTEM],
39         AC_ARG_WITH([boost-filesystem],
40         AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@],
41                    [use the Filesystem library from boost - it is possible to specify a certain library for the linker
42                         e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]),
43         [
44         if test "$withval" = "no"; then
45                         want_boost="no"
46         elif test "$withval" = "yes"; then
47             want_boost="yes"
48             ax_boost_user_filesystem_lib=""
49         else
50                     want_boost="yes"
51                 ax_boost_user_filesystem_lib="$withval"
52                 fi
53         ],
54         [want_boost="yes"]
55         )
57         if test "x$want_boost" = "xyes"; then
58         AC_REQUIRE([AC_PROG_CC])
59                 CPPFLAGS_SAVED="$CPPFLAGS"
60                 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
61                 export CPPFLAGS
63                 LDFLAGS_SAVED="$LDFLAGS"
64                 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
65                 export LDFLAGS
66                 
67                 LIBS_SAVED=$LIBS
68                 LIBS="$LIBS $BOOST_SYSTEM_LIB"
69                 export LIBS
71         AC_CACHE_CHECK(whether the Boost::Filesystem library is available,
72                                            ax_cv_boost_filesystem,
73         [AC_LANG_PUSH([C++])
74          AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/filesystem/path.hpp>]],
75                                    [[using namespace boost::filesystem;
76                                    path my_path( "foo/bar/data.txt" );
77                                    return 0;]]),
78                                                ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no)
79          AC_LANG_POP([C++])
80                 ])
81                 if test "x$ax_cv_boost_filesystem" = "xyes"; then
82                         AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available])
83             BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
84             if test "x$ax_boost_user_filesystem_lib" = "x"; then
85                 for libextension in `ls $BOOSTLIBDIR/libboost_filesystem*.{so,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_filesystem.*\)\.so.*$;\1;' -e 's;^lib\(boost_filesystem.*\)\.a*$;\1;'` ; do
86                      ax_lib=${libextension}
87                                     AC_CHECK_LIB($ax_lib, exit,
88                                  [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
89                                  [link_filesystem="no"])
90                                 done
91                 if test "x$link_program_options" != "xyes"; then
92                 for libextension in `ls $BOOSTLIBDIR/boost_filesystem*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_filesystem.*\)\.dll.*$;\1;' -e 's;^\(boost_filesystem.*\)\.a*$;\1;'` ; do
93                      ax_lib=${libextension}
94                                     AC_CHECK_LIB($ax_lib, exit,
95                                  [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
96                                  [link_filesystem="no"])
97                                 done
98                     fi
99             else
100                for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do
101                                       AC_CHECK_LIB($ax_lib, exit,
102                                    [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break],
103                                    [link_filesystem="no"])
104                   done
106             fi
107                         if test "x$link_filesystem" != "xyes"; then
108                                 AC_MSG_ERROR(Could not link against $ax_lib !)
109                         fi
110                 fi
112                 CPPFLAGS="$CPPFLAGS_SAVED"
113                 LDFLAGS="$LDFLAGS_SAVED"
114                 LIBS="$LIBS_SAVED"
115         fi