1##### http://autoconf-archive.cryp.to/ax_boost_base.html
2#
3# SYNOPSIS
4#
5#   AX_BOOST_BASE([MINIMUM-VERSION])
6#
7# DESCRIPTION
8#
9#   Test for the Boost C++ libraries of a particular version (or newer)
10#
11#   If no path to the installed boost library is given the macro
12#   searchs under /usr, /usr/local, and /opt, and evaluates the
13#   $BOOST_ROOT environment variable. Further documentation is
14#   available at <http://randspringer.de/boost/index.html>.
15#
16#   This macro calls:
17#
18#     AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS)
19#
20#   And sets:
21#
22#     HAVE_BOOST
23#
24# LAST MODIFICATION
25#
26#   2006-12-28
27#
28# COPYLEFT
29#
30#   Copyright (c) 2006 Thomas Porschberg <thomas@randspringer.de>
31#
32#   Copying and distribution of this file, with or without
33#   modification, are permitted in any medium without royalty provided
34#   the copyright notice and this notice are preserved.
35
36AC_DEFUN([AX_BOOST_BASE],
37[
38AC_ARG_WITH([boost],
39	AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is No) - it is possible to specify the root directory for boost (optional)]),
40	[
41    if test "$withval" = "no"; then
42		want_boost="no"
43    elif test "$withval" = "yes"; then
44        want_boost="yes"
45        ac_boost_path=""
46    else
47	    want_boost="yes"
48        ac_boost_path="$withval"
49	fi
50    ],
51    [want_boost="yes"])
52
53if test "x$want_boost" = "xyes"; then
54	boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
55	boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
56	boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
57	boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
58	boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
59	if test "x$boost_lib_version_req_sub_minor" = "x" ; then
60		boost_lib_version_req_sub_minor="0"
61    	fi
62	WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+  $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
63	AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req)
64	succeeded=no
65
66	dnl first we check the system location for boost libraries
67	dnl this location ist chosen if boost libraries are installed with the --layout=system option
68	dnl or if you install boost with RPM
69	if test "$ac_boost_path" != ""; then
70		BOOST_LDFLAGS="-L$ac_boost_path/lib"
71		BOOST_CPPFLAGS="-I$ac_boost_path/include"
72	else
73		for ac_boost_path_tmp in /usr /usr/local /opt ; do
74			if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
75				BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
76				BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
77				break;
78			fi
79		done
80	fi
81
82	CPPFLAGS_SAVED="$CPPFLAGS"
83	CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
84	export CPPFLAGS
85
86	LDFLAGS_SAVED="$LDFLAGS"
87	LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
88	export LDFLAGS
89
90	AC_LANG_PUSH(C++)
91     	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
92	@%:@include <boost/version.hpp>
93	]], [[
94	#if BOOST_VERSION >= $WANT_BOOST_VERSION
95	// Everything is okay
96	#else
97	#  error Boost version is too old
98	#endif
99	]])],[
100        AC_MSG_RESULT(yes)
101	succeeded=yes
102	found_system=yes
103       	],[
104       	])
105	AC_LANG_POP([C++])
106
107
108
109	dnl if we found no boost with system layout we search for boost libraries
110	dnl built and installed without the --layout=system option or for a staged(not installed) version
111	if test "x$succeeded" != "xyes"; then
112		_version=0
113		if test "$ac_boost_path" != ""; then
114               		BOOST_LDFLAGS="-L$ac_boost_path/lib"
115			if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
116				for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
117					_version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
118					V_CHECK=`expr $_version_tmp \> $_version`
119					if test "$V_CHECK" = "1" ; then
120						_version=$_version_tmp
121					fi
122					VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
123					BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE"
124				done
125			fi
126		else
127			for ac_boost_path in /usr /usr/local /opt ; do
128				if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
129					for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
130						_version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'`
131						V_CHECK=`expr $_version_tmp \> $_version`
132						if test "$V_CHECK" = "1" ; then
133							_version=$_version_tmp
134	               					best_path=$ac_boost_path
135						fi
136					done
137				fi
138			done
139
140			VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
141			BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
142			BOOST_LDFLAGS="-L$best_path/lib"
143
144	    		if test "x$BOOST_ROOT" != "x"; then
145				if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then
146					version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'`
147					stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'`
148			        	stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'`
149					V_CHECK=`expr $stage_version_shorten \>\= $_version`
150				        if test "$V_CHECK" = "1" ; then
151						AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT)
152						BOOST_CPPFLAGS="-I$BOOST_ROOT"
153						BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib"
154					fi
155				fi
156	    		fi
157		fi
158
159		CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
160		export CPPFLAGS
161		LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
162		export LDFLAGS
163
164		AC_LANG_PUSH(C++)
165	     	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
166		@%:@include <boost/version.hpp>
167		]], [[
168		#if BOOST_VERSION >= $WANT_BOOST_VERSION
169		// Everything is okay
170		#else
171		#  error Boost version is too old
172		#endif
173		]])],[
174        	AC_MSG_RESULT(yes)
175		succeeded=yes
176		found_system=yes
177       		],[
178	       	])
179		AC_LANG_POP([C++])
180	fi
181
182	if test "$succeeded" != "yes" ; then
183		if test "$_version" = "0" ; then
184			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.]])
185		else
186			AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).])
187		fi
188	else
189		AC_SUBST(BOOST_CPPFLAGS)
190		AC_SUBST(BOOST_LDFLAGS)
191		AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available])
192	fi
193
194        CPPFLAGS="$CPPFLAGS_SAVED"
195       	LDFLAGS="$LDFLAGS_SAVED"
196fi
197
198])
199