Use AM_PATH_PYTHON and python-config to detect Python configuration

Using AM_PATH_PYTHON solves the site-packages directory problem. At least
in Ubuntu with Python 2.6 and later site-packages is renamed to dist-packages
and site-packages is not part of sys.path anymore. So installing the libvirt
Python bindings to site-packages renders them unusable, because they can be
imported from there without manually including site-packages into sys.path.

AM_PATH_PYTHON detects the correct site-packages/dist-packages directory.

python-config --includes gives the correct include path for the Python header
files. The old probing code stays there as fallback mechanism.

* configure.in: use AM_PATH_PYTHON and python-config
* python/Makefile.am: remove -I because PYTHON_INCLUDES contains it now
This commit is contained in:
Matthias Bolte 2009-12-06 16:05:33 +01:00
parent 10616d7a1e
commit 66137344fe
2 changed files with 54 additions and 58 deletions

View File

@ -1464,75 +1464,71 @@ AC_ARG_WITH([python],
PYTHON_VERSION= PYTHON_VERSION=
PYTHON_INCLUDES= PYTHON_INCLUDES=
PYTHON_SITE_PACKAGES=
PYTHON_TESTS=
pythondir= pythondir=
if test "$with_python" != "no" ; then if test "$with_python" != "no" ; then
if test -x "$with_python/bin/python" if test -x "$with_python/bin/python"
then then
echo Found python in $with_python/bin/python AC_MSG_NOTICE(Found python in $with_python/bin/python)
PYTHON="$with_python/bin/python" PYTHON="$with_python/bin/python"
with_python=yes
else else
if test -x "$with_python" if test -x "$with_python"
then then
echo Found python in $with_python AC_MSG_NOTICE(Found python in $with_python)
PYTHON="$with_python" PYTHON="$with_python"
else with_python=yes
if test -x "$PYTHON" else
then if test -x "$PYTHON"
echo Found python in environment PYTHON=$PYTHON then
with_python=`$PYTHON -c "import sys; print sys.exec_prefix"` AC_MSG_NOTICE(Found python in environment PYTHON=$PYTHON)
else with_python=yes
AC_PATH_PROG([PYTHON], [python python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 python1.6 python1.5]) fi
fi fi
fi
fi fi
if test "$PYTHON" != ""
then if test "$with_python" == "yes" ; then
PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"` AM_PATH_PYTHON(,, [:])
echo Found Python version $PYTHON_VERSION
fi if test "$PYTHON" != : ; then
if test "$PYTHON_VERSION" != "" PYTHON_CONFIG="$PYTHON-config"
then
if test -r $with_python/include/python$PYTHON_VERSION/Python.h -a \ if test -x "$PYTHON_CONFIG"
-d $with_python/lib/python$PYTHON_VERSION/site-packages then
then PYTHON_INCLUDES=`$PYTHON_CONFIG --includes`
PYTHON_INCLUDES=$with_python/include/python$PYTHON_VERSION else
PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages if test -r $PYTHON_EXEC_PREFIX/include/python$PYTHON_VERSION/Python.h
else then
if test -r $prefix/include/python$PYTHON_VERSION/Python.h PYTHON_INCLUDES=-I$PYTHON_EXEC_PREFIX/include/python$PYTHON_VERSION
then else
PYTHON_INCLUDES=$prefix/include/python$PYTHON_VERSION if test -r $prefix/include/python$PYTHON_VERSION/Python.h
PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages then
else PYTHON_INCLUDES=-I$prefix/include/python$PYTHON_VERSION
if test -r /usr/include/python$PYTHON_VERSION/Python.h else
then if test -r /usr/include/python$PYTHON_VERSION/Python.h
PYTHON_INCLUDES=/usr/include/python$PYTHON_VERSION then
PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages PYTHON_INCLUDES=-I/usr/include/python$PYTHON_VERSION
else else
echo could not find python$PYTHON_VERSION/Python.h AC_MSG_NOTICE([Could not find python$PYTHON_VERSION/Python.h, disabling bindings])
fi with_python=no
fi fi
if test ! -d "$PYTHON_SITE_PACKAGES" fi
then fi
PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib()"` fi
fi else
fi AC_MSG_NOTICE([Could not find python interpreter, disabling bindings])
fi with_python=no
if test "$with_python" != "yes" fi
then
pythondir='$(PYTHON_SITE_PACKAGES)'
else else
pythondir='$(libdir)/python$(PYTHON_VERSION)/site-packages' AC_MSG_NOTICE([Could not find python in $with_python, disabling bindings])
with_python=no
fi fi
else
PYTHON=
fi fi
AM_CONDITIONAL([WITH_PYTHON], test "$PYTHON_INCLUDES" != "") AM_CONDITIONAL([WITH_PYTHON], [test "$with_python" = "yes"])
AC_SUBST([pythondir])
AC_SUBST([PYTHON_VERSION]) AC_SUBST([PYTHON_VERSION])
AC_SUBST([PYTHON_INCLUDES]) AC_SUBST([PYTHON_INCLUDES])
AC_SUBST([PYTHON_SITE_PACKAGES]) AC_SUBST([pythondir])
AC_MSG_CHECKING([whether this host is running a Xen kernel]) AC_MSG_CHECKING([whether this host is running a Xen kernel])
RUNNING_XEN= RUNNING_XEN=

View File

@ -4,7 +4,7 @@ SUBDIRS= . tests
INCLUDES = \ INCLUDES = \
$(WARN_CFLAGS) \ $(WARN_CFLAGS) \
-I$(PYTHON_INCLUDES) \ $(PYTHON_INCLUDES) \
-I$(top_srcdir)/include \ -I$(top_srcdir)/include \
-I$(top_builddir)/include \ -I$(top_builddir)/include \
-I$(top_builddir)/$(subdir) -I$(top_builddir)/$(subdir)