improved error reporting of file errors (uses boost.system's error_code). Now permiss...
[libtorrent.git] / m4 / ax_boost_system.m4
blob6188603251b1c2ebfe3d40e4ceb044d8cb5dfd49
1 # ===========================================================================
2 #            http://autoconf-archive.cryp.to/ax_boost_system.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_BOOST_SYSTEM
9 # DESCRIPTION
11 #   Test for System library from the Boost C++ libraries. The macro requires
12 #   a preceding call to AX_BOOST_BASE. Further documentation is available at
13 #   <http://randspringer.de/boost/index.html>.
15 #   This macro calls:
17 #     AC_SUBST(BOOST_SYSTEM_LIB)
19 #   And sets:
21 #     HAVE_BOOST_SYSTEM
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 Daniel Casimiro <dan.casimiro@gmail.com>
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_SYSTEM],
39         AC_ARG_WITH([boost-system],
40         AS_HELP_STRING([--with-boost-system@<:@=special-lib@:>@],
41                    [use the System library from boost - it is possible to specify a certain library for the linker
42                         e.g. --with-boost-system=boost_system-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_system_lib=""
49         else
50                     want_boost="yes"
51                 ax_boost_user_system_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         AC_REQUIRE([AC_CANONICAL_BUILD])
60                 CPPFLAGS_SAVED="$CPPFLAGS"
61                 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
62                 export CPPFLAGS
64                 LDFLAGS_SAVED="$LDFLAGS"
65                 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
66                 export LDFLAGS
68         AC_CACHE_CHECK(whether the Boost::System library is available,
69                                            ax_cv_boost_system,
70         [AC_LANG_PUSH([C++])
71                          CXXFLAGS_SAVE=$CXXFLAGS
73                          AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include <boost/system/error_code.hpp>]],
74                                    [[boost::system::system_category]]),
75                    ax_cv_boost_system=yes, ax_cv_boost_system=no)
76                          CXXFLAGS=$CXXFLAGS_SAVE
77              AC_LANG_POP([C++])
78                 ])
79                 if test "x$ax_cv_boost_system" = "xyes"; then
80                         AC_SUBST(BOOST_CPPFLAGS)
82                         AC_DEFINE(HAVE_BOOST_SYSTEM,,[define if the Boost::System library is available])
83             BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
85                         LDFLAGS_SAVE=$LDFLAGS
86             if test "x$ax_boost_user_system_lib" = "x"; then
87                 for libextension in `ls $BOOSTLIBDIR/libboost_system*.{so,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_system.*\)\.so.*$;\1;' -e 's;^lib\(boost_system.*\)\.a*$;\1;'` ; do
88                      ax_lib=${libextension}
89                                     AC_CHECK_LIB($ax_lib, exit,
90                                  [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
91                                  [link_system="no"])
92                                 done
93                 if test "x$link_system" != "xyes"; then
94                 for libextension in `ls $BOOSTLIBDIR/boost_system*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_system.*\)\.dll.*$;\1;' -e 's;^\(boost_system.*\)\.a*$;\1;'` ; do
95                      ax_lib=${libextension}
96                                     AC_CHECK_LIB($ax_lib, exit,
97                                  [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
98                                  [link_system="no"])
99                                 done
100                 fi
102             else
103                for ax_lib in $ax_boost_user_system_lib boost_system-$ax_boost_user_system_lib; do
104                                       AC_CHECK_LIB($ax_lib, exit,
105                                    [BOOST_SYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_SYSTEM_LIB) link_system="yes"; break],
106                                    [link_system="no"])
107                   done
109             fi
110                         if test "x$link_system" = "xno"; then
111                                 AC_MSG_ERROR(Could not link against $ax_lib !)
112                         fi
113                 fi
115                 CPPFLAGS="$CPPFLAGS_SAVED"
116         LDFLAGS="$LDFLAGS_SAVED"
117         fi