[PATCH] Use pkg-config for Python
At least libpython2.7-dev and libpython3.3-dev on current Debian/unstable ship with pkg-config files. As with the pkg-config check for Lua, we check for versioned and an unversioned .pc files. --- configure.ac | 35 ++++++++++++++++++++--------------- python/Makefile.am | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index c809741..0aa1716 100644 --- a/configure.ac +++ b/configure.ac @@ -1106,7 +1106,6 @@ AM_CONDITIONAL([HAVE_PERL], dnl Check for Python (optional, for Python bindings). PYTHON_PREFIX= PYTHON_VERSION= -PYTHON_INCLUDEDIR= PYTHON_INSTALLDIR= AC_ARG_ENABLE([python], @@ -1117,23 +1116,30 @@ AS_IF([test "x$enable_python" != "xno"],[ AC_CHECK_PROG([PYTHON],[python],[python],[no]) if test "x$PYTHON" != "xno"; then - AC_MSG_CHECKING([Python prefix]) - PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"` - AC_MSG_RESULT([$PYTHON_PREFIX]) - AC_MSG_CHECKING([Python version]) PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"` PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"` PYTHON_VERSION="$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR" AC_MSG_RESULT([$PYTHON_VERSION]) - - AC_MSG_CHECKING([for Python include path]) - if test -z "$PYTHON_INCLUDEDIR"; then - python_path=`$PYTHON -c "import distutils.sysconfig; \ - print (distutils.sysconfig.get_python_inc ());"` - PYTHON_INCLUDEDIR=$python_path - fi - AC_MSG_RESULT([$PYTHON_INCLUDEDIR]) + # Debian: python-2.7.pc, python-3.2.pc + PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + PKG_CHECK_MODULES([PYTHON], [python],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + AC_MSG_WARN([python $PYTHON_VERSION not found]) + ]) + ]) + AC_MSG_CHECKING([Python prefix]) + PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"` + AC_MSG_RESULT([$PYTHON_PREFIX]) AC_ARG_WITH([python-installdir], [AS_HELP_STRING([--with-python-installdir], @@ -1171,11 +1177,10 @@ AS_IF([test "x$enable_python" != "xno"],[ AC_SUBST(PYTHON_PREFIX) AC_SUBST(PYTHON_VERSION) - AC_SUBST(PYTHON_INCLUDEDIR) AC_SUBST(PYTHON_INSTALLDIR) ]) AM_CONDITIONAL([HAVE_PYTHON], - [test "x$PYTHON" != "xno" && test "x$PYTHON_INCLUDEDIR" != "x" && test "x$PYTHON_INSTALLDIR" != "x"]) + [test "x$PYTHON" != "xno" && test "x$PYTHON_LIBS" != "x" ]) dnl Check for Ruby and rake (optional, for Ruby bindings). AC_ARG_ENABLE([ruby], diff --git a/python/Makefile.am b/python/Makefile.am index e514a76..ecc25d5 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -43,7 +43,7 @@ libguestfsmod_la_SOURCES = guestfs-py.c guestfs-py.h guestfs-py-byhand.c libguestfsmod_la_CPPFLAGS = \ -DGUESTFS_PRIVATE=1 \ - -I$(PYTHON_INCLUDEDIR) \ + $(PYTHON_CFLAGS) \ -I$(top_srcdir)/src -I$(top_builddir)/src libguestfsmod_la_CFLAGS = \ -- 1.7.10.4
On Thu, May 16, 2013 at 10:13:50PM +0200, Hilko Bengen wrote:
At least libpython2.7-dev and libpython3.3-dev on current Debian/unstable ship with pkg-config files. As with the pkg-config check for Lua, we check for versioned and an unversioned .pc files.
--- configure.ac | 35 ++++++++++++++++++++--------------- python/Makefile.am | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/configure.ac b/configure.ac index c809741..0aa1716 100644 --- a/configure.ac +++ b/configure.ac @@ -1106,7 +1106,6 @@ AM_CONDITIONAL([HAVE_PERL], dnl Check for Python (optional, for Python bindings). PYTHON_PREFIX= PYTHON_VERSION= -PYTHON_INCLUDEDIR= PYTHON_INSTALLDIR=
AC_ARG_ENABLE([python], @@ -1117,23 +1116,30 @@ AS_IF([test "x$enable_python" != "xno"],[ AC_CHECK_PROG([PYTHON],[python],[python],[no])
if test "x$PYTHON" != "xno"; then - AC_MSG_CHECKING([Python prefix]) - PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"` - AC_MSG_RESULT([$PYTHON_PREFIX]) - AC_MSG_CHECKING([Python version]) PYTHON_VERSION_MAJOR=`$PYTHON -c "import sys; print (sys.version_info@<:@0@:>@)"` PYTHON_VERSION_MINOR=`$PYTHON -c "import sys; print (sys.version_info@<:@1@:>@)"` PYTHON_VERSION="$PYTHON_VERSION_MAJOR.$PYTHON_VERSION_MINOR" AC_MSG_RESULT([$PYTHON_VERSION]) - - AC_MSG_CHECKING([for Python include path]) - if test -z "$PYTHON_INCLUDEDIR"; then - python_path=`$PYTHON -c "import distutils.sysconfig; \ - print (distutils.sysconfig.get_python_inc ());"` - PYTHON_INCLUDEDIR=$python_path - fi - AC_MSG_RESULT([$PYTHON_INCLUDEDIR]) + # Debian: python-2.7.pc, python-3.2.pc + PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + PKG_CHECK_MODULES([PYTHON], [python],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + AC_MSG_WARN([python $PYTHON_VERSION not found]) + ]) + ]) + AC_MSG_CHECKING([Python prefix]) + PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"` + AC_MSG_RESULT([$PYTHON_PREFIX])
AC_ARG_WITH([python-installdir], [AS_HELP_STRING([--with-python-installdir], @@ -1171,11 +1177,10 @@ AS_IF([test "x$enable_python" != "xno"],[
AC_SUBST(PYTHON_PREFIX) AC_SUBST(PYTHON_VERSION) - AC_SUBST(PYTHON_INCLUDEDIR) AC_SUBST(PYTHON_INSTALLDIR) ]) AM_CONDITIONAL([HAVE_PYTHON], - [test "x$PYTHON" != "xno" && test "x$PYTHON_INCLUDEDIR" != "x" && test "x$PYTHON_INSTALLDIR" != "x"]) + [test "x$PYTHON" != "xno" && test "x$PYTHON_LIBS" != "x" ])
dnl Check for Ruby and rake (optional, for Ruby bindings). AC_ARG_ENABLE([ruby], diff --git a/python/Makefile.am b/python/Makefile.am index e514a76..ecc25d5 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -43,7 +43,7 @@ libguestfsmod_la_SOURCES = guestfs-py.c guestfs-py.h guestfs-py-byhand.c
libguestfsmod_la_CPPFLAGS = \ -DGUESTFS_PRIVATE=1 \ - -I$(PYTHON_INCLUDEDIR) \ + $(PYTHON_CFLAGS) \ -I$(top_srcdir)/src -I$(top_builddir)/src
libguestfsmod_la_CFLAGS = \ -- 1.7.10.4
I tested this on Fedora with both Python 3.3 and Python 2.7 and it works for both. Therefore: ACK. I just pushed this. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
On Thu, May 16, Hilko Bengen wrote:
AC_MSG_RESULT([$PYTHON_VERSION]) - - AC_MSG_CHECKING([for Python include path]) - if test -z "$PYTHON_INCLUDEDIR"; then - python_path=`$PYTHON -c "import distutils.sysconfig; \ - print (distutils.sysconfig.get_python_inc ());"` - PYTHON_INCLUDEDIR=$python_path - fi - AC_MSG_RESULT([$PYTHON_INCLUDEDIR]) + # Debian: python-2.7.pc, python-3.2.pc + PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + PKG_CHECK_MODULES([PYTHON], [python],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + AC_MSG_WARN([python $PYTHON_VERSION not found]) + ]) + ]) + AC_MSG_CHECKING([Python prefix]) + PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"` + AC_MSG_RESULT([$PYTHON_PREFIX])
AC_ARG_WITH([python-installdir], [AS_HELP_STRING([--with-python-installdir], @@ -1171,11 +1177,10 @@ AS_IF([test "x$enable_python" != "xno"],[
AC_SUBST(PYTHON_PREFIX) AC_SUBST(PYTHON_VERSION) - AC_SUBST(PYTHON_INCLUDEDIR) AC_SUBST(PYTHON_INSTALLDIR) ]) AM_CONDITIONAL([HAVE_PYTHON], - [test "x$PYTHON" != "xno" && test "x$PYTHON_INCLUDEDIR" != "x" && test "x$PYTHON_INSTALLDIR" != "x"]) + [test "x$PYTHON" != "xno" && test "x$PYTHON_LIBS" != "x" ])
If pkg-config check fails, PYTHON_LIBS remains empty (at least for me) and as a result python gets disabled. Without this change, PYTHON_INCLUDEDIR was retreived directly from python itself. For me current 1.20 branch fails to build python in SLE11. Olaf
On Sun, Jun 16, 2013 at 02:55:29PM +0200, Olaf Hering wrote:
On Thu, May 16, Hilko Bengen wrote:
AC_MSG_RESULT([$PYTHON_VERSION]) - - AC_MSG_CHECKING([for Python include path]) - if test -z "$PYTHON_INCLUDEDIR"; then - python_path=`$PYTHON -c "import distutils.sysconfig; \ - print (distutils.sysconfig.get_python_inc ());"` - PYTHON_INCLUDEDIR=$python_path - fi - AC_MSG_RESULT([$PYTHON_INCLUDEDIR]) + # Debian: python-2.7.pc, python-3.2.pc + PKG_CHECK_MODULES([PYTHON], [python-"$PYTHON_VERSION"],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + PKG_CHECK_MODULES([PYTHON], [python],[ + AC_SUBST([PYTHON_CFLAGS]) + AC_SUBST([PYTHON_LIBS]) + AC_SUBST([PYTHON_VERSION]) + AC_DEFINE([HAVE_PYTHON],[1],[Python library found at compile time]) + ],[ + AC_MSG_WARN([python $PYTHON_VERSION not found]) + ]) + ]) + AC_MSG_CHECKING([Python prefix]) + PYTHON_PREFIX=`$PYTHON -c "import sys; print (sys.prefix)"` + AC_MSG_RESULT([$PYTHON_PREFIX])
AC_ARG_WITH([python-installdir], [AS_HELP_STRING([--with-python-installdir], @@ -1171,11 +1177,10 @@ AS_IF([test "x$enable_python" != "xno"],[
AC_SUBST(PYTHON_PREFIX) AC_SUBST(PYTHON_VERSION) - AC_SUBST(PYTHON_INCLUDEDIR) AC_SUBST(PYTHON_INSTALLDIR) ]) AM_CONDITIONAL([HAVE_PYTHON], - [test "x$PYTHON" != "xno" && test "x$PYTHON_INCLUDEDIR" != "x" && test "x$PYTHON_INSTALLDIR" != "x"]) + [test "x$PYTHON" != "xno" && test "x$PYTHON_LIBS" != "x" ])
If pkg-config check fails, PYTHON_LIBS remains empty (at least for me) and as a result python gets disabled. Without this change, PYTHON_INCLUDEDIR was retreived directly from python itself.
For me current 1.20 branch fails to build python in SLE11.
Does SuSE's python have a pkg-config file? RHEL 5 didn't have one, but it was added in RHEL 6. So for the branch of libguestfs we use on RHEL 5 ('oldlinux'[1]) I have reverted this patch[2]. Rich. [1] https://github.com/libguestfs/libguestfs/tree/oldlinux [2] https://github.com/libguestfs/libguestfs/commit/5f7acbb95e055efa840d2108e207... -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
On Mon, Jun 17, Richard W.M. Jones wrote:
On Sun, Jun 16, 2013 at 02:55:29PM +0200, Olaf Hering wrote:
For me current 1.20 branch fails to build python in SLE11.
Does SuSE's python have a pkg-config file?
SLE11 does not have it, but openSUSE 11.4+ has it. I think the previous code should be restored as a fallback when the .pc files are missing. Olaf
On Mon, Jun 17, 2013 at 10:08:46AM +0200, Olaf Hering wrote:
On Mon, Jun 17, Richard W.M. Jones wrote:
On Sun, Jun 16, 2013 at 02:55:29PM +0200, Olaf Hering wrote:
For me current 1.20 branch fails to build python in SLE11.
Does SuSE's python have a pkg-config file?
SLE11 does not have it, but openSUSE 11.4+ has it. I think the previous code should be restored as a fallback when the .pc files are missing.
TBH it adds a lot of complexity to an already complex and fragile configure script, which would hardly ever be tested. Can't either SLE11 be fixed, or else the revert patch carried by SLE11 (the latter is what we are doing for RHEL 5)? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
On Mon, Jun 17, Richard W.M. Jones wrote:
On Mon, Jun 17, 2013 at 10:08:46AM +0200, Olaf Hering wrote:
On Mon, Jun 17, Richard W.M. Jones wrote:
On Sun, Jun 16, 2013 at 02:55:29PM +0200, Olaf Hering wrote:
For me current 1.20 branch fails to build python in SLE11.
Does SuSE's python have a pkg-config file?
SLE11 does not have it, but openSUSE 11.4+ has it. I think the previous code should be restored as a fallback when the .pc files are missing.
TBH it adds a lot of complexity to an already complex and fragile configure script, which would hardly ever be tested.
Can't either SLE11 be fixed, or else the revert patch carried by SLE11 (the latter is what we are doing for RHEL 5)?
I have added this to the spec file to fix my build failure: +if ! pkg-config python +then + export PYTHON_LIBS="-lpython`python -c 'import distutils.sysconfig; print (distutils.sysconfig.get_python_version ());'`" + export PYTHON_CFLAGS="-I`python -c 'import distutils.sysconfig; print (distutils.sysconfig.get_python_inc ());'`" +fi Olaf
participants (3)
-
Hilko Bengen -
Olaf Hering -
Richard W.M. Jones