[glom/boostpythonretry] m4 hackery for boost::python. Seems to work more or less.



commit d8ecf88b6ff4ba9f928d1c1a3b6ae593a915b555
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Feb 10 09:42:26 2010 +0100

    m4 hackery for boost::python. Seems to work more or less.

 configure.ac              |   30 ++---------
 macros/ax_boost_python.m4 |  121 +++++++++++++++++++++++++++++++++++++++++++++
 macros/ax_python.m4       |   98 ++++++++++++++++++++++++++++++++++++
 macros/mm-python.m4       |    3 +
 4 files changed, 227 insertions(+), 25 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2adfeb5..0b43566 100644
--- a/configure.ac
+++ b/configure.ac
@@ -200,31 +200,11 @@ AC_CHECK_FUNCS([strptime])
 # For instance: PYTHON=python2.5
 MM_CHECK_MODULE_PYTHON
 
-BOOST_PYTHON_LIBS="-lboost_python"
-#BOOST_PYTHON_LIBS="-lboost_python-py25.so.1.40.0"
-BOOST_PYTHON_CFLAGS="-I/opt/gnome228/include/boost"
-#BOOST_PYTHON_CFLAGS="-I/usr/include/include/boost"
-AC_SUBST([BOOST_PYTHON_LIBS])
-AC_SUBST([BOOST_PYTHON_CFLAGS])
-
-AC_ARG_WITH(boost-python,
-    [ --with-boost-python=<path> prefix of boost::python installation. e.g. /usr/local or /usr],
-    [BOOST_PYTHON_PREFIX=$with_boostpython],
-    AC_MSG_ERROR([You must call configure with the --with-boost-python option.
-    This tells configure where to find the boost::python C++ library and headers.
-    e.g. --with-boost-python=/usr/local or --with-boost-python=/usr])
-)
-BOOST_PYTHON_ACTUAL_LIB= "-lboost_python"
-#BOOST_PYTHON_ACTUAL_LIB= "-lboost_python-py25.so.1.40.0"
-BOOST_PYTHON_LIBS="-L${BOOST_PYTHON_PREFIX}/lib ${BOOST_PYTHON_ACTUAL_LIB}"
-BOOST_PYTHON_CFLAGS="-I{BOOST_PYTHON_PREFIX}/boost"
-AC_SUBST([BOOST_PYTHON_LIBS])
-AC_SUBST([BOOST_PYTHON_CFLAGS])
-
-
-#These don't work. pyconfig.h can't be found when using python.hpp.
-#AX_PYTHON()
-#AX_BOOST_PYTHON()
+# Get the CFLAGS and LIBS for boost::python.
+# Note that we have hacked this script to work with MM_CHECK_MODULE_PYTHON instead of AX_PYTHON
+# This does an AC_SUBST() of BOOST_PYTHON_LIBS
+# For the CFLAGS we must assume that boost is at the top-level, for instance in /usr/include/:
+AX_BOOST_PYTHON
 
 AC_ARG_ENABLE([update-mime-database],
               [AS_HELP_STRING([--disable-update-mime-database],
diff --git a/macros/ax_boost_python.m4 b/macros/ax_boost_python.m4
new file mode 100644
index 0000000..8ccd765
--- /dev/null
+++ b/macros/ax_boost_python.m4
@@ -0,0 +1,121 @@
+# ===========================================================================
+#         http://www.nongnu.org/autoconf-archive/ax_boost_python.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_BOOST_PYTHON
+#
+# DESCRIPTION
+#
+#   This macro checks to see if the Boost.Python library is installed. It
+#   also attempts to guess the currect library name using several attempts.
+#   It tries to build the library name using a user supplied name or suffix
+#   and then just the raw library.
+#
+#   If the library is found, HAVE_BOOST_PYTHON is defined and
+#   BOOST_PYTHON_LIBS is set to the name of the library.
+#
+#   This macro calls AC_SUBST(BOOST_PYTHON_LIBS).
+#
+#   In order to ensure that the Python headers are specified on the include
+#   path, this macro requires AX_PYTHON to be called.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Michael Tindal
+#
+#   This program is free software; you can redistribute it and/or modify it
+#   under the terms of the GNU General Public License as published by the
+#   Free Software Foundation; either version 2 of the License, or (at your
+#   option) any later version.
+#
+#   This program is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+#   Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License along
+#   with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+#serial 7
+#With large changes by murrayc
+
+#Note that this previously said it was checking for the library, but it's techically the both the headers and library that it looks for. murrayc
+AC_DEFUN([AX_BOOST_PYTHON],
+[AC_REQUIRE([AX_PYTHON])dnl
+AC_CACHE_CHECK(whether the Boost::Python headers are available,
+ac_cv_boost_python,
+[AC_LANG_SAVE
+ AC_LANG_CPLUSPLUS
+ CPPFLAGS_SAVE=$CPPFLAGS
+ # Hacked to use the output of MM_CHECK_MODULE_PYTHON() instead of the outout of AX_PYTHON, which we don't use. murrayc
+ # if test x$PYTHON_INCLUDE_DIR != x; then
+ #  CPPFLAGS=-I$PYTHON_INCLUDE_DIR $CPPFLAGS
+ #fi
+ if test x$PYTHON_CPPFLAGS != x; then
+   #Note that this expects boost/ to be at some top-level such as /usr/include/
+   #We couldn't check for anything else anyway because there's no pkg-config file to tell us where it is 
+   CPPFLAGS=$PYTHON_CPPFLAGS $CPPFLAGS
+ fi
+ AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[
+ #include <boost/python/module.hpp>
+ using namespace boost::python;
+ BOOST_PYTHON_MODULE(test) { throw "Boost::Python test."; }]],
+ 			   [[return 0;]]),
+  			   ac_cv_boost_python=yes, ac_cv_boost_python=no)
+ AC_LANG_RESTORE
+ CPPFLAGS=$CPPFLAGS_SAVE
+])
+if test "$ac_cv_boost_python" = "yes"; then
+  AC_DEFINE(HAVE_BOOST_PYTHON,,[define if the Boost::Python headers and library are available])
+  ax_python_lib=boost_python
+  AC_ARG_WITH([boost-python],AS_HELP_STRING([--with-boost-python],[specify the boost python shared library to use. For instance, --with-boost-python=boost_python-py25. Defaults to boost-python. If you use this then you should probably set PYTHON too, to avoid using multiple python versions.]),
+  [if test "x$with_boost_python" != "xno"; then
+     ax_python_lib=$with_boost_python
+     ax_boost_python_lib=boost_python-$with_boost_python
+   fi])
+  for ax_lib in $ax_python_lib $ax_boost_python_lib boost_python; do
+    #This previously checked for an exit() function in the boost::python library.
+    #That was strange and apparently no longer works. murrayc.
+    #AC_CHECK_LIB($ax_lib, exit, [BOOST_PYTHON_LIB=$ax_lib break])
+    AC_LANG_SAVE
+    AC_LANG_CPLUSPLUS
+    #Note that this requires PYTHON_LIBS from MM_CHECK_MODULE_PYTHON()
+    SAVED_CPPFLAGS=$CPPFLAGS
+    CPPFLAGS="-I$PYTHON_INCLUDE_DIR"
+    SAVED_LDFLAGS=$LDFLAGS
+    LDFLAGS="$LDFLAGS $PYTHON_LIBS -l$ax_lib"
+    AC_LINK_IFELSE(
+      [AC_LANG_PROGRAM([#include <boost/python.hpp>],
+        [boost::python::object test_object])],
+      #Note that this was previously BOOST_PYTHON_LIB, but I renamed it because people expect *LIBS. murrayc.
+      [BOOST_PYTHON_LIBS="-l$ax_lib"])
+    LDFLAGS=$SAVED_LDFLAGS
+    CPPFLAGS=$SAVED_CPPFLAGS
+    AC_LANG_RESTORE
+  done
+  if test x$BOOST_PYTHON_LIBS != x; then
+    AC_MSG_RESULT([boost::python shared library found: $BOOST_PYTHON_LIBS])
+  fi
+  #TODO: Figure out how to do a simple if else:
+  if test x$BOOST_PYTHON_LIBS == x; then
+    AC_MSG_ERROR([boost::python shared library not found])
+  fi
+  AC_SUBST(BOOST_PYTHON_LIBS)
+fi
+])dnl
+
diff --git a/macros/ax_python.m4 b/macros/ax_python.m4
new file mode 100644
index 0000000..b98ac28
--- /dev/null
+++ b/macros/ax_python.m4
@@ -0,0 +1,98 @@
+# ===========================================================================
+#            http://www.nongnu.org/autoconf-archive/ax_python.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_PYTHON
+#
+# DESCRIPTION
+#
+#   This macro does a complete Python development environment check.
+#
+#   It recurses through several python versions (from 2.1 to 2.6 in this
+#   version), looking for an executable. When it finds an executable, it
+#   looks to find the header files and library.
+#
+#   It sets PYTHON_BIN to the name of the python executable,
+#   PYTHON_INCLUDE_DIR to the directory holding the header files, and
+#   PYTHON_LIB to the name of the Python library.
+#
+#   This macro calls AC_SUBST on PYTHON_BIN (via AC_CHECK_PROG),
+#   PYTHON_INCLUDE_DIR and PYTHON_LIB.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Michael Tindal
+#
+#   This program is free software; you can redistribute it and/or modify it
+#   under the terms of the GNU General Public License as published by the
+#   Free Software Foundation; either version 2 of the License, or (at your
+#   option) any later version.
+#
+#   This program is distributed in the hope that it will be useful, but
+#   WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
+#   Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License along
+#   with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+#   As a special exception, the respective Autoconf Macro's copyright owner
+#   gives unlimited permission to copy, distribute and modify the configure
+#   scripts that are the output of Autoconf when processing the Macro. You
+#   need not follow the terms of the GNU General Public License when using
+#   or distributing such scripts, even though portions of the text of the
+#   Macro appear in them. The GNU General Public License (GPL) does govern
+#   all other use of the material that constitutes the Autoconf Macro.
+#
+#   This special exception to the GPL applies to versions of the Autoconf
+#   Macro released by the Autoconf Archive. When you make and distribute a
+#   modified version of the Autoconf Macro, you may extend this special
+#   exception to the GPL to apply to your modified version as well.
+
+#serial 8
+
+AC_DEFUN([AX_PYTHON],
+[AC_MSG_CHECKING(for python build information)
+AC_MSG_RESULT([])
+for python in python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python; do
+AC_CHECK_PROGS(PYTHON_BIN, [$python])
+ax_python_bin=$PYTHON_BIN
+if test x$ax_python_bin != x; then
+   AC_CHECK_LIB($ax_python_bin, main, ax_python_lib=$ax_python_bin, ax_python_lib=no)
+   AC_CHECK_HEADER([$ax_python_bin/Python.h],
+   [[ax_python_header=`locate $ax_python_bin/Python.h | sed -e s,/Python.h,,`]],
+   ax_python_header=no)
+   if test $ax_python_lib != no; then
+     if test $ax_python_header != no; then
+       break;
+     fi
+   fi
+fi
+done
+if test x$ax_python_bin = x; then
+   ax_python_bin=no
+fi
+if test x$ax_python_header = x; then
+   ax_python_header=no
+fi
+if test x$ax_python_lib = x; then
+   ax_python_lib=no
+fi
+
+AC_MSG_RESULT([  results of the Python check:])
+AC_MSG_RESULT([    Binary:      $ax_python_bin])
+AC_MSG_RESULT([    Library:     $ax_python_lib])
+AC_MSG_RESULT([    Include Dir: $ax_python_header])
+
+if test x$ax_python_header != xno; then
+  PYTHON_INCLUDE_DIR=$ax_python_header
+  AC_SUBST(PYTHON_INCLUDE_DIR)
+fi
+if test x$ax_python_lib != xno; then
+  PYTHON_LIB=$ax_python_lib
+  AC_SUBST(PYTHON_LIB)
+fi
+])dnl
+
diff --git a/macros/mm-python.m4 b/macros/mm-python.m4
index 77dbce5..9265507 100644
--- a/macros/mm-python.m4
+++ b/macros/mm-python.m4
@@ -34,6 +34,9 @@ AS_IF([test "[$]?" -eq 0 && test "x$mm_val" != x], [$2], [$3])[]dnl
 ## The resulting configuration is stored in the PYTHON_CPPFLAGS and
 ## PYTHON_LIBS substitution variables.
 ##
+## Note: We use this in preference to AX_PYTHON() because it seems to behave better, preferring python and PYTHON.
+## For instance, it uses python2.5 if python is symlinked to python2.5, instead of preferring the newest one.
+##
 AC_DEFUN([MM_CHECK_MODULE_PYTHON],
 [dnl
 AC_REQUIRE([AM_PATH_PYTHON])[]dnl



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]