1# ===========================================================================
2#       http://www.gnu.org/software/autoconf-archive/ax_boost_base.html
3# ===========================================================================
4#
5# SYNOPSIS
6#
7#   AX_BOOST_BASE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
8#
9# DESCRIPTION
10#
11#   Test for the Boost C++ libraries of a particular version (or newer)
12#
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>.
17#
18#   This macro calls:
19#
20#     AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
21#
22#   And sets:
23#
24#     HAVE_BOOST
25#
26# LICENSE
27#
28#   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
29#   Copyright (c) 2009 Peter Adolphs
30#
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.
35
36#serial 21
37
38AC_DEFUN([AX_BOOST_BASE],
39[
40AC_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"])
58
59
60AC_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=""]
72)
73
74if 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
86
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|ppc64|s390x|sparc64|aarch64)
96        libsubdirs="lib64 lib lib64"
97        ;;
98    esac
99
100    dnl first we check the system location for boost libraries
101    dnl this location ist chosen if boost libraries are installed with the --layout=system option
102    dnl or if you install boost with RPM
103    if test "$ac_boost_path" != ""; then
104        BOOST_CPPFLAGS="-I$ac_boost_path/include"
105        for ac_boost_path_tmp in $libsubdirs; do
106                if test -d "$ac_boost_path"/"$ac_boost_path_tmp" ; then
107                        BOOST_LDFLAGS="-L$ac_boost_path/$ac_boost_path_tmp"
108                        break
109                fi
110        done
111    elif test "$cross_compiling" != yes; then
112        for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
113            if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
114                for libsubdir in $libsubdirs ; do
115                    if ls "$ac_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
116                done
117                BOOST_LDFLAGS="-L$ac_boost_path_tmp/$libsubdir"
118                BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
119                break;
120            fi
121        done
122    fi
123
124    dnl overwrite ld flags if we have required special directory with
125    dnl --with-boost-libdir parameter
126    if test "$ac_boost_lib_path" != ""; then
127       BOOST_LDFLAGS="-L$ac_boost_lib_path"
128    fi
129
130    CPPFLAGS_SAVED="$CPPFLAGS"
131    CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
132    export CPPFLAGS
133
134    LDFLAGS_SAVED="$LDFLAGS"
135    LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
136    export LDFLAGS
137
138    AC_REQUIRE([AC_PROG_CXX])
139    AC_LANG_PUSH(C++)
140        AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
141    @%:@include <boost/version.hpp>
142    ]], [[
143    #if BOOST_VERSION >= $WANT_BOOST_VERSION
144    // Everything is okay
145    #else
146    #  error Boost version is too old
147    #endif
148    ]])],[
149        AC_MSG_RESULT(yes)
150    succeeded=yes
151    found_system=yes
152        ],[
153        ])
154    AC_LANG_POP([C++])
155
156
157
158    dnl if we found no boost with system layout we search for boost libraries
159    dnl built and installed without the --layout=system option or for a staged(not installed) version
160    if test "x$succeeded" != "xyes"; then
161        _version=0
162        if test "$ac_boost_path" != ""; then
163            if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
164                for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
165                    _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
166                    V_CHECK=`expr $_version_tmp \> $_version`
167                    if test "$V_CHECK" = "1" ; then
168                        _version=$_version_tmp
169                    fi
170                    VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
171                    BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
172                done
173            fi
174        else
175            if test "$cross_compiling" != yes; then
176                for ac_boost_path in /usr /usr/local /opt /opt/local ; do
177                    if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
178                        for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
179                            _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
180                            V_CHECK=`expr $_version_tmp \> $_version`
181                            if test "$V_CHECK" = "1" ; then
182                                _version=$_version_tmp
183                                best_path=$ac_boost_path
184                            fi
185                        done
186                    fi
187                done
188
189                VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
190                BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
191                if test "$ac_boost_lib_path" = ""; then
192                    for libsubdir in $libsubdirs ; do
193                        if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
194                    done
195                    BOOST_LDFLAGS="-L$best_path/$libsubdir"
196                fi
197            fi
198
199            if test "x$BOOST_ROOT" != "x"; then
200                for libsubdir in $libsubdirs ; do
201                    if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
202                done
203                if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/$libsubdir" && test -r "$BOOST_ROOT/stage/$libsubdir"; then
204                    version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
205                    stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
206                        stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
207                    V_CHECK=`expr $stage_version_shorten \>\= $_version`
208                    if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then
209                        AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
210                        BOOST_CPPFLAGS="-I$BOOST_ROOT"
211                        BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
212                    fi
213                fi
214            fi
215        fi
216
217        CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
218        export CPPFLAGS
219        LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
220        export LDFLAGS
221
222        AC_LANG_PUSH(C++)
223            AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
224        @%:@include <boost/version.hpp>
225        ]], [[
226        #if BOOST_VERSION >= $WANT_BOOST_VERSION
227        // Everything is okay
228        #else
229        #  error Boost version is too old
230        #endif
231        ]])],[
232            AC_MSG_RESULT(yes)
233        succeeded=yes
234        found_system=yes
235            ],[
236            ])
237        AC_LANG_POP([C++])
238    fi
239
240    if test "$succeeded" != "yes" ; then
241        if test "$_version" = "0" ; then
242            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.]])
243        else
244            AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
245        fi
246        # execute ACTION-IF-NOT-FOUND (if present):
247        ifelse([$3], , :, [$3])
248    else
249        AC_SUBST(BOOST_CPPFLAGS)
250        AC_SUBST(BOOST_LDFLAGS)
251        AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
252        # execute ACTION-IF-FOUND (if present):
253        ifelse([$2], , :, [$2])
254    fi
255
256    CPPFLAGS="$CPPFLAGS_SAVED"
257    LDFLAGS="$LDFLAGS_SAVED"
258fi
259
260])
261