fix piece_picker piece-shuffle bug
[libtorrent.git] / m4 / ax_boost_base-fixed.m4
blob87027655da4dae22d91234fc4ef1c470b7835db6
1 # ===========================================================================
2 #             http://autoconf-archive.cryp.to/ax_boost_base.html
3 # ===========================================================================
5 # SYNOPSIS
7 #   AX_BOOST_BASE([MINIMUM-VERSION],[ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
9 # DESCRIPTION
11 #   Test for the Boost C++ libraries of a particular version (or newer)
13 #   If no path to the installed boost library is given the macro searchs
14 #   under /usr, /usr/local, /opt and /opt/local and evaluates the
15 #   $BOOST_ROOT environment variable. Further documentation is available at
16 #   <http://randspringer.de/boost/index.html>.
18 #   This macro calls:
20 #     AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
22 #   And sets:
24 #     HAVE_BOOST
26 # LAST MODIFICATION
28 #   2008-04-12 - original
29 #   2008-06-13 - AIF/AINF parameters
31 # COPYLEFT
33 #   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
35 #   Copyright (c) 2008 Roman Rybalko <libtorrent@romanr.info> (under RbLibtorrent project)
36 #   (ACTION-IF-FOUND/ACTION-IF-NOT-FOUND options, re-enterability fixes)
38 #   Copying and distribution of this file, with or without modification, are
39 #   permitted in any medium without royalty provided the copyright notice
40 #   and this notice are preserved.
42 AC_DEFUN([AX_BOOST_BASE],
44 AC_ARG_WITH([boost],
45         AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]),
46         [
47     if test "$withval" = "no"; then
48                 want_boost="no"
49     elif test "$withval" = "yes"; then
50         want_boost="yes"
51         ac_boost_path=""
52     else
53             want_boost="yes"
54         ac_boost_path="$withval"
55         fi
56     ],
57     [want_boost="yes"])
60 AC_ARG_WITH([boost-libdir],
61         AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
62         [Force given directory for boost libraries. Note that this will overwrite library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.]),
63         [
64         if test -d $withval
65         then
66                 ac_boost_lib_path="$withval"
67         else
68                 AC_MSG_ERROR(--with-boost-libdir expected directory name)
69         fi
70         ],
71         [ac_boost_lib_path=""]
74 if test "x$want_boost" = "xyes"; then
75         boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
76         boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
77         boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
78         boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
79         boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
80         if test "x$boost_lib_version_req_sub_minor" = "x" ; then
81                 boost_lib_version_req_sub_minor="0"
82         fi
83         WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+  $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
84         AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
85         succeeded=no
87         dnl first we check the system location for boost libraries
88         dnl this location ist chosen if boost libraries are installed with the --layout=system option
89         dnl or if you install boost with RPM
90         if test "$ac_boost_path" != ""; then
91                 BOOST_LDFLAGS="-L$ac_boost_path/lib"
92                 BOOST_CPPFLAGS="-I$ac_boost_path/include"
93         else
94                 for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
95                         if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
96                                 BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
97                                 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
98                                 break;
99                         fi
100                 done
101         fi
103     dnl overwrite ld flags if we have required special directory with
104     dnl --with-boost-libdir parameter
105     if test "$ac_boost_lib_path" != ""; then
106        BOOST_LDFLAGS="-L$ac_boost_lib_path"
107     fi
109         CPPFLAGS_SAVED="$CPPFLAGS"
110         CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
111         export CPPFLAGS
113         LDFLAGS_SAVED="$LDFLAGS"
114         LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
115         export LDFLAGS
117         AC_LANG_PUSH(C++)
118         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
119         @%:@include <boost/version.hpp>
120         ]], [[
121         #if BOOST_VERSION >= $WANT_BOOST_VERSION
122         // Everything is okay
123         #else
124         #  error Boost version is too old
125         #endif
126         ]])],[
127         AC_MSG_RESULT(yes)
128         succeeded=yes
129         found_system=yes
130         ],[
131         ])
132         AC_LANG_POP([C++])
136         dnl if we found no boost with system layout we search for boost libraries
137         dnl built and installed without the --layout=system option or for a staged(not installed) version
138         if test "x$succeeded" != "xyes"; then
139                 _version=0
140                 if test "$ac_boost_path" != ""; then
141                         if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
142                                 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
143                                         _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
144                                         V_CHECK=`expr $_version_tmp \> $_version`
145                                         if test "$V_CHECK" = "1" ; then
146                                                 _version=$_version_tmp
147                                         fi
148                                         VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
149                                         BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
150                                 done
151                         fi
152                 else
153                         for ac_boost_path in /usr /usr/local /opt /opt/local ; do
154                                 if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
155                                         for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
156                                                 _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
157                                                 V_CHECK=`expr $_version_tmp \> $_version`
158                                                 if test "$V_CHECK" = "1" ; then
159                                                         _version=$_version_tmp
160                                                         best_path=$ac_boost_path
161                                                 fi
162                                         done
163                                 fi
164                         done
166                         VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
167                         BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
168             if test "$ac_boost_lib_path" = ""
169             then
170                BOOST_LDFLAGS="-L$best_path/lib"
171             fi
173                         if test "x$BOOST_ROOT" != "x"; then
174                                 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
175                                         version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
176                                         stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
177                                         stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
178                                         V_CHECK=`expr $stage_version_shorten \>\= $_version`
179                     if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
180                                                 AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
181                                                 BOOST_CPPFLAGS="-I$BOOST_ROOT"
182                                                 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
183                                         fi
184                                 fi
185                         fi
186                 fi
188                 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
189                 export CPPFLAGS
190                 LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
191                 export LDFLAGS
193                 AC_LANG_PUSH(C++)
194                 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
195                 @%:@include <boost/version.hpp>
196                 ]], [[
197                 #if BOOST_VERSION >= $WANT_BOOST_VERSION
198                 // Everything is okay
199                 #else
200                 #  error Boost version is too old
201                 #endif
202                 ]])],[
203                 AC_MSG_RESULT(yes)
204                 succeeded=yes
205                 found_system=yes
206                 ],[
207                 ])
208                 AC_LANG_POP([C++])
209         fi
210         
211         CPPFLAGS="$CPPFLAGS_SAVED"
212         LDFLAGS="$LDFLAGS_SAVED"
213         unset ac_boost_path # re-enterability
215         if test "$succeeded" != "yes" ; then
216                 ifelse([$3], ,[
217                         if test "$_version" = "0" ; then
218                                 AC_MSG_ERROR([[We could not detect the boost libraries (version $boost_lib_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option.  If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.]])
219                         else
220                                 AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
221                         fi
222                 ],[
223                         AC_MSG_RESULT(no)
224                         $3
225                 ])
226         else
227                 $2
228                 AC_SUBST(BOOST_CPPFLAGS)
229                 AC_SUBST(BOOST_LDFLAGS)
230                 AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
231         fi