[tests] Tidy up forknotify.py
[bitcoinplatinum.git] / build-aux / m4 / ax_boost_base.m4
blob650c94fa64752a362a34eb6d489c194255ecfc51
1 # ===========================================================================
2 #       http://www.gnu.org/software/autoconf-archive/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 # LICENSE
28 #   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
29 #   Copyright (c) 2009 Peter Adolphs
31 #   Copying and distribution of this file, with or without modification, are
32 #   permitted in any medium without royalty provided the copyright notice
33 #   and this notice are preserved. This file is offered as-is, without any
34 #   warranty.
36 #serial 27
38 AC_DEFUN([AX_BOOST_BASE],
40 AC_ARG_WITH([boost],
41   [AS_HELP_STRING([--with-boost@<:@=ARG@:>@],
42     [use Boost library from a standard location (ARG=yes),
43      from the specified location (ARG=<path>),
44      or disable it (ARG=no)
45      @<:@ARG=yes@:>@ ])],
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 override 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 On 64-bit systems check for system libraries in both lib64 and lib.
88     dnl The former is specified by FHS, but e.g. Debian does not adhere to
89     dnl this (as it rises problems for generic multi-arch support).
90     dnl The last entry in the list is chosen by default when no libraries
91     dnl are found, e.g. when only header-only libraries are installed!
92     libsubdirs="lib"
93     ax_arch=`uname -m`
94     case $ax_arch in
95       x86_64)
96         libsubdirs="lib64 libx32 lib lib64"
97         ;;
98       ppc64|s390x|sparc64|aarch64|ppc64le)
99         libsubdirs="lib64 lib lib64"
100         ;;
101     esac
103     dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give
104     dnl them priority over the other paths since, if libs are found there, they
105     dnl are almost assuredly the ones desired.
106     AC_REQUIRE([AC_CANONICAL_HOST])
107     libsubdirs="lib/${host_cpu}-${host_os} $libsubdirs"
109     case ${host_cpu} in
110       i?86)
111         libsubdirs="lib/i386-${host_os} $libsubdirs"
112         ;;
113     esac
115     dnl some arches may advertise a cpu type that doesn't line up with their
116     dnl prefix's cpu type. For example, uname may report armv7l while libs are
117     dnl installed to /usr/lib/arm-linux-gnueabihf. Try getting the compiler's
118     dnl value for an extra chance of finding the correct path.
119     libsubdirs="lib/`$CXX -dumpmachine 2>/dev/null` $libsubdirs"
121     dnl first we check the system location for boost libraries
122     dnl this location ist chosen if boost libraries are installed with the --layout=system option
123     dnl or if you install boost with RPM
124     if test "$ac_boost_path" != ""; then
125         BOOST_CPPFLAGS="-I$ac_boost_path/include"
126         for ac_boost_path_tmp in $libsubdirs; do
127                 if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then
128                         BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp"
129                         break
130                 fi
131         done
132     elif test "$cross_compiling" != yes; then
133         for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
134             if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
135                 for libsubdir in $libsubdirs ; do
136                     if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
137                 done
138                 BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir"
139                 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
140                 break;
141             fi
142         done
143     fi
145     dnl overwrite ld flags if we have required special directory with
146     dnl --with-boost-libdir parameter
147     if test "$ac_boost_lib_path" != ""; then
148        BOOST_LDFLAGS="-L$ac_boost_lib_path"
149     fi
151     CPPFLAGS_SAVED="$CPPFLAGS"
152     CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
153     export CPPFLAGS
155     LDFLAGS_SAVED="$LDFLAGS"
156     LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
157     export LDFLAGS
159     AC_REQUIRE([AC_PROG_CXX])
160     AC_LANG_PUSH(C++)
161         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
162     @%:@include <boost/version.hpp>
163     ]], [[
164     #if BOOST_VERSION >= $WANT_BOOST_VERSION
165     // Everything is okay
166     #else
167     #  error Boost version is too old
168     #endif
169     ]])],[
170         AC_MSG_RESULT(yes)
171     succeeded=yes
172     found_system=yes
173         ],[
174         ])
175     AC_LANG_POP([C++])
179     dnl if we found no boost with system layout we search for boost libraries
180     dnl built and installed without the --layout=system option or for a staged(not installed) version
181     if test "x$succeeded" != "xyes"; then
182         CPPFLAGS="$CPPFLAGS_SAVED"
183         LDFLAGS="$LDFLAGS_SAVED"
184         BOOST_CPPFLAGS=
185         BOOST_LDFLAGS=
186         _version=0
187         if test "$ac_boost_path" != ""; then
188             if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
189                 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
190                     _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
191                     V_CHECK=`expr $_version_tmp \> $_version`
192                     if test "$V_CHECK" = "1" ; then
193                         _version=$_version_tmp
194                     fi
195                     VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
196                     BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
197                 done
198                 dnl if nothing found search for layout used in Windows distributions
199                 if test -z "$BOOST_CPPFLAGS"; then
200                     if test -d "$ac_boost_path/boost" && test -r "$ac_boost_path/boost"; then
201                         BOOST_CPPFLAGS="-I$ac_boost_path"
202                     fi
203                 fi
204             fi
205         else
206             if test "$cross_compiling" != yes; then
207                 for ac_boost_path in /usr /usr/local /opt /opt/local ; do
208                     if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
209                         for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
210                             _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
211                             V_CHECK=`expr $_version_tmp \> $_version`
212                             if test "$V_CHECK" = "1" ; then
213                                 _version=$_version_tmp
214                                 best_path=$ac_boost_path
215                             fi
216                         done
217                     fi
218                 done
220                 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
221                 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
222                 if test "$ac_boost_lib_path" = ""; then
223                     for libsubdir in $libsubdirs ; do
224                         if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
225                     done
226                     BOOST_LDFLAGS="-L$best_path/$libsubdir"
227                 fi
228             fi
230             if test "x$BOOST_ROOT" != "x"; then
231                 for libsubdir in $libsubdirs ; do
232                     if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
233                 done
234                 if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
235                     version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
236                     stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
237                         stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
238                     V_CHECK=`expr $stage_version_shorten \>\= $_version`
239                     if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
240                         AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
241                         BOOST_CPPFLAGS="-I$BOOST_ROOT"
242                         BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
243                     fi
244                 fi
245             fi
246         fi
248         CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
249         export CPPFLAGS
250         LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
251         export LDFLAGS
253         AC_LANG_PUSH(C++)
254             AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
255         @%:@include <boost/version.hpp>
256         ]], [[
257         #if BOOST_VERSION >= $WANT_BOOST_VERSION
258         // Everything is okay
259         #else
260         #  error Boost version is too old
261         #endif
262         ]])],[
263             AC_MSG_RESULT(yes)
264         succeeded=yes
265         found_system=yes
266             ],[
267             ])
268         AC_LANG_POP([C++])
269     fi
271     if test "$succeeded" != "yes" ; then
272         if test "$_version" = "0" ; then
273             AC_MSG_NOTICE([[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.]])
274         else
275             AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
276         fi
277         # execute ACTION-IF-NOT-FOUND (if present):
278         ifelse([$3], , :, [$3])
279     else
280         AC_SUBST(BOOST_CPPFLAGS)
281         AC_SUBST(BOOST_LDFLAGS)
282         AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
283         # execute ACTION-IF-FOUND (if present):
284         ifelse([$2], , :, [$2])
285     fi
287     CPPFLAGS="$CPPFLAGS_SAVED"
288     LDFLAGS="$LDFLAGS_SAVED"