[libxml2] Use AM_PATH_PYTHON/PKG_CHECK_MODULES for python bindings



commit d9335077dd61ec6d518fb331f2f8778837e686de
Author: David Seifert <soap gentoo org>
Date:   Tue Mar 29 13:37:16 2022 +0200

    Use AM_PATH_PYTHON/PKG_CHECK_MODULES for python bindings
    
    * `AM_PATH_PYTHON` is a much more common idiom for building
      and installing python modules than writing your own.
    * It also makes cross-compiling the python bindings possible.
      Previously the `PYTHON_CFLAGS`/`PYTHON_LIBS` would have been
      based on the `--build` python and not the `--host` python.
      By using `pkg-config`, we can always redirect the python-X.Y.pc.
    
    Bug: https://bugs.gentoo.org/582130

 .gitignore         |   1 +
 .gitlab-ci.yml     |   4 +-
 Makefile.am        |  10 +++--
 configure.ac       | 114 ++++-------------------------------------------------
 python/Makefile.am |  16 ++++----
 5 files changed, 26 insertions(+), 119 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ad751e89..ce51efe1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,6 +70,7 @@ log
 missing
 missing.lst
 m4
+py-compile
 python/.deps
 python/.libs
 python/Makefile
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 308dda23..e7279c69 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -30,11 +30,9 @@ gcc:
 
 gcc:python3:
   extends: .test
-  only:
-    - schedules
   variables:
-    CONFIG: "--with-python=/usr/bin/python3"
     CFLAGS: "-O2"
+    PYTHON: "/usr/bin/python3"
 
 clang:asan:
   extends: .test
diff --git a/Makefile.am b/Makefile.am
index 559fa652..5d06aaaf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,10 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = include . doc example fuzz xstc $(PYTHON_SUBDIR)
+SUBDIRS = include . doc example fuzz xstc
+if WITH_PYTHON
+SUBDIRS += python
+endif
 
 DIST_SUBDIRS = include . doc example fuzz python xstc
 
@@ -201,9 +204,10 @@ runtests: runtest$(EXEEXT) testrecurse$(EXEEXT) testapi$(EXEEXT) \
            $(CHECKER) ./testchar$(EXEEXT) && \
            $(CHECKER) ./testdict$(EXEEXT) && \
            $(CHECKER) ./runxmlconf$(EXEEXT)
-       @(if [ "$(PYTHON_SUBDIR)" != "" ] ; then cd python ; \
-           $(MAKE) tests ; fi)
        @cd fuzz; $(MAKE) tests
+if WITH_PYTHON
+       @cd python && $(MAKE) tests
+endif
 
 check: all runtests
 
diff --git a/configure.ac b/configure.ac
index 84df2c77..d91d4f74 100644
--- a/configure.ac
+++ b/configure.ac
@@ -135,10 +135,7 @@ AC_ARG_WITH(pattern,
 AC_ARG_WITH(push,
 [  --with-push             add the PUSH parser interfaces (on)])
 AC_ARG_WITH(python,
-[  --with-python[[=DIR]]     build Python bindings if found])
-AC_ARG_WITH(python_install_dir,
-[  --with-python-install-dir=DIR
-                          install Python bindings in DIR])
+[  --with-python           build Python bindings (on)])
 AC_ARG_WITH(reader,
 [  --with-reader           add the xmlReader parsing interface (on)])
 AC_ARG_WITH(readline,
@@ -771,103 +768,12 @@ dnl
 dnl check for python
 dnl
 
-PYTHON_VERSION=
-PYTHON_INCLUDES=
-PYTHON_SITE_PACKAGES=
 PYTHON_TESTS=
-pythondir=
-if test "$with_python" != "no" ; then
-    if test -x "$with_python/bin/python"
-    then
-        echo Found python in $with_python/bin/python
-        PYTHON="$with_python/bin/python"
-    else
-        if test -x "$with_python/python.exe"
-        then
-            echo Found python in $with_python/python.exe
-            PYTHON="$with_python/python.exe"
-        else
-            if test -x "$with_python"
-            then
-                echo Found python in $with_python
-                PYTHON="$with_python"
-            else
-                if test -x "$PYTHON"
-                then
-                    echo Found python in environment PYTHON=$PYTHON
-                    with_python=`$PYTHON -c "import sys; print(sys.exec_prefix)"`
-                else
-                    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
-    if test "$PYTHON" != ""
-    then
-        PYTHON_VERSION=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_version())"`
-       PYTHON_INCLUDES=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_inc())"`
-# does not work as it produce a /usr/lib/python path instead of/usr/lib64/python
-#
-#      PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib())"`
-       echo Found Python version $PYTHON_VERSION
-    fi
-    if test "$PYTHON_VERSION" != "" -a "$PYTHON_INCLUDES" = ""
-    then
-       if test -r $with_python/include/python$PYTHON_VERSION/Python.h
-       then
-           PYTHON_INCLUDES=$with_python/include/python$PYTHON_VERSION
-       else
-           if test -r $prefix/include/python$PYTHON_VERSION/Python.h
-           then
-               PYTHON_INCLUDES=$prefix/include/python$PYTHON_VERSION
-           else
-               if test -r /usr/include/python$PYTHON_VERSION/Python.h
-               then
-                   PYTHON_INCLUDES=/usr/include/python$PYTHON_VERSION
-               else
-                   if test -r $with_python/include/Python.h
-                   then
-                       PYTHON_INCLUDES=$with_python/include
-                   else
-                       echo could not find python$PYTHON_VERSION/Python.h or $with_python/include/Python.h
-                   fi
-               fi
-           fi
-       fi
-    fi
-    if test "$with_python_install_dir" != ""
-    then
-       PYTHON_SITE_PACKAGES="$with_python_install_dir"
-    fi
-    if test "$PYTHON_VERSION" != "" -a "$PYTHON_SITE_PACKAGES" = ""
-    then
-       if test -d $libdir/python$PYTHON_VERSION/site-packages
-       then
-           PYTHON_SITE_PACKAGES=$libdir/python$PYTHON_VERSION/site-packages
-       else
-           if test -d $with_python/lib/site-packages
-           then
-               PYTHON_SITE_PACKAGES=$with_python/lib/site-packages
-           else
-               PYTHON_SITE_PACKAGES=$($PYTHON -c 'from distutils import sysconfig; 
print(sysconfig.get_python_lib(True,False,"${exec_prefix}"))')
-           fi
-       fi
-    fi
-    pythondir='$(PYTHON_SITE_PACKAGES)'
-    PYTHON_LIBS=`python$PYTHON_VERSION-config --ldflags`
-else
-    PYTHON=
-fi
-AM_CONDITIONAL(WITH_PYTHON, test "$PYTHON_INCLUDES" != "")
-if test "$PYTHON_INCLUDES" != ""
-then
-    PYTHON_SUBDIR=python
-else
-    PYTHON_SUBDIR=
-fi
-AC_SUBST(pythondir)
-AC_SUBST(PYTHON_SUBDIR)
-AC_SUBST(PYTHON_LIBS)
+AS_IF([test "x$with_python" != "xno"], [
+    AM_PATH_PYTHON
+    PKG_CHECK_MODULES([PYTHON], [python-${PYTHON_VERSION}])
+])
+AM_CONDITIONAL([WITH_PYTHON], [test "x$with_python" != "xno"])
 
 dnl check for dso support
 WITH_MODULES=0
@@ -1448,9 +1354,9 @@ else
     echo "Enabled Schemas/Relax-NG support"
     WITH_SCHEMAS=1
     TEST_SCHEMAS="Schemastests Relaxtests"
-    if test "$PYTHON_INCLUDES" != "" ; then
+    AS_IF([test "x$with_python" != "xno"], [
         PYTHON_TESTS="$PYTHON_TESTS RelaxNGPythonTests SchemasPythonTests"
-    fi
+    ])
     with_regexps=yes
 fi
 AC_SUBST(WITH_SCHEMAS)
@@ -1578,10 +1484,6 @@ AC_SUBST(ICONV_LIBS)
 AC_SUBST(ICU_LIBS)
 AC_SUBST(XML_INCLUDEDIR)
 AC_SUBST(HTML_DIR)
-AC_SUBST(PYTHON)
-AC_SUBST(PYTHON_VERSION)
-AC_SUBST(PYTHON_INCLUDES)
-AC_SUBST(PYTHON_SITE_PACKAGES)
 
 AC_SUBST(M_LIBS)
 AC_SUBST(RDL_LIBS)
diff --git a/python/Makefile.am b/python/Makefile.am
index 726e6936..bf8cabba 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -19,14 +19,13 @@ if WITH_PYTHON
 AM_CPPFLAGS = \
        -I$(top_builddir)/include \
        -I$(top_srcdir)/include \
-       -I$(PYTHON_INCLUDES)
+       $(PYTHON_CFLAGS)
 
-python_LTLIBRARIES = libxml2mod.la
+pyexec_LTLIBRARIES = libxml2mod.la
 
 libxml2mod_la_SOURCES = libxml.c libxml_wrap.h libxml2-py.h libxml2-py.c types.c
-libxml2mod_la_LDFLAGS = $(CYGWIN_EXTRA_LDFLAGS) $(WIN32_EXTRA_LDFLAGS) -module -avoid-version \
-        $(top_builddir)/libxml2.la
-libxml2mod_la_LIBADD = $(CYGWIN_EXTRA_PYTHON_LIBADD) $(WIN32_EXTRA_PYTHON_LIBADD) $(PYTHON_LIBS)
+libxml2mod_la_LDFLAGS = $(CYGWIN_EXTRA_LDFLAGS) $(WIN32_EXTRA_LDFLAGS) -module -avoid-version
+libxml2mod_la_LIBADD = $(top_builddir)/libxml2.la $(CYGWIN_EXTRA_PYTHON_LIBADD) $(WIN32_EXTRA_PYTHON_LIBADD) 
$(PYTHON_LIBS)
 
 BUILT_SOURCES = libxml2-export.c libxml2-py.h libxml2-py.c
 
@@ -36,10 +35,10 @@ libxml.$(OBJEXT): libxml2-export.c
 libxml2.py: $(srcdir)/libxml.py libxml2class.py
        cat $(srcdir)/libxml.py `test -f libxml2class.py || echo $(srcdir)/`libxml2class.py > $@
 
-dist_python_DATA = \
+python_PYTHON = \
        drv_libxml2.py \
        libxml2.py
-       
+
 CLEANFILES = *.pyc
 
 MAINTAINERCLEANFILES = libxml2.py libxml2class.*
@@ -47,6 +46,9 @@ MAINTAINERCLEANFILES = libxml2.py libxml2class.*
 API_DESC = $(top_srcdir)/doc/libxml2-api.xml $(srcdir)/libxml2-python-api.xml
 GENERATED = libxml2class.py libxml2class.txt $(BUILT_SOURCES)
 
+# Generated sources
+all-local: drv_libxml2.py libxml2.py
+
 $(GENERATED): $(srcdir)/generator.py $(API_DESC)
        $(PYTHON) $(srcdir)/generator.py $(srcdir)
 endif


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