Imported Upstream version 3.2.2
[debian/gnuradio] / config / ax_boost_base.m4
1 # ===========================================================================
2 #             http://autoconf-archive.cryp.to/ax_boost_base.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 #   AX_BOOST_BASE([MINIMUM-VERSION])
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 # LAST MODIFICATION
27 #
28 #   2008-04-12
29 #
30 # COPYLEFT
31 #
32 #   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de>
33 #   Copyright (c) 2008 Free Software Foundation, Inc.
34 #
35 #   Copying and distribution of this file, with or without modification, are
36 #   permitted in any medium without royalty provided the copyright notice
37 #   and this notice are preserved.
38
39 AC_DEFUN([AX_BOOST_BASE],
40 [
41 AC_REQUIRE([GR_LIB64])
42 AC_ARG_WITH([boost],
43     AS_HELP_STRING([--with-boost@<:@=DIR@:>@],
44                    [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]),
45     [
46     if test "$withval" = "no"; then
47         want_boost="no"
48     elif test "$withval" = "yes"; then
49         want_boost="yes"
50         ac_boost_path=""
51     else
52         want_boost="yes"
53         ac_boost_path="$withval"
54     fi
55     ],
56     [want_boost="yes"])
57
58
59 AC_ARG_WITH([boost-libdir],
60         AS_HELP_STRING([--with-boost-libdir=LIB_DIR],
61                        [Force given directory for boost libraries. Note that this
62                         will overwrite library path detection, so use this parameter
63                         only if default library detection fails and you know exactly
64                         where your boost libraries are located.]),
65         [
66         if test -d $withval
67         then
68                 ac_boost_lib_path="$withval"
69         else
70                 AC_MSG_ERROR(--with-boost-libdir expected directory name)
71         fi
72         ],
73         [ac_boost_lib_path=""]
74 )
75
76 if test "x$want_boost" = "xyes"; then
77     boost_lib_version_req=ifelse([$1], ,1.20.0,$1)
78     boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
79     boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'`
80     boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
81     boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
82     if test "x$boost_lib_version_req_sub_minor" = "x" ; then
83         boost_lib_version_req_sub_minor="0"
84         fi
85     WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+  $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor`
86     AC_MSG_CHECKING(for boost >= $boost_lib_version_req)
87     succeeded=no
88
89     dnl first we check the system location for boost libraries
90     dnl this location ist chosen if boost libraries are installed with the --layout=system option
91     dnl or if you install boost with RPM
92     if test "$ac_boost_path" != ""; then
93         dnl Look first where we think they ought to be, accounting for a possible "64" suffix on lib.
94         dnl If that directory doesn't exist, fall back to the default behavior
95         if test -d "$ac_boost_path/lib${gr_libdir_suffix}"; then
96             BOOST_LDFLAGS="-L$ac_boost_path/lib${gr_libdir_suffix}"
97         else
98             BOOST_LDFLAGS="-L$ac_boost_path/lib"
99         fi
100         BOOST_CPPFLAGS="-I$ac_boost_path/include"
101     else
102         for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do
103             if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then
104                 dnl Look first where we think they ought to be, accounting for a possible "64" suffix on lib.
105                 dnl If that directory doesn't exist, fall back to the default behavior
106                 if test -d "$ac_boost_path_tmp/lib${gr_libdir_suffix}"; then
107                     BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib${gr_libdir_suffix}"
108                 else
109                     BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib"
110                 fi
111                 BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include"
112                 break;
113             fi
114         done
115     fi
116
117     dnl overwrite ld flags if we have required special directory with
118     dnl --with-boost-libdir parameter
119     if test "$ac_boost_lib_path" != ""; then
120        BOOST_LDFLAGS="-L$ac_boost_lib_path"
121     fi
122
123     CPPFLAGS_SAVED="$CPPFLAGS"
124     CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
125     export CPPFLAGS
126
127     LDFLAGS_SAVED="$LDFLAGS"
128     LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
129     export LDFLAGS
130
131     AC_LANG_PUSH(C++)
132         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
133     @%:@include <boost/version.hpp>
134     ]], [[
135     #if BOOST_VERSION >= $WANT_BOOST_VERSION
136     // Everything is okay
137     #else
138     #  error Boost version is too old
139     #endif
140     ]])],[AC_MSG_RESULT(yes)
141           succeeded=yes
142           found_system=yes
143           ],
144          [])
145     AC_LANG_POP([C++])
146     CPPFLAGS="$CPPFLAGS_SAVED"
147     LDFLAGS="$LDFLAGS_SAVED"
148
149
150     dnl if we found no boost with system layout we search for boost libraries
151     dnl built and installed without the --layout=system option
152     if test "$succeeded" != "yes"; then
153         _version=0
154
155         if test "$ac_boost_path" != ""; then
156             path_list="$ac_boost_path"
157         else
158             path_list="/usr /usr/local /opt /opt/local"
159         fi
160         for ac_boost_path in $path_list ; do
161             if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then
162                 for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do
163                     _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's,/include/boost-,,; s,_,.,'`
164                     V_CHECK=`expr $_version_tmp \> $_version`
165                     if test "$V_CHECK" = "1" ; then
166                         _version=$_version_tmp
167                         best_path=$ac_boost_path
168                     fi
169                 done
170             fi
171         done
172
173         VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'`
174         BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE"
175
176         if test "$ac_boost_lib_path" = "";  then
177             dnl Look first where we think they ought to be, accounting for a possible "64" suffix on lib.
178             dnl If that directory doesn't exist, fall back to the default behavior
179             if test -d "$best_path/lib${gr_libdir_suffix}"; then
180                 BOOST_LDFLAGS="-L$best_path/lib${gr_libdir_suffix}"
181             else
182                 BOOST_LDFLAGS="-L$best_path/lib"
183             fi
184         fi
185
186         CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
187         export CPPFLAGS
188         LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
189         export LDFLAGS
190
191         AC_LANG_PUSH(C++)
192             AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
193         @%:@include <boost/version.hpp>
194         ]], [[
195         #if BOOST_VERSION >= $WANT_BOOST_VERSION
196         // Everything is okay
197         #else
198         #  error Boost version is too old
199         #endif
200         ]])],[AC_MSG_RESULT(yes)
201               succeeded=yes
202               found_system=yes
203               ],
204              [])
205         AC_LANG_POP([C++])
206         CPPFLAGS="$CPPFLAGS_SAVED"
207         LDFLAGS="$LDFLAGS_SAVED"
208     fi
209
210     if test "$succeeded" != "yes" ; then
211         AC_MSG_RESULT([no])
212         if test "$_version" = "0" ; then
213             AC_MSG_ERROR([[we could not detect the boost libraries (version $boost_lib_version_req_shorten or higher).
214 If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>.]])
215         else
216             AC_MSG_ERROR([your boost libraries seem to old (version $_version).])
217         fi
218     else
219         AC_SUBST(BOOST_CPPFLAGS)
220         AC_SUBST(BOOST_LDFLAGS)
221         AC_DEFINE(HAVE_BOOST,1,[Define if the Boost headers are available])
222     fi
223 fi
224 ])
225
226 dnl
227 dnl Macros used by the boost items that need libraries.
228 dnl
229
230 dnl $1 is unit name.  E.g., boost_thread
231 AC_DEFUN([_AX_BOOST_CHECK_LIB],[
232     _AX_BOOST_CHECK_LIB_($1,HAVE_[]m4_toupper($1),m4_toupper($1)_LIB)
233 ])
234
235 dnl $1 is unit name.  E.g., boost_thread
236 dnl $2 is AC_DEFINE name.  E.g., HAVE_BOOST_THREAD
237 dnl $3 is lib var name.    E.g., BOOST_THREAD_LIB
238 AC_DEFUN([_AX_BOOST_CHECK_LIB_],[
239     AC_LANG_PUSH([C++])
240     AC_DEFINE($2,1,[Define if the $1 library is available])
241     BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
242
243     dnl See if we can find a usable library
244     link_ok="no"
245     if test "$ax_boost_user_lib" != ""; then
246         dnl use what the user supplied 
247         for ax_lib in $ax_boost_user_lib $1-${ax_boost_user_lib}; do
248             AC_CHECK_LIB($ax_lib, exit,
249                          [$3="-l$ax_lib"; AC_SUBST($3) link_ok="yes"; break])
250         done
251     else
252         dnl Look in BOOSTLIBDIR for possible candidates
253         head=$BOOSTLIBDIR/lib[]$1
254         for f in ${head}*.so* ${head}*.a* ${head}*.dll* ${head}*.dylib; do
255             dnl echo 1: $f
256             case $f in
257               *\**) continue;;
258             esac
259             f=`echo $f | sed -e 's,.*/,,' -e 's,^lib,,'`
260             dnl echo 2: $f
261             f=`echo $f | sed -e 's,\($1.*\)\.so.*$,\1,' -e 's,\($1.*\)\.a.*$,\1,' -e 's,\($1.*\)\.dll.*$,\1,' -e 's,\($1.*\)\.dylib.*$,\1,'`
262             dnl echo 3: $f
263
264             ax_lib=$f
265             AC_CHECK_LIB($ax_lib, exit,
266                         [$3="-l$ax_lib"; AC_SUBST($3) link_ok="yes"; break])
267         done
268     fi              
269                                     
270     if test "$link_ok" != "yes"; then
271         AC_MSG_ERROR([Could not link against lib[$1]!])
272     fi
273     AC_LANG_POP([C++])
274 ])
275
276
277 dnl $1 is unit name.  E.g., boost_thread
278 AC_DEFUN([_AX_BOOST_WITH],[
279     _AX_BOOST_WITH_($1,m4_bpatsubst($1,_,-))
280 ])
281
282 dnl $1 is unit name.  E.g., boost_thread
283 dnl $2 is hyphenated unit name.  E.g., boost-thread
284 AC_DEFUN([_AX_BOOST_WITH_],[
285     AC_ARG_WITH([$2],
286                 AC_HELP_STRING([--with-$2@<:@=special-lib@:>@],
287                                [Use the m4_substr($1,6) library from boost.  It is possible to specify a certain
288                                 library to the linker.  E.g., --with-$2=$1-gcc41-mt-1_35]),
289                 [
290                 if test "$withval" = "no"; then
291                     want_boost="no"
292                 elif test "$withval" = "yes"; then
293                     want_boost="yes"
294                     ax_boost_user_lib=""
295                 else
296                     want_boost="yes"
297                     ax_boost_user_lib="$withval"
298                 fi
299                 ],
300                 [want_boost="yes"])
301 ])
302
303 dnl $1 is unit name.  E.g., boost_thread
304 dnl $2 is AC_LANG_PROGRAM argument 1
305 dnl $3 is AC_LANG_PROGRAM argument 2
306 dnl $4 is cv variable name.  E.g., ax_cv_boost_thread
307 AC_DEFUN([_AX_BOOST_CHECK_],[
308     _AX_BOOST_WITH($1)
309     if test "$want_boost" = "yes"; then
310         AC_REQUIRE([AC_PROG_CC])
311         AC_REQUIRE([AC_PROG_CXX])
312         CPPFLAGS_SAVED="$CPPFLAGS"
313         CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
314         LDFLAGS_SAVED="$LDFLAGS"
315         LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
316         AC_CACHE_CHECK([whether the boost::m4_substr([$1],6) includes are available], [$4],
317                        [AC_LANG_PUSH([C++])
318                         AC_COMPILE_IFELSE(AC_LANG_PROGRAM([$2],[$3]),[$4]=yes,[$4]=no)
319                         AC_LANG_POP([C++])
320                        ])
321         if test "$[$4]" = "yes"; then
322             _AX_BOOST_CHECK_LIB([$1])
323         fi
324         CPPFLAGS="$CPPFLAGS_SAVED"
325         LDFLAGS="$LDFLAGS_SAVED"
326     fi
327 ])
328
329 dnl $1 is unit name.  E.g., boost_thread
330 dnl $2 is AC_LANG_PROGRAM argument 1
331 dnl $3 is AC_LANG_PROGRAM argument 2
332 AC_DEFUN([_AX_BOOST_CHECK],[
333     _AX_BOOST_CHECK_($1,$2,$3,ax_cv_$1)
334 ])