Commit cc1b6517 authored by Tiago Peixoto's avatar Tiago Peixoto

Improve and cleanup python detection

parent f6aa2b20
......@@ -63,5 +63,4 @@ dist-hook:
if test -f $$specfile; then \
cp -p $$specfile $(distdir); \
fi \
done
done
\ No newline at end of file
......@@ -34,6 +34,6 @@ autoconf || exit $?
if test -z "$AUTOGEN_SUBDIR_MODE"; then
$srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?
echo
echo
echo "Now type 'make' to compile $PROJECT."
fi
......@@ -172,16 +172,25 @@ dnl expat
AC_CHECK_LIB(expat,main)
dnl python
echo "================"
echo "Detecting python"
echo "================"
AM_PATH_PYTHON([2.6])
AC_SUBST(PYTHON_VERSION)
PYTHON_FULL_VERSION=[`${PYTHON} -c "import sys; print(sys.version.split()[0])"`]
AC_SUBST(PYTHON_FULL_VERSION)
[TEMP_CPPFLAGS="${CPPFLAGS}"]
AC_PYTHON_DEVEL([2.5])
[PYTHON="python${PYTHON_VERSION}"]
AX_PYTHON
AM_PATH_PYTHON([2.5])
AC_PYTHON_DEVEL([== '${PYTHON_FULL_VERSION}'])
[CPPFLAGS="${CPPFLAGS} ${PYTHON_CPPFLAGS}"]
[LDFLAGS="${LDFLAGS} ${PYTHON_LDFLAGS}"]
echo "==========================="
echo "Using python version: ${PYTHON_FULL_VERSION}"
echo "==========================="
dnl boost
AX_BOOST_BASE([1.38.0])
AX_BOOST_BASE([[1.38.0]])
AX_BOOST_PYTHON
if test "$BOOST_PYTHON_LIB" = ""; then
AC_MSG_ERROR([No usable boost::python found])
......@@ -212,9 +221,9 @@ AC_SUBST(CGAL_FLAGS)
dnl Checks for header files.
dnl numpy
AC_PYTHON_MODULE(numpy, fatal)
AX_PYTHON_MODULE(numpy, fatal)
dnl [NUMPY_DIR="${PYTHON_SITE_PKG}/numpy"]
[NUMPY_DIR=`$PYTHON -c "import os, numpy; print os.path.dirname(numpy.__file__)"`]
[NUMPY_DIR=`$PYTHON -c "import os, numpy; print(os.path.dirname(numpy.__file__))"`]
AC_ARG_WITH([numpy], [AS_HELP_STRING([--with-numpy=DIR],[directory where numpy is installed
[default="autodetected"] ])],
NUMPY_DIR=$withval)
......@@ -225,16 +234,16 @@ AC_CHECK_HEADER([${NUMPY_DIR}/arrayobject.h],
[#include "Python.h"])
dnl scipy
AC_PYTHON_MODULE(scipy, fatal)
AX_PYTHON_MODULE(scipy, fatal)
dnl [SCIPY_DIR="${PYTHON_SITE_PKG}/scipy"]
[SCIPY_DIR=`$PYTHON -c "import os, scipy; print os.path.dirname(scipy.__file__)"`]
[SCIPY_DIR=`$PYTHON -c "import os, scipy; print(os.path.dirname(scipy.__file__))"`]
AC_ARG_WITH([scipy], [AS_HELP_STRING([--with-scipy=DIR],[scipy install directory
[default=${PYTHON_SITE_PKG}/scipy] ])],
[SCIPY_DIR=$withval])
AC_CHECK_HEADER([${SCIPY_DIR}/weave/scxx/object.h],
[AC_DEFINE([HAVE_SCIPY], [1], [using scipy's weave])]
[CPPFLAGS="${CPPFLAGS} -I${SCIPY_DIR}"],
[AC_MSG_ERROR([Scipy weave/scxx header not found])])
[AC_MSG_WARN([Scipy weave/scxx header not found! (Ignore this if python 3 is being used.)])])
dnl expat
AC_CHECK_HEADER([expat.h],
......@@ -254,7 +263,7 @@ if test "$USING_CAIRO" = "yes"; then
[Cairomm is available]), [])
AC_SUBST(CAIROMM_CFLAGS)
AC_SUBST(CAIROMM_LIBS)
AC_PYTHON_MODULE(cairo)
AX_PYTHON_MODULE(cairo)
[OLD_CXXFLAGS="${CXXFLAGS}"]
[OLD_CPPFLAGS="${CPPFLAGS}"]
[CXXFLAGS="${CXXFLAGS} ${CAIROMM_CFLAGS}"]
......
......@@ -56,7 +56,7 @@
# special exception to the GPL to apply to your modified version as well.
AC_DEFUN([AX_BOOST_PYTHON],
[AC_REQUIRE([AX_PYTHON])dnl
[ dnl AC_REQUIRE([AX_PYTHON])dnl
AC_CACHE_CHECK(whether the Boost::Python library is available,
ac_cv_boost_python,
[AC_LANG_SAVE
......
# ===========================================================================
# http://autoconf-archive.cryp.to/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.5 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.
#
# LAST MODIFICATION
#
# 2008-04-12
#
# COPYLEFT
#
# 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 Macro 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.
AC_DEFUN([AX_PYTHON],
[AC_MSG_CHECKING(for python build information)
AC_MSG_RESULT([])
if test -z $PYTHON_VERSION
then
python_list="python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python"
else
python_list="python$PYTHON_VERSION"
fi
for python in $python_list; 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 | head -n 1 | 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
# ===========================================================================
# http://autoconf-archive.cryp.to/ac_python_devel.html
# http://www.gnu.org/software/autoconf-archive/ax_python_devel.html
# ===========================================================================
#
# SYNOPSIS
#
# AC_PYTHON_DEVEL([version])
# AX_PYTHON_DEVEL([version])
#
# DESCRIPTION
#
......@@ -31,18 +31,14 @@
# If you need to use this macro for an older Python version, please
# contact the authors. We're always open for feedback.
#
# LAST MODIFICATION
# LICENSE
#
# 2008-04-12
#
# COPYLEFT
#
# Copyright (c) 2008 Sebastian Huber <sebastian-huber@web.de>
# Copyright (c) 2008 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
# Copyright (c) 2008 Rafael Laboissiere <rafael@laboissiere.net>
# Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
# Copyright (c) 2008 Matteo Settenvini <matteo@member.fsf.org>
# Copyright (c) 2008 Horst Knorr <hk_classes@knoda.org>
# Copyright (c) 2009 Sebastian Huber <sebastian-huber@web.de>
# Copyright (c) 2009 Alan W. Irwin <irwin@beluga.phys.uvic.ca>
# Copyright (c) 2009 Rafael Laboissiere <rafael@laboissiere.net>
# Copyright (c) 2009 Andrew Collier <colliera@ukzn.ac.za>
# Copyright (c) 2009 Matteo Settenvini <matteo@member.fsf.org>
# Copyright (c) 2009 Horst Knorr <hk_classes@knoda.org>
#
# 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
......@@ -66,11 +62,14 @@
# 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 Macro 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.
# 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([AC_PYTHON_DEVEL],[
AU_ALIAS([AC_PYTHON_DEVEL], [AX_PYTHON_DEVEL])
AC_DEFUN([AX_PYTHON_DEVEL],[
#
# Allow the use of a (user set) custom python version
#
......@@ -89,9 +88,9 @@ AC_DEFUN([AC_PYTHON_DEVEL],[
# Check for a version of Python >= 2.1.0
#
AC_MSG_CHECKING([for a version of Python >= '2.1.0'])
ac_supports_python_ver=`$PYTHON -c "import sys, string; \
ver = string.split(sys.version)[[0]]; \
print ver >= '2.1.0'"`
ac_supports_python_ver=`$PYTHON -c "import sys; \
ver = sys.version.split ()[[0]]; \
print (ver >= '2.1.0')"`
if test "$ac_supports_python_ver" != "True"; then
if test -z "$PYTHON_NOVERSIONCHECK"; then
AC_MSG_RESULT([no])
......@@ -116,11 +115,11 @@ to something else than an empty string.
#
if test -n "$1"; then
AC_MSG_CHECKING([for a version of Python $1])
ac_supports_python_ver=`$PYTHON -c "import sys, string; \
ver = string.split(sys.version)[[0]]; \
print ver >= \"$1\""`
ac_supports_python_ver=`$PYTHON -c "import sys; \
ver = sys.version.split ()[[0]]; \
print (ver $1)"`
if test "$ac_supports_python_ver" = "True"; then
AC_MSG_RESULT([yes])
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
AC_MSG_ERROR([this package requires Python $1.
......@@ -153,9 +152,9 @@ $ac_distutils_result])
AC_MSG_CHECKING([for Python include path])
if test -z "$PYTHON_CPPFLAGS"; then
python_path=`$PYTHON -c "import distutils.sysconfig; \
print distutils.sysconfig.get_python_inc();"`
print (distutils.sysconfig.get_python_inc ());"`
if test -n "${python_path}"; then
python_path="-I$python_path"
python_path="-I$python_path"
fi
PYTHON_CPPFLAGS=$python_path
fi
......@@ -169,22 +168,82 @@ $ac_distutils_result])
if test -z "$PYTHON_LDFLAGS"; then
# (makes two attempts to ensure we've got a version number
# from the interpreter)
py_version=`$PYTHON -c "from distutils.sysconfig import *; \
from string import join; \
print join(get_config_vars('VERSION'))"`
if test "$py_version" == "[None]"; then
ac_python_version=`cat<<EOD | $PYTHON -
# join all versioning strings, on some systems
# major/minor numbers could be in different list elements
from distutils.sysconfig import *
ret = ''
for e in get_config_vars ('VERSION'):
if (e != None):
ret += e
print (ret)
EOD`
if test -z "$ac_python_version"; then
if test -n "$PYTHON_VERSION"; then
py_version=$PYTHON_VERSION
ac_python_version=$PYTHON_VERSION
else
py_version=`$PYTHON -c "import sys; \
print sys.version[[:3]]"`
ac_python_version=`$PYTHON -c "import sys; \
print (sys.version[[:3]])"`
fi
fi
PYTHON_LDFLAGS=`$PYTHON -c "from distutils.sysconfig import *; \
from string import join; \
print '-L' + get_python_lib(0,1), \
'-lpython';"`$py_version
# Make the versioning information available to the compiler
AC_DEFINE_UNQUOTED([HAVE_PYTHON], ["$ac_python_version"],
[If available, contains the Python version number currently in use.])
# First, the library directory:
ac_python_libdir=`cat<<EOD | $PYTHON -
# There should be only one
import distutils.sysconfig
for e in distutils.sysconfig.get_config_vars ('LIBDIR'):
if e != None:
print (e)
break
EOD`
# Before checking for libpythonX.Y, we need to know
# the extension the OS we're on uses for libraries
# (we take the first one, if there's more than one fix me!):
ac_python_soext=`$PYTHON -c \
"import distutils.sysconfig; \
print (distutils.sysconfig.get_config_vars('SO')[[0]])"`
# Now, for the library:
ac_python_soname=`$PYTHON -c \
"import distutils.sysconfig; \
print (distutils.sysconfig.get_config_vars('LDLIBRARY')[[0]])"`
# Strip away extension from the end to canonicalize its name:
ac_python_library=`echo "$ac_python_soname" | sed "s/${ac_python_soext}$//"`
# This small piece shamelessly adapted from PostgreSQL python macro;
# credits goes to momjian, I think. I'd like to put the right name
# in the credits, if someone can point me in the right direction... ?
#
if test -n "$ac_python_libdir" -a -n "$ac_python_library" \
-a x"$ac_python_library" != x"$ac_python_soname"
then
# use the official shared library
ac_python_library=`echo "$ac_python_library" | sed "s/^lib//"`
PYTHON_LDFLAGS="-L$ac_python_libdir -l$ac_python_library"
else
# old way: use libpython from python_configdir
ac_python_libdir=`$PYTHON -c \
"from distutils.sysconfig import get_python_lib as f; \
import os; \
print (os.path.join(f(plat_specific=1, standard_lib=1), 'config'));"`
PYTHON_LDFLAGS="-L$ac_python_libdir -lpython$ac_python_version"
fi
if test -z "PYTHON_LDFLAGS"; then
AC_MSG_ERROR([
Cannot determine location of your Python DSO. Please check it was installed with
dynamic libraries enabled, or try setting PYTHON_LDFLAGS by hand.
])
fi
fi
AC_MSG_RESULT([$PYTHON_LDFLAGS])
AC_SUBST([PYTHON_LDFLAGS])
......@@ -195,7 +254,7 @@ $ac_distutils_result])
AC_MSG_CHECKING([for Python site-packages path])
if test -z "$PYTHON_SITE_PKG"; then
PYTHON_SITE_PKG=`$PYTHON -c "import distutils.sysconfig; \
print distutils.sysconfig.get_python_lib(0,0);"`
print (distutils.sysconfig.get_python_lib(0,0));"`
fi
AC_MSG_RESULT([$PYTHON_SITE_PKG])
AC_SUBST([PYTHON_SITE_PKG])
......@@ -207,7 +266,7 @@ $ac_distutils_result])
if test -z "$PYTHON_EXTRA_LIBS"; then
PYTHON_EXTRA_LIBS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
print conf('LOCALMODLIBS'), conf('LIBS')"`
print (conf('LOCALMODLIBS') + ' ' + conf('LIBS'))"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LIBS])
AC_SUBST(PYTHON_EXTRA_LIBS)
......@@ -219,7 +278,7 @@ $ac_distutils_result])
if test -z "$PYTHON_EXTRA_LDFLAGS"; then
PYTHON_EXTRA_LDFLAGS=`$PYTHON -c "import distutils.sysconfig; \
conf = distutils.sysconfig.get_config_var; \
print conf('LINKFORSHARED')"`
print (conf('LINKFORSHARED'))"`
fi
AC_MSG_RESULT([$PYTHON_EXTRA_LDFLAGS])
AC_SUBST(PYTHON_EXTRA_LDFLAGS)
......@@ -228,20 +287,25 @@ $ac_distutils_result])
# final check to see if everything compiles alright
#
AC_MSG_CHECKING([consistency of all components of python development environment])
AC_LANG_PUSH([C])
# save current global flags
LIBS="$ac_save_LIBS $PYTHON_LDFLAGS"
ac_save_LIBS="$LIBS"
ac_save_CPPFLAGS="$CPPFLAGS"
LIBS="$ac_save_LIBS $PYTHON_LDFLAGS $PYTHON_EXTRA_LDFLAGS $PYTHON_EXTRA_LIBS"
CPPFLAGS="$ac_save_CPPFLAGS $PYTHON_CPPFLAGS"
AC_TRY_LINK([
#include <Python.h>
],[
Py_Initialize();
],[pythonexists=yes],[pythonexists=no])
AC_LANG_PUSH([C])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[#include <Python.h>]],
[[Py_Initialize();]])
],[pythonexists=yes],[pythonexists=no])
AC_LANG_POP([C])
# turn back to default flags
CPPFLAGS="$ac_save_CPPFLAGS"
LIBS="$ac_save_LIBS"
AC_MSG_RESULT([$pythonexists])
if test ! "$pythonexists" = "yes"; then
AC_MSG_ERROR([
if test ! "x$pythonexists" = "xyes"; then
AC_MSG_FAILURE([
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LDFLAGS environment variable.
......@@ -254,10 +318,6 @@ $ac_distutils_result])
])
PYTHON_VERSION=""
fi
AC_LANG_POP
# turn back to default flags
CPPFLAGS="$ac_save_CPPFLAGS"
LIBS="$ac_save_LIBS"
#
# all done!
......
# ===========================================================================
# http://autoconf-archive.cryp.to/ac_python_module.html
# http://www.gnu.org/software/autoconf-archive/ax_python_module.html
# ===========================================================================
#
# SYNOPSIS
#
# AC_PYTHON_MODULE(modname[, fatal])
# AX_PYTHON_MODULE(modname[, fatal])
#
# DESCRIPTION
#
......@@ -12,24 +12,22 @@
#
# If fatal is non-empty then absence of a module will trigger an error.
#
# LAST MODIFICATION
#
# 2008-04-12
#
# COPYLEFT
# LICENSE
#
# Copyright (c) 2008 Andrew Collier <colliera@ukzn.ac.za>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved.
# and this notice are preserved. This file is offered as-is, without any
# warranty.
#serial 5
AC_DEFUN([AC_PYTHON_MODULE],[
if test -z $PYTHON_BIN;
AU_ALIAS([AC_PYTHON_MODULE], [AX_PYTHON_MODULE])
AC_DEFUN([AX_PYTHON_MODULE],[
if test -z $PYTHON;
then
PYTHON="python"
else
PYTHON=$PYTHON_BIN
fi
PYTHON_NAME=`basename $PYTHON`
AC_MSG_CHECKING($PYTHON_NAME module: $1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment