From: =?utf-8?b?T25kxZllaiBTdXLDvQ==?= <ondrej@sury.org>
Date: Sun, 23 Feb 2020 16:19:20 +0100
Subject: Use pkg-config for PHP_SETUP_LIBXML

---
 acinclude.m4 | 74 +++++-------------------------------------------------------
 aclocal.m4   | 74 +++++-------------------------------------------------------
 2 files changed, 12 insertions(+), 136 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index 34d2b78..13b4bac 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -2538,79 +2538,17 @@ ifelse([$3],[],,[else $3])
 dnl
 dnl PHP_SETUP_LIBXML(shared-add [, action-found [, action-not-found]])
 dnl
-dnl Common setup macro for libxml
+dnl Common setup macro for libxml.
 dnl
 AC_DEFUN([PHP_SETUP_LIBXML], [
-  found_libxml=no
-
-  dnl First try to find xml2-config
-  AC_CACHE_CHECK([for xml2-config path], ac_cv_php_xml2_config_path,
-  [
-    for i in $PHP_LIBXML_DIR /usr/local /usr; do
-      if test -x "$i/bin/xml2-config"; then
-        ac_cv_php_xml2_config_path="$i/bin/xml2-config"
-        break
-      fi
-    done
-  ])
+  PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.7.6])
 
-  if test -x "$ac_cv_php_xml2_config_path"; then
-    XML2_CONFIG="$ac_cv_php_xml2_config_path"
-    libxml_full_version=`$XML2_CONFIG --version`
-    ac_IFS=$IFS
-    IFS="."
-    set $libxml_full_version
-    IFS=$ac_IFS
-    LIBXML_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
-    if test "$LIBXML_VERSION" -ge "2006011"; then
-      found_libxml=yes
-      LIBXML_LIBS=`$XML2_CONFIG --libs`
-      LIBXML_INCS=`$XML2_CONFIG --cflags`
-    else
-      AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
-    fi
-  fi
-
-  dnl If xml2-config fails, try pkg-config
-  if test "$found_libxml" = "no"; then
-    if test -z "$PKG_CONFIG"; then
-      AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
-    fi
-
-    dnl If pkg-config is found try using it
-    if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libxml-2.0; then
-      if $PKG_CONFIG --atleast-version=2.6.11 libxml-2.0; then
-        found_libxml=yes
-        LIBXML_LIBS=`$PKG_CONFIG --libs libxml-2.0`
-        LIBXML_INCS=`$PKG_CONFIG --cflags-only-I libxml-2.0`
-      else
-        AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
-      fi
-    fi
-  fi
+  PHP_EVAL_INCLINE($LIBXML_CFLAGS)
+  PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
 
-  if test "$found_libxml" = "yes"; then
-    PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
-    PHP_EVAL_INCLINE($LIBXML_INCS)
+  AC_DEFINE(HAVE_LIBXML, 1, [ ])
 
-    dnl Check that build works with given libs
-    AC_CACHE_CHECK(whether libxml build works, php_cv_libxml_build_works, [
-      PHP_TEST_BUILD(xmlInitParser,
-      [
-        php_cv_libxml_build_works=yes
-      ], [
-        AC_MSG_RESULT(no)
-        AC_MSG_ERROR([build test failed.  Please check the config.log for details.])
-      ], [
-        [$]$1
-      ])
-    ])
-    if test "$php_cv_libxml_build_works" = "yes"; then
-      AC_DEFINE(HAVE_LIBXML, 1, [ ])
-    fi
-    $2
-ifelse([$3],[],,[else $3])
-  fi
+  $2
 ])
 
 dnl -------------------------------------------------------------------------
diff --git a/aclocal.m4 b/aclocal.m4
index 17a24c4..7d0aff9 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -2538,79 +2538,17 @@ ifelse([$3],[],,[else $3])
 dnl
 dnl PHP_SETUP_LIBXML(shared-add [, action-found [, action-not-found]])
 dnl
-dnl Common setup macro for libxml
+dnl Common setup macro for libxml.
 dnl
 AC_DEFUN([PHP_SETUP_LIBXML], [
-  found_libxml=no
-
-  dnl First try to find xml2-config
-  AC_CACHE_CHECK([for xml2-config path], ac_cv_php_xml2_config_path,
-  [
-    for i in $PHP_LIBXML_DIR /usr/local /usr; do
-      if test -x "$i/bin/xml2-config"; then
-        ac_cv_php_xml2_config_path="$i/bin/xml2-config"
-        break
-      fi
-    done
-  ])
+  PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.7.6])
 
-  if test -x "$ac_cv_php_xml2_config_path"; then
-    XML2_CONFIG="$ac_cv_php_xml2_config_path"
-    libxml_full_version=`$XML2_CONFIG --version`
-    ac_IFS=$IFS
-    IFS="."
-    set $libxml_full_version
-    IFS=$ac_IFS
-    LIBXML_VERSION=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
-    if test "$LIBXML_VERSION" -ge "2006011"; then
-      found_libxml=yes
-      LIBXML_LIBS=`$XML2_CONFIG --libs`
-      LIBXML_INCS=`$XML2_CONFIG --cflags`
-    else
-      AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
-    fi
-  fi
-
-  dnl If xml2-config fails, try pkg-config
-  if test "$found_libxml" = "no"; then
-    if test -z "$PKG_CONFIG"; then
-      AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
-    fi
-
-    dnl If pkg-config is found try using it
-    if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists libxml-2.0; then
-      if $PKG_CONFIG --atleast-version=2.6.11 libxml-2.0; then
-        found_libxml=yes
-        LIBXML_LIBS=`$PKG_CONFIG --libs libxml-2.0`
-        LIBXML_INCS=`$PKG_CONFIG --cflags-only-I libxml-2.0`
-      else
-        AC_MSG_ERROR([libxml2 version 2.6.11 or greater required.])
-      fi
-    fi
-  fi
+  PHP_EVAL_INCLINE($LIBXML_CFLAGS)
+  PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
 
-  if test "$found_libxml" = "yes"; then
-    PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
-    PHP_EVAL_INCLINE($LIBXML_INCS)
+  AC_DEFINE(HAVE_LIBXML, 1, [ ])
 
-    dnl Check that build works with given libs
-    AC_CACHE_CHECK(whether libxml build works, php_cv_libxml_build_works, [
-      PHP_TEST_BUILD(xmlInitParser,
-      [
-        php_cv_libxml_build_works=yes
-      ], [
-        AC_MSG_RESULT(no)
-        AC_MSG_ERROR([build test failed.  Please check the config.log for details.])
-      ], [
-        [$]$1
-      ])
-    ])
-    if test "$php_cv_libxml_build_works" = "yes"; then
-      AC_DEFINE(HAVE_LIBXML, 1, [ ])
-    fi
-    $2
-ifelse([$3],[],,[else $3])
-  fi
+  $2
 ])
 
 dnl -------------------------------------------------------------------------
