11# ===========================================================================
2- # http ://www.gnu.org/software/autoconf-archive/ax_boost_base.html
2+ # https ://www.gnu.org/software/autoconf-archive/ax_boost_base.html
33# ===========================================================================
44#
55# SYNOPSIS
3333# and this notice are preserved. This file is offered as-is, without any
3434# warranty.
3535
36- # serial 27
36+ # serial 47
37+
38+ # example boost program (need to pass version)
39+ m4_define ( [ _AX_BOOST_BASE_PROGRAM] ,
40+ [ AC_LANG_PROGRAM ( [ [
41+ #include <boost/version.hpp>
42+ ] ] ,[ [
43+ (void) ((void)sizeof(char[ 1 - 2*!!((BOOST_VERSION) < ($1 ))] ));
44+ ] ] ) ] )
3745
3846AC_DEFUN ( [ AX_BOOST_BASE ] ,
3947[
@@ -44,110 +52,122 @@ AC_ARG_WITH([boost],
4452 or disable it (ARG=no)
4553 @<:@ ARG=yes@:>@ ] ) ] ,
4654 [
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
55+ AS_CASE ( [ $withval] ,
56+ [ no] ,[ want_boost="no";_AX_BOOST_BASE_boost_path=""] ,
57+ [ yes] ,[ want_boost="yes";_AX_BOOST_BASE_boost_path=""] ,
58+ [ want_boost="yes";_AX_BOOST_BASE_boost_path="$withval"] )
5659 ] ,
5760 [ want_boost="yes"] )
5861
5962
6063AC_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- )
64+ [ AS_HELP_STRING ( [ --with-boost-libdir=LIB_DIR] ,
65+ [ Force given directory for boost libraries.
66+ Note that this will override library path detection,
67+ so use this parameter only if default library detection fails
68+ and you know exactly where your boost libraries are located.] ) ] ,
69+ [
70+ AS_IF ( [ test -d "$withval"] ,
71+ [ _AX_BOOST_BASE_boost_lib_path="$withval"] ,
72+ [ AC_MSG_ERROR ( [ --with-boost-libdir expected directory name] ) ] )
73+ ] ,
74+ [ _AX_BOOST_BASE_boost_lib_path=""] )
7375
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 )
76+ BOOST_LDFLAGS=""
77+ BOOST_CPPFLAGS=""
78+ AS_IF ( [ test "x$want_boost" = "xyes"] ,
79+ [ _AX_BOOST_BASE_RUNDETECT([ $1 ] ,[ $2 ] ,[ $3 ] )] )
80+ AC_SUBST ( BOOST_CPPFLAGS )
81+ AC_SUBST ( BOOST_LDFLAGS )
82+ ] )
83+
84+
85+ # convert a version string in $2 to numeric and affect to polymorphic var $1
86+ AC_DEFUN ( [ _AX_BOOST_BASE_TONUMERICVERSION] ,[
87+ AS_IF ( [ test "x$2 " = "x"] ,[ _AX_BOOST_BASE_TONUMERICVERSION_req="1.20.0"] ,[ _AX_BOOST_BASE_TONUMERICVERSION_req="$2 "] )
88+ _AX_BOOST_BASE_TONUMERICVERSION_req_shorten=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([ [ 0-9] ] *\.[ [ 0-9] ] *\)'`
89+ _AX_BOOST_BASE_TONUMERICVERSION_req_major=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '\([ [ 0-9] ] *\)'`
90+ AS_IF ( [ test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_major" = "x"] ,
91+ [ AC_MSG_ERROR ( [ You should at least specify libboost major version] ) ] )
92+ _AX_BOOST_BASE_TONUMERICVERSION_req_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[ [ 0-9] ] *\.\([ [ 0-9] ] *\)'`
93+ AS_IF ( [ test "x$_AX_BOOST_BASE_TONUMERICVERSION_req_minor" = "x"] ,
94+ [ _AX_BOOST_BASE_TONUMERICVERSION_req_minor="0"] )
95+ _AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req : '[ [ 0-9] ] *\.[ [ 0-9] ] *\.\([ [ 0-9] ] *\)'`
96+ AS_IF ( [ test "X$_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor" = "X"] ,
97+ [ _AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor="0"] )
98+ _AX_BOOST_BASE_TONUMERICVERSION_RET=`expr $_AX_BOOST_BASE_TONUMERICVERSION_req_major \* 100000 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_minor \* 100 \+ $_AX_BOOST_BASE_TONUMERICVERSION_req_sub_minor`
99+ AS_VAR_SET ( $1 ,$_AX_BOOST_BASE_TONUMERICVERSION_RET )
100+ ] )
101+
102+ dnl Run the detection of boost should be run only if $want_boost
103+ AC_DEFUN ( [ _AX_BOOST_BASE_RUNDETECT] ,[
104+ _AX_BOOST_BASE_TONUMERICVERSION(WANT_BOOST_VERSION,[ $1 ] )
85105 succeeded=no
86106
107+
108+ AC_REQUIRE ( [ AC_CANONICAL_HOST ] )
87109 dnl On 64-bit systems check for system libraries in both lib64 and lib.
88110 dnl The former is specified by FHS, but e.g. Debian does not adhere to
89111 dnl this (as it rises problems for generic multi-arch support).
90112 dnl The last entry in the list is chosen by default when no libraries
91113 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
114+ AS_CASE ( [ ${host_cpu}] ,
115+ [ x86_64] ,[ libsubdirs="lib64 libx32 lib lib64"] ,
116+ [ mips*64*] ,[ libsubdirs="lib64 lib32 lib lib64"] ,
117+ [ ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64] ,[ libsubdirs="lib64 lib lib64"] ,
118+ [ libsubdirs="lib"]
119+ )
102120
103121 dnl allow for real multi-arch paths e.g. /usr/lib/x86_64-linux-gnu. Give
104122 dnl them priority over the other paths since, if libs are found there, they
105123 dnl are almost assuredly the ones desired.
106- AC_REQUIRE ( [ AC_CANONICAL_HOST ] )
107- libsubdirs="lib/${host_cpu}-${host_os} $libsubdirs"
108-
109- case ${host_cpu} in
110- i?86)
111- libsubdirs="lib/i386-${host_os} $libsubdirs"
112- ;;
113- esac
114-
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"
124+ AS_CASE ( [ ${host_cpu}] ,
125+ [ i?86] ,[ multiarch_libsubdir="lib/i386-${host_os}"] ,
126+ [ multiarch_libsubdir="lib/${host_cpu}-${host_os}"]
127+ )
120128
121129 dnl first we check the system location for boost libraries
122130 dnl this location ist chosen if boost libraries are installed with the --layout=system option
123131 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
132+ AS_IF ( [ test "x$_AX_BOOST_BASE_boost_path" != "x"] ,[
133+ AC_MSG_CHECKING ( [ for boostlib >= $1 ($WANT_BOOST_VERSION) includes in "$_AX_BOOST_BASE_boost_path/include"] )
134+ AS_IF ( [ test -d "$_AX_BOOST_BASE_boost_path/include" && test -r "$_AX_BOOST_BASE_boost_path/include"] ,[
135+ AC_MSG_RESULT ( [ yes] )
136+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path/include"
137+ for _AX_BOOST_BASE_boost_path_tmp in $multiarch_libsubdir $libsubdirs; do
138+ AC_MSG_CHECKING ( [ for boostlib >= $1 ($WANT_BOOST_VERSION) lib path in "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp"] )
139+ AS_IF ( [ test -d "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" && test -r "$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp" ] ,[
140+ AC_MSG_RESULT ( [ yes] )
141+ BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$_AX_BOOST_BASE_boost_path_tmp";
142+ break;
143+ ] ,
144+ [ AC_MSG_RESULT ( [ no] ) ] )
145+ done] ,[
146+ AC_MSG_RESULT ( [ no] ) ] )
147+ ] ,[
148+ if test X"$cross_compiling" = Xyes; then
149+ search_libsubdirs=$multiarch_libsubdir
150+ else
151+ search_libsubdirs="$multiarch_libsubdir $libsubdirs"
152+ fi
153+ for _AX_BOOST_BASE_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
154+ if test -d "$_AX_BOOST_BASE_boost_path_tmp/include/boost" && test -r "$_AX_BOOST_BASE_boost_path_tmp/include/boost" ; then
155+ for libsubdir in $search_libsubdirs ; do
156+ if ls "$_AX_BOOST_BASE_boost_path_tmp/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
137157 done
138- BOOST_LDFLAGS="-L$ac_boost_path_tmp /$libsubdir"
139- BOOST_CPPFLAGS="-I$ac_boost_path_tmp /include"
158+ BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path_tmp /$libsubdir"
159+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path_tmp /include"
140160 break;
141161 fi
142162 done
143- fi
163+ ] )
144164
145165 dnl overwrite ld flags if we have required special directory with
146166 dnl --with-boost-libdir parameter
147- if test "$ac_boost_lib_path" != ""; then
148- BOOST_LDFLAGS="-L$ac_boost_lib_path"
149- fi
167+ AS_IF ( [ test "x$_AX_BOOST_BASE_boost_lib_path" != "x"] ,
168+ [ BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_lib_path"] )
150169
170+ AC_MSG_CHECKING ( [ for boostlib >= $1 ($WANT_BOOST_VERSION)] )
151171 CPPFLAGS_SAVED="$CPPFLAGS"
152172 CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
153173 export CPPFLAGS
@@ -158,15 +178,7 @@ if test "x$want_boost" = "xyes"; then
158178
159179 AC_REQUIRE ( [ AC_PROG_CXX ] )
160180 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- ] ] ) ] ,[
181+ AC_COMPILE_IFELSE ( [ _AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)] ,[
170182 AC_MSG_RESULT ( yes )
171183 succeeded=yes
172184 found_system=yes
@@ -178,56 +190,66 @@ if test "x$want_boost" = "xyes"; then
178190
179191 dnl if we found no boost with system layout we search for boost libraries
180192 dnl built and installed without the --layout=system option or for a staged(not installed) version
181- if test "x$succeeded" != "xyes"; then
193+ if test "x$succeeded" != "xyes" ; then
182194 CPPFLAGS="$CPPFLAGS_SAVED"
183195 LDFLAGS="$LDFLAGS_SAVED"
184196 BOOST_CPPFLAGS=
185- BOOST_LDFLAGS=
197+ if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
198+ BOOST_LDFLAGS=
199+ fi
186200 _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/_/./'`
201+ if test -n "$_AX_BOOST_BASE_boost_path" ; then
202+ if test -d "$_AX_BOOST_BASE_boost_path " && test -r "$_AX_BOOST_BASE_boost_path "; then
203+ for i in `ls -d $_AX_BOOST_BASE_boost_path /include/boost-* 2>/dev/null`; do
204+ _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path ##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
191205 V_CHECK=`expr $_version_tmp \> $_version`
192- if test "$V_CHECK" = "1 " ; then
206+ if test "x $V_CHECK" = "x1 " ; then
193207 _version=$_version_tmp
194208 fi
195209 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
196- BOOST_CPPFLAGS="-I$ac_boost_path /include/boost-$VERSION_UNDERSCORE"
210+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path /include/boost-$VERSION_UNDERSCORE"
197211 done
198212 dnl if nothing found search for layout used in Windows distributions
199213 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 "
214+ if test -d "$_AX_BOOST_BASE_boost_path /boost" && test -r "$_AX_BOOST_BASE_boost_path /boost"; then
215+ BOOST_CPPFLAGS="-I$_AX_BOOST_BASE_boost_path "
202216 fi
203217 fi
218+ dnl if we found something and BOOST_LDFLAGS was unset before
219+ dnl (because "$_AX_BOOST_BASE_boost_lib_path" = ""), set it here.
220+ if test -n "$BOOST_CPPFLAGS" && test -z "$BOOST_LDFLAGS"; then
221+ for libsubdir in $libsubdirs ; do
222+ if ls "$_AX_BOOST_BASE_boost_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
223+ done
224+ BOOST_LDFLAGS="-L$_AX_BOOST_BASE_boost_path/$libsubdir"
225+ fi
204226 fi
205227 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/_/./'`
228+ if test "x $cross_compiling" != "xyes" ; then
229+ for _AX_BOOST_BASE_boost_path in /usr /usr/local /opt /opt/local ; do
230+ if test -d "$_AX_BOOST_BASE_boost_path " && test -r "$_AX_BOOST_BASE_boost_path" ; then
231+ for i in `ls -d $_AX_BOOST_BASE_boost_path /include/boost-* 2>/dev/null`; do
232+ _version_tmp=`echo $i | sed "s#$_AX_BOOST_BASE_boost_path ##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
211233 V_CHECK=`expr $_version_tmp \> $_version`
212- if test "$V_CHECK" = "1 " ; then
234+ if test "x $V_CHECK" = "x1 " ; then
213235 _version=$_version_tmp
214- best_path=$ac_boost_path
236+ best_path=$_AX_BOOST_BASE_boost_path
215237 fi
216238 done
217239 fi
218240 done
219241
220242 VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
221243 BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
222- if test "$ac_boost_lib_path" = "" ; then
244+ if test -z "$_AX_BOOST_BASE_boost_lib_path" ; then
223245 for libsubdir in $libsubdirs ; do
224246 if ls "$best_path/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
225247 done
226248 BOOST_LDFLAGS="-L$best_path/$libsubdir"
227249 fi
228250 fi
229251
230- if test "x $BOOST_ROOT" != "x" ; then
252+ if test -n " $BOOST_ROOT" ; then
231253 for libsubdir in $libsubdirs ; do
232254 if ls "$BOOST_ROOT/stage/$libsubdir/libboost_"* >/dev/null 2>&1 ; then break; fi
233255 done
@@ -236,7 +258,7 @@ if test "x$want_boost" = "xyes"; then
236258 stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
237259 stage_version_shorten=`expr $stage_version : '\([ [ 0-9] ] *\.[ [ 0-9] ] *\)'`
238260 V_CHECK=`expr $stage_version_shorten \>\= $_version`
239- if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = " " ; then
261+ if test "x $V_CHECK" = "x1" && test -z "$_AX_BOOST_BASE_boost_lib_path " ; then
240262 AC_MSG_NOTICE ( We will use a staged boost library from $BOOST_ROOT )
241263 BOOST_CPPFLAGS="-I$BOOST_ROOT"
242264 BOOST_LDFLAGS="-L$BOOST_ROOT/stage/$libsubdir"
@@ -251,15 +273,7 @@ if test "x$want_boost" = "xyes"; then
251273 export LDFLAGS
252274
253275 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- ] ] ) ] ,[
276+ AC_COMPILE_IFELSE ( [ _AX_BOOST_BASE_PROGRAM($WANT_BOOST_VERSION)] ,[
263277 AC_MSG_RESULT ( yes )
264278 succeeded=yes
265279 found_system=yes
@@ -268,24 +282,21 @@ if test "x$want_boost" = "xyes"; then
268282 AC_LANG_POP ( [ C++] )
269283 fi
270284
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.] ] )
285+ if test "x $succeeded" != "xyes " ; then
286+ if test "x $_version" = "x0 " ; then
287+ AC_MSG_NOTICE ( [ [ We could not detect the boost libraries (version $1 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.] ] )
274288 else
275289 AC_MSG_NOTICE ( [ Your boost libraries seems to old (version $_version).] )
276290 fi
277291 # execute ACTION-IF-NOT-FOUND (if present):
278292 ifelse ( [ $3 ] , , : , [ $3 ] )
279293 else
280- AC_SUBST ( BOOST_CPPFLAGS )
281- AC_SUBST ( BOOST_LDFLAGS )
282294 AC_DEFINE ( HAVE_BOOST ,,[ define if the Boost library is available] )
283295 # execute ACTION-IF-FOUND (if present):
284296 ifelse ( [ $2 ] , , : , [ $2 ] )
285297 fi
286298
287299 CPPFLAGS="$CPPFLAGS_SAVED"
288300 LDFLAGS="$LDFLAGS_SAVED"
289- fi
290301
291302] )
0 commit comments