Permalink
Browse files

re-work boost detection again

it now supports trying over and over until it finds one that works.
  • Loading branch information...
1 parent 5b4d519 commit 1605e60b5b09da62a634d911680b2327c224e2df @novas0x2a novas0x2a committed Jan 1, 2010
Showing with 148 additions and 142 deletions.
  1. +18 −14 configure.ac
  2. +31 −0 m4/ax_extract_cpp_symbol.m4
  3. +1 −1 m4/ax_find_files.m4
  4. +40 −63 m4/ax_pkg_boost.m4
  5. +1 −12 m4/ax_pkg_boost_check_version.m4
  6. +57 −52 m4/ax_pkg_boost_lib.m4
View
@@ -192,20 +192,24 @@ AM_CONDITIONAL(DIST_REMOVE_MODULES, [test ! -z "$DIST_REMOVE_MODULES"])
AX_PKG_PTHREADS
-AX_PKG_BOOST
-if test x"$HAVE_PKG_BOOST" = "xyes"; then
- AX_PKG_BOOST_CHECK_VERSION([VW_])
- AC_MSG_NOTICE([VW will be built using Boost version $BOOST_VERSION])
-
- AX_PKG_BOOST_LIB(PROGRAM_OPTIONS, [-lboost_program_options], [boost/program_options.hpp])
- AX_PKG_BOOST_LIB(SYSTEM, [-lboost_system], [boost/system/error_code.hpp])
- AX_PKG_BOOST_LIB(FILESYSTEM, [-lboost_filesystem], [boost/filesystem/path.hpp], [$PKG_BOOST_SYSTEM_LIBS])
- AX_PKG_BOOST_LIB(REGEX, [-lboost_regex], [boost/regex.hpp])
- AX_PKG_BOOST_LIB(DATETIME, [-lboost_date_time], [boost/date_time/gregorian/gregorian_types.hpp])
- AX_PKG_BOOST_LIB(THREAD, [-lboost_thread], [boost/thread/thread.hpp], [$PKG_BOOST_DATETIME_LIBS], [boost/thread/condition.hpp])
- AX_PKG_BOOST_LIB(IOSTREAMS, [-lboost_iostreams], [boost/iostreams/stream_buffer.hpp])
- AX_PKG_BOOST_LIB(GRAPH, [], [boost/graph/adjacency_list.hpp])
-fi
+AX_PKG_BOOST([BOOST_PROGRAM_OPTIONS BOOST_FILESYSTEM BOOST_THREAD BOOST_GRAPH],
+ BOOST_PROGRAM_OPTIONS,
+ [AX_PKG_BOOST_LIB(PROGRAM_OPTIONS, [-lboost_program_options], [boost/program_options.hpp], [boost::program_options::options_description("Rawr");])],
+ BOOST_SYSTEM,
+ [AX_PKG_BOOST_LIB(SYSTEM, [-lboost_system], [boost/system/error_code.hpp], [boost::system::error_code();])],
+ BOOST_FILESYSTEM,
+ [AX_PKG_BOOST_LIB(FILESYSTEM, [-lboost_filesystem], [boost/filesystem/path.hpp], [boost::filesystem::path();], [$PKG_BOOST_SYSTEM_LIBS])],
+ BOOST_REGEX,
+ [AX_PKG_BOOST_LIB(REGEX, [-lboost_regex], [boost/regex.hpp], [boost::regex(".*");])],
+ BOOST_DATETIME,
+ [AX_PKG_BOOST_LIB(DATETIME, [-lboost_date_time], [boost/date_time/gregorian/gregorian_types.hpp])],
+ BOOST_THREAD,
+ [AX_PKG_BOOST_LIB(THREAD, [-lboost_thread], [boost/thread/thread.hpp], [boost::mutex();], [$PKG_BOOST_DATETIME_LIBS], [boost/thread/condition.hpp])],
+ BOOST_IOSTREAMS,
+ [AX_PKG_BOOST_LIB(IOSTREAMS, [-lboost_iostreams], [boost/iostreams/device/mapped_file.hpp], [boost::iostreams::mapped_file_source();])],
+ BOOST_GRAPH,
+ [AX_PKG_BOOST_LIB(GRAPH, [], [boost/graph/adjacency_list.hpp])]
+)
# This provides an easy way for users to override the threads options
# if they are replacing Boost threads with something else for their platform.
@@ -0,0 +1,31 @@
+dnl __BEGIN_LICENSE__
+dnl __END_LICENSE__
+
+dnl Usage: AX_EXTRACT_CPP_SYMBOL([symbol], [headers], [ifyes], [ifno])
+dnl It the variable $output will contain the extracted value
+dnl example: AX_EXTRACT_CPP_SYMBOL([BOOST_VERSION], [BOOST_VERSION="$output"], [BOOST_VERSION=nope], [#include <boost/version.hpp>])
+AC_DEFUN([AX_EXTRACT_CPP_SYMBOL],
+[
+ AC_REQUIRE_CPP()dnl
+ AC_REQUIRE([AC_PROG_SED])dnl
+AC_LANG_CONFTEST(
+ [AC_LANG_SOURCE([$2
+#define __ac_extract_cpp_symbol_delimiter "__ac_extract_cpp_symbol_delimiter"
+__ac_extract_cpp_symbol_delimiter $1 __ac_extract_cpp_symbol_delimiter])])
+
+AS_VAR_PUSHDEF([output], [ax_extract_cpp_symbol_$1])dnl
+if (eval "$ac_cpp conftest.$ac_ext") >conftest.out 2>&AC_FD_CC; then
+ output="`${SED} -n -e 's/^.*"__ac_extract_cpp_symbol_delimiter" \(.*\) "__ac_extract_cpp_symbol_delimiter".*$/\1/p' conftest.out 2>/dev/null`"
+ if test x"${output}" != x"$1"; then
+ ifelse([$3], , :, [$3])
+ ifelse([$4], , , [else
+ $4
+])
+ fi
+ ifelse([$4], , , [else
+ $4
+])dnl
+fi
+AS_VAR_POPDEF([output])
+rm -f conftest*
+])
View
@@ -21,7 +21,7 @@ AC_DEFUN([AX_FIND_FILES],
if test ! -z "$ax_find_files_paths" ; then
AX_LOG([Find Files: Found ${ax_find_files_paths}])
else
- AX_LOG([Fine Files: Not Found])
+ AX_LOG([Find Files: Not Found])
ax_find_files_passed=no
break
fi
View
@@ -5,7 +5,7 @@ dnl All Rights Reserved.
dnl __END_LICENSE__
-# Usage: AX_PKG_BOOST
+# Usage: AX_PKG_BOOST(<required boost libs> [,boost_lib, how-to-detect-lib]*)
AC_DEFUN([AX_PKG_BOOST],
[
m4_divert_once([INIT_PREPARE], [dnl
@@ -14,8 +14,6 @@ AC_DEFUN([AX_PKG_BOOST],
[ HAVE_PKG_BOOST=$withval ]
)])
- AC_MSG_CHECKING(for package BOOST)
-
AC_LANG_ASSERT(C++)
if test -n "${HAVE_PKG_BOOST}" && test "${HAVE_PKG_BOOST}" != "yes" && test "${HAVE_PKG_BOOST}" != "no" && test x"${HAVE_PKG_BOOST#no:}" = "x$HAVE_PKG_BOOST"; then
@@ -26,88 +24,67 @@ AC_DEFUN([AX_PKG_BOOST],
# Skip testing if the user has overridden
if test "no" = "$HAVE_PKG_BOOST"; then
- AC_MSG_RESULT([no (disabled by user)])
+ HAVE_PKG_BOOST="no:disabled by user"
elif test x"${HAVE_PKG_BOOST#no:}" != "x$HAVE_PKG_BOOST"; then # read as: if has_prefix(HAVE_PKG_BOOST, "no:")
- dnl { and } break AC_MSG_RESULT
- reason="${HAVE_PKG_BOOST#no:}"
- AC_MSG_RESULT([no ($reason)])
- HAVE_PKG_BOOST=no
+ :
else
- PKG_BOOST_CPPFLAGS=
- PKG_BOOST_LIBS=
HAVE_PKG_BOOST=no
- ax_pkg_old_cppflags="$CPPFLAGS"
- ax_pkg_old_ldflags="$LDFLAGS"
-
for ax_boost_base_path in $PKG_PATHS_BOOST; do
- # First look for a system-style installation
- AX_LOG([Checking for a boost in ${ax_boost_base_path}])
-
- if test -f "${ax_boost_base_path}/include/boost/version.hpp" ; then
- AX_LOG([Found a system-style boost])
- PKG_BOOST_INCDIR="${ax_boost_base_path}/include"
- PKG_BOOST_LIBDIR="${ax_boost_base_path}/${AX_LIBDIR}"
- HAVE_PKG_BOOST="yes"
- else
- # Next look for a default-style installation
- for ax_boost_inc_path in `ls -d ${ax_boost_base_path}/include/boost-* 2> /dev/null` ; do
- AX_LOG([Checking for default-style boost in ${ax_boost_inc_path}])
- if test -f "${ax_boost_inc_path}/boost/version.hpp"; then
- AX_LOG([Found a default-style boost in ${ax_boost_inc_path}])
- # At the moment we greedily accept the first one we find, regardless of version
- PKG_BOOST_INCDIR="${ax_boost_inc_path}"
- PKG_BOOST_LIBDIR="${ax_boost_base_path}/${AX_LIBDIR}"
- HAVE_PKG_BOOST="yes"
- fi
- done
- fi
-
- if test x"${HAVE_PKG_BOOST}" = "xyes"; then
+ boost_base_path_glob="${ax_boost_base_path}/include/boost-*"
+ for ax_boost_inc_path in ${ax_boost_base_path}/include `echo ${boost_base_path_glob} | xargs -n1 | sort -r` ; do
+ AX_LOG([Checking for a boost in ${ax_boost_inc_path}])
+ if test -f "${ax_boost_inc_path}/boost/version.hpp"; then
+ AC_MSG_NOTICE([Checking if Boost at ${ax_boost_inc_path}/boost is OK])
- HAVE_PKG_BOOST="no"
+ AX_EXTRACT_CPP_SYMBOL([BOOST_VERSION], [#include <boost/version.hpp>], [BOOST_VERSION=$output],
+ [AX_LOG([Couldn't get boost version for $ax_boost_inc_path/boost]); continue;])
- # In case it's not in lib64 despite specifying lib64...
- if test ! -d $PKG_BOOST_LIBDIR -a x"${AX_OTHER_LIBDIR}" != "x"; then
- PKG_BOOST_LIBDIR="${ax_boost_base_path}/${AX_OTHER_LIBDIR}"
- fi
-
- CPPFLAGS="$ax_pkg_old_cppflags -I${PKG_BOOST_INCDIR}"
- LDFLAGS="$ax_pkg_old_ldflags -L${PKG_BOOST_LIBDIR}"
+ AX_LOG([Found boost includes at ${ax_boost_inc_path}, version(${BOOST_VERSION})])
- echo "#include <boost/version.hpp>" > conftest.h
+ PKG_BOOST_INCDIR="${ax_boost_inc_path}"
+ PKG_BOOST_LIBDIR="${ax_boost_base_path}/${AX_LIBDIR}"
- dnl check for the header
- dnl otherwise, check next path
- AC_LINK_IFELSE(
- AC_LANG_PROGRAM([#include "conftest.h"],[]),
- [ HAVE_PKG_BOOST=yes; break; ])
+ # In case it's not in lib64 despite specifying lib64...
+ if test ! -d $PKG_BOOST_LIBDIR -a x"${AX_OTHER_LIBDIR}" != "x"; then
+ PKG_BOOST_LIBDIR="${ax_boost_base_path}/${AX_OTHER_LIBDIR}"
+ fi
- HAVE_PKG_BOOST="no"
- unset PKG_BOOST_INCDIR
- unset PKG_BOOST_LIBDIR
+ m4_for([idx], 3, $#, 2, [m4_unquote(m4_argn(idx, $@))])
- fi
+ missing=
+ AC_FOREACH([required], $1,
+ [AS_IF([test x"$HAVE_PKG_]required[" != "xyes"], [missing="${missing} required"]); ])
+ AS_IF([test -n "$missing"], [AC_MSG_NOTICE([${ax_boost_inc_path}/boost is missing these required libraries: $missing]); continue;],
+ [
+ HAVE_PKG_BOOST="yes"
+ break 2
+ ])
+ fi
+ done
done
- CPPFLAGS="$ax_pkg_old_cppflags"
- LDFLAGS="$ax_pkg_old_ldflags"
-
- AC_MSG_RESULT([$HAVE_PKG_BOOST])
-
fi
+ AC_MSG_CHECKING(for package BOOST)
+
if test "${HAVE_PKG_BOOST}" = "yes" ; then
ax_have_pkg_bool=1
- PKG_BOOST_CPPFLAGS="-I${PKG_BOOST_INCDIR}"
- PKG_BOOST_LIBS="-L${PKG_BOOST_LIBDIR}"
- OTHER_CPPFLAGS="${OTHER_CPPFLAGS} ${PKG_BOOST_CPPFLAGS}"
- OTHER_LDFLAGS="${OTHER_LDFLAGS} ${PKG_BOOST_LIBS}"
+ OTHER_CPPFLAGS="${OTHER_CPPFLAGS} -I${PKG_BOOST_INCDIR}"
+ OTHER_LDFLAGS="${OTHER_LDFLAGS} -L${PKG_BOOST_LIBDIR}"
+ AC_MSG_RESULT([yes])
+ elif test x"${HAVE_PKG_BOOST#no:}" != "x$HAVE_PKG_BOOST"; then # read as: if has_prefix(HAVE_PKG_BOOST, "no:")
+ dnl { and } break AC_MSG_RESULT
+ reason="${HAVE_PKG_BOOST#no:}"
+ AC_MSG_RESULT([no ($reason)])
else
+ HAVE_PKG_BOOST=no
ax_have_pkg_bool=0
+ AC_MSG_RESULT([no])
fi
+
AC_DEFINE_UNQUOTED([HAVE_PKG_BOOST],
[$ax_have_pkg_bool],
[Define to 1 if the BOOST package is available.])
@@ -15,18 +15,7 @@ AC_DEFUN([AX_PKG_BOOST_CHECK_VERSION],
CPPFLAGS="$PKG_BOOST_CPPFLAGS"
LDFLAGS="$PKG_BOOST_LDFLAGS"
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM([[
- #include <fstream>
- #include <boost/version.hpp>
- ]], [[
- std::ofstream out("conftest.out");
- if (!out.is_open())
- return 1;
- out << BOOST_VERSION;
- ]])],
- [BOOST_VERSION=`cat conftest.out`],
- [AC_MSG_ERROR([Failed to run Boost version check program])])
+ AX_EXTRACT_CPP_SYMBOL([BOOST_VERSION], [BOOST_VERSION=$output], AC_MSG_ERROR([Failed to run Boost version check program]), [#include <boost/version.hpp>])
if test -z "$BOOST_VERSION"; then
AC_MSG_ERROR([Boost version check program did not define BOOST_VERSION])
View
@@ -4,6 +4,11 @@ dnl the Administrator of the National Aeronautics and Space Administration.
dnl All Rights Reserved.
dnl __END_LICENSE__
+dnl this was introduced in autoconf 2.6, i think.
+m4_ifset([m4_foreach_w], [],
+[m4_define([m4_foreach_w],[m4_foreach([$1], m4_split(m4_normalize([$2])), [$3])])])
+
+m4_pattern_allow([^PKG_BOOST_SAME_SUFFIX])
dnl Here's a new version of AX_PKG_BOOST_LIB designed to find the
dnl multithreaded boost libraries and boost libraries that are just weirdly
@@ -19,7 +24,7 @@ dnl Boost with the string in said variable somewhere inside the Boost
dnl library names, but after the initial name of the library (specified
dnl as the second parameter to this function). A blank value will give
dnl normal behavior.
-# Usage: AX_PKG_BOOST_LIB(<name>, <libraries>, <header>, [<ldflags>, <other-headers>])
+# Usage: AX_PKG_BOOST_LIB(<name>, <libraries>, <header>, <function>[, <dep-libs>, <other-headers>])
AC_DEFUN([AX_PKG_BOOST_LIB],
[
AC_MSG_CHECKING(for package BOOST_$1)
@@ -32,71 +37,71 @@ AC_DEFUN([AX_PKG_BOOST_LIB],
HAVE_PKG_BOOST_$1=no
# Check for general Boost presence
- if test "x${HAVE_PKG_BOOST}" = "xyes" ; then
- # Check for required headers
- AX_FIND_FILES([$3],[${PKG_BOOST_INCDIR}])
- if test ! -z "$ax_find_files_path" ; then
- # Check for required libraries with no suffix, aside from the one
- # given by environment variable.
- AX_FIND_FILES([`echo $2 | sed "s/-l\([[^[:space:]]]*\)/lib\1${BOOST_LIBRARIES_SUFFIX}.*/g"`],[$PKG_BOOST_LIBDIR])
- if test ! -z "$ax_find_files_path" ; then
- HAVE_PKG_BOOST_$1="yes"
- ax_pkg_boost_lib=`echo $2 | sed "s/\(-l[[^[:space:]]]*\)/\1${BOOST_LIBRARIES_SUFFIX}/g"`
- PKG_BOOST_$1_LIBS="$PKG_BOOST_LIBS $ax_pkg_boost_lib $4"
+ if test -n "$PKG_BOOST_INCDIR" -a -n "$PKG_BOOST_LIBDIR"; then
+
+ m4_ifval([$2], [
+ boost_name="$2"
+ boost_name="${boost_name#-l}"
+ # The SAME_SUFFIX macro is sticky from the previously-searched-for boost lib.
+ # They should all have the same suffix.
+ if test -n "${PKG_BOOST_SAME_SUFFIX}"; then
+ AX_LOG([Reusing suffix ${PKG_BOOST_SAME_SUFFIX}])
+ libglob="${PKG_BOOST_LIBDIR}/lib${boost_name}${PKG_BOOST_SAME_SUFFIX}"
else
- # Check for required libraries with some suffix. We have to check
- # for both a suffix before ${BOOST_LIBRARIES_SUFFIX} (pre-suffix)
- # and a suffix after (for example) the -mt (post-suffix), because
- # boost likes to stick the name of the compiler before the -mt.
- # Extremely annoying.
-
- ax_pkg_boost_lib=`echo $2 | awk '{print [$]1}' | sed 's/-l\([[^[:space:]-]]*\).*/lib\1/g'`
- ax_pkg_boost_file=`ls ${PKG_BOOST_LIBDIR}/${ax_pkg_boost_lib}-*${BOOST_LIBRARIES_SUFFIX}${BOOST_LIBRARIES_SUFFIX:+*} | head -n 1 | sed "s,^${PKG_BOOST_LIBDIR}/\(.*\),\1,"`
-
- # The pre-suffix.
- ax_pkg_boost_presuffix=`echo ${ax_pkg_boost_file} | sed "s/${ax_pkg_boost_lib}\([[^.]]*\)${BOOST_LIBRARIES_SUFFIX}.*/\1/"`
-
- # The post-suffix.
- ax_pkg_boost_postsuffix=`echo ${ax_pkg_boost_file} | sed "s/${ax_pkg_boost_lib}${ax_pkg_boost_presuffix}${BOOST_LIBRARIES_SUFFIX}\([[^.]]*\).*/\1/"`
-
- AX_FIND_FILES([`echo $2 | sed "s/-l\([[^[:space:]]]*\)/lib\1${ax_pkg_boost_presuffix}${BOOST_LIBRARIES_SUFFIX}${ax_pkg_boost_postsuffix}.*/g"`],[$PKG_BOOST_LIBDIR])
- if test ! -z $ax_find_files_path ; then
- HAVE_PKG_BOOST_$1="yes"
- PKG_BOOST_$1_LIBS=`echo $2 | sed "s/[[^ ]]*/&${ax_pkg_boost_presuffix}${BOOST_LIBRARIES_SUFFIX}${ax_pkg_boost_postsuffx}/g"`
- PKG_BOOST_$1_LIBS="$PKG_BOOST_LIBS $PKG_BOOST_$1_LIBS $4"
+ AX_LOG([No known suffix. Figuring one out.])
+ libglob="${PKG_BOOST_LIBDIR}/lib${boost_name}*.so"
+ # If they ask for a suffix, look for it first
+ if test -n "${BOOST_LIBRARIES_SUFFIX}"; then
+ boost_want_suffix="${PKG_BOOST_LIBDIR}/lib${boost_name}${BOOST_LIBRARIES_SUFFIX}.so"
+ else
+ boost_want_suffix=
fi
fi
- fi
- fi
- fi
+ ])
+
+ ax_pkg_old_cppflags="$CPPFLAGS"
+ ax_pkg_old_libs="$LIBS"
+
+ m4_ifval([$2], [
+ for boost_libpath in $boost_want_suffix `echo ${libglob} | xargs -n1 | sort -r`; do
+ ], [
+ for boost_libpath in boost_header_only; do
+ ])
+
+ AX_LOG([Checking to see if $boost_libpath works])
+ m4_ifval([$2], [
+ dnl If the glob doesn't expand, we'll get the same path back. Check for that.
+ AS_IF([test ! -f ${boost_libpath}], [continue])
+ stem="`basename $boost_libpath .so`"
+ PKG_BOOST_SAME_SUFFIX="${stem#lib${boost_name}}.so"
+ PKG_BOOST_$1_LIBS="-L${PKG_BOOST_LIBDIR} -l${stem#lib} $5"
+ ])
- # Check to make sure we found a working one
- ax_pkg_old_cppflags="$CPPFLAGS"
- ax_pkg_old_libs="$LIBS"
+ PKG_BOOST_$1_CPPFLAGS="-I${PKG_BOOST_INCDIR}"
- echo > conftest.h
- for header in $5 ; do
- echo "#include <$header>" >> conftest.h
- done
- for header in $3 ; do
- echo "#include <$header>" >> conftest.h
- done
+ # Check to make sure we found a working one
+ CPPFLAGS="$ax_pkg_old_cppflags $PKG_BOOST_$1_CPPFLAGS"
+ LIBS="$ax_pkg_old_libs $PKG_BOOST_$1_LIBS"
- CPPFLAGS="$CPPFLAGS $PKG_BOOST_CPPFLAGS"
- LIBS="$LIBS $PKG_BOOST_$1_LIBS"
+ AC_LINK_IFELSE(
+ AC_LANG_PROGRAM(m4_foreach_w([header], [$6 $3], [@%:@include <header>
+]), [[$4]]), [ HAVE_PKG_BOOST_$1=yes; break; ], [ continue ] )
+ done
- AC_LINK_IFELSE(
- AC_LANG_PROGRAM([#include "conftest.h"],[]),
- [ HAVE_PKG_BOOST_$1=yes ], [ HAVE_PKG_BOOST_$1=no ] )
+ CPPFLAGS="$ax_pkg_old_cppflags"
+ LIBS="$ax_pkg_old_libs"
- CPPFLAGS="$ax_pkg_old_cppflags"
- LIBS="$ax_pkg_old_libs"
+ fi # PKG_BOOST_INCDIR/LIBDIR set.
+ fi # User override
AC_MSG_RESULT([$HAVE_PKG_BOOST_]$1)
if test "${HAVE_PKG_BOOST_$1}" = "yes" ; then
ax_have_pkg_bool=1
else
+ PKG_BOOST_SAME_SUFFIX=
+ PKG_BOOST_$1_CPPFLAGS=
+ PKG_BOOST_$1_LIBS=
ax_have_pkg_bool=0
fi
AC_DEFINE_UNQUOTED([HAVE_PKG_BOOST_$1],

0 comments on commit 1605e60

Please sign in to comment.