]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use pkg-config for --with-libxml2=auto/yes
authorOndřej Surý <ondrej@sury.org>
Tue, 25 Feb 2020 14:22:54 +0000 (15:22 +0100)
committerOndřej Surý <ondrej@isc.org>
Mon, 2 Mar 2020 14:07:18 +0000 (15:07 +0100)
The downstream distributors of BIND 9 (Debian in this case) are in
process of removing xml2-config command from the libxml2-dev package
(see Debian Bug #949056 for details).  The removal of the script will
make BIND 9 to fail to build from the source when --with-libxml2=yes is
specified or not link with libxml2 when --with-libxml2=auto is specified
and then fail ABI changes (Debian Bug #949056).

When --with-libxml2=<path>, the script checks for <path>/bin/xml2-config
and uses the specified path to link with libxml2. This has been kept to
retain backwards compatibility with systems that does not ship
pkg-config.

aclocal.m4
configure
configure.ac

index a39635ed780f36d4897750002ceff91c09f6400d..ddddd296b5d5db302f52bcf609223a8bebef0f59 100644 (file)
@@ -100,7 +100,7 @@ dnl Check to see whether a particular set of modules exists. Similar to
 dnl PKG_CHECK_MODULES(), but does not set variables or print errors.
 dnl
 dnl Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG])
-dnl only at the first occurrence in configure.ac, so if the first place
+dnl only at the first occurence in configure.ac, so if the first place
 dnl it's called might be skipped (such as if it is within an "if", you
 dnl have to call PKG_CHECK_EXISTS manually
 AC_DEFUN([PKG_CHECK_EXISTS],
index 920d3bfb635d047b7c8922bf51617344df4929fd..83ffa8a649629669192f9b87c2e1bac024d65034 100755 (executable)
--- a/configure
+++ b/configure
@@ -818,6 +818,8 @@ MKDEPCC
 ZLIB
 JSONSTATS
 XMLSTATS
+LIBXML2_LIBS
+LIBXML2_CFLAGS
 NZDTARGETS
 NZDSRCS
 NZD_TOOLS
@@ -1108,6 +1110,8 @@ PYTHON
 MAXMINDDB_CFLAGS
 MAXMINDDB_LIBS
 MAXMINDDB_PREFIX
+LIBXML2_CFLAGS
+LIBXML2_LIBS
 CMOCKA_CFLAGS
 CMOCKA_LIBS
 KYUA'
@@ -1798,7 +1802,8 @@ Optional Packages:
   --with-aes              Crypto AES
   --with-cc-alg=ALG       deprecated
   --with-lmdb=PATH        build with LMDB library [yes|no|path]
-  --with-libxml2=PATH     build with libxml2 library [yes|no|path]
+  --with-libxml2=PATH     build with libxml2 library (auto|yes|no|path)
+                          [default=auto]
   --with-libjson=PATH     build with libjson0 library [yes|no|path]
   --with-zlib=PATH        build with zlib for HTTP compression [default=yes]
   --with-purify=PATH      use Rational purify
@@ -1859,6 +1864,10 @@ Some influential environment variables:
               linker flags for MAXMINDDB, overriding pkg-config
   MAXMINDDB_PREFIX
               value of prefix for libmaxminddb, overriding pkg-config
+  LIBXML2_CFLAGS
+              C compiler flags for LIBXML2, overriding pkg-config
+  LIBXML2_LIBS
+              linker flags for LIBXML2, overriding pkg-config
   CMOCKA_CFLAGS
               C compiler flags for CMOCKA, overriding pkg-config
   CMOCKA_LIBS linker flags for CMOCKA, overriding pkg-config
 #
 # was --with-libxml2 specified?
 #
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libxml2 library" >&5
-$as_echo_n "checking for libxml2 library... " >&6; }
 
 # Check whether --with-libxml2 was given.
 if test "${with_libxml2+set}" = set; then :
-  withval=$with_libxml2; use_libxml2="$withval"
+  withval=$with_libxml2;
 else
-  use_libxml2="auto"
+  with_libxml2="auto"
 fi
 
 
-case "$use_libxml2" in
-       no)
-               DST_LIBXML2_INC=""
-               ;;
-       auto|yes)
-               case X`(xml2-config --version) 2>/dev/null` in
-               X2.[6789].*)
-                       libxml2_libs=`xml2-config --libs`
-                       libxml2_cflags=`xml2-config --cflags`
-                       ;;
-               *)
-                       if test "yes" = "$use_libxml2" ; then
-                               { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+LIBXML2_CFLAGS=
+LIBXML2_LIBS=
+case $with_libxml2 in #(
+  no) :
+    : ;; #(
+  auto) :
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libxml-2.0 >= 2.6.0" >&5
+$as_echo_n "checking for libxml-2.0 >= 2.6.0... " >&6; }
+
+if test -n "$LIBXML2_CFLAGS"; then
+    pkg_cv_LIBXML2_CFLAGS="$LIBXML2_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libxml-2.0 >= 2.6.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libxml-2.0 >= 2.6.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBXML2_CFLAGS=`$PKG_CONFIG --cflags "libxml-2.0 >= 2.6.0" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$LIBXML2_LIBS"; then
+    pkg_cv_LIBXML2_LIBS="$LIBXML2_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libxml-2.0 >= 2.6.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libxml-2.0 >= 2.6.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBXML2_LIBS=`$PKG_CONFIG --libs "libxml-2.0 >= 2.6.0" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-                               as_fn_error $? "required libxml2 version not available" "$LINENO" 5
-                       else
-                               libxml2_libs=
-                               libxml2_cflags=
-                       fi
-                       ;;
-               esac
-               ;;
-       *)
-               if test -f "$use_libxml2/bin/xml2-config" ; then
-                       libxml2_libs=`$use_libxml2/bin/xml2-config --libs`
-                       libxml2_cflags=`$use_libxml2/bin/xml2-config --cflags`
-               fi
-               ;;
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               LIBXML2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libxml-2.0 >= 2.6.0" 2>&1`
+        else
+               LIBXML2_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libxml-2.0 >= 2.6.0" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$LIBXML2_PKG_ERRORS" >&5
+
+       :
+elif test $pkg_failed = untried; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       :
+else
+       LIBXML2_CFLAGS=$pkg_cv_LIBXML2_CFLAGS
+       LIBXML2_LIBS=$pkg_cv_LIBXML2_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+       :
+fi ;; #(
+  yes) :
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libxml-2.0 >= 2.6.0" >&5
+$as_echo_n "checking for libxml-2.0 >= 2.6.0... " >&6; }
+
+if test -n "$LIBXML2_CFLAGS"; then
+    pkg_cv_LIBXML2_CFLAGS="$LIBXML2_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libxml-2.0 >= 2.6.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libxml-2.0 >= 2.6.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBXML2_CFLAGS=`$PKG_CONFIG --cflags "libxml-2.0 >= 2.6.0" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+if test -n "$LIBXML2_LIBS"; then
+    pkg_cv_LIBXML2_LIBS="$LIBXML2_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+    if test -n "$PKG_CONFIG" && \
+    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libxml-2.0 >= 2.6.0\""; } >&5
+  ($PKG_CONFIG --exists --print-errors "libxml-2.0 >= 2.6.0") 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; then
+  pkg_cv_LIBXML2_LIBS=`$PKG_CONFIG --libs "libxml-2.0 >= 2.6.0" 2>/dev/null`
+                     test "x$?" != "x0" && pkg_failed=yes
+else
+  pkg_failed=yes
+fi
+ else
+    pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+        _pkg_short_errors_supported=yes
+else
+        _pkg_short_errors_supported=no
+fi
+        if test $_pkg_short_errors_supported = yes; then
+               LIBXML2_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libxml-2.0 >= 2.6.0" 2>&1`
+        else
+               LIBXML2_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libxml-2.0 >= 2.6.0" 2>&1`
+        fi
+       # Put the nasty error message in config.log where it belongs
+       echo "$LIBXML2_PKG_ERRORS" >&5
+
+       as_fn_error $? "Package requirements (libxml-2.0 >= 2.6.0) were not met:
+
+$LIBXML2_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables LIBXML2_CFLAGS
+and LIBXML2_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details." "$LINENO" 5
+elif test $pkg_failed = untried; then
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+       { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables LIBXML2_CFLAGS
+and LIBXML2_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details" "$LINENO" 5; }
+else
+       LIBXML2_CFLAGS=$pkg_cv_LIBXML2_CFLAGS
+       LIBXML2_LIBS=$pkg_cv_LIBXML2_LIBS
+        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+
+fi ;; #(
+  *) :
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libxml2 library in $with_libxml2" >&5
+$as_echo_n "checking for libxml2 library in $with_libxml2... " >&6; }
+        if test -x "$with_libxml2/bin/xml2-config"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+               LIBXML2_LIBS=`$with_libxml2/bin/xml2-config --libs`
+               LIBXML2_CFLAGS=`$with_libxml2/bin/xml2-config --cflags`
+else
+  as_fn_error $? "not found" "$LINENO" 5
+fi ;;
 esac
 
-if test "X$libxml2_libs" != "X"
-then
-       CFLAGS="$CFLAGS $libxml2_cflags"
-       LIBS="$LIBS $libxml2_libs"
-       #
-       # Sanity check xml2-config output.
-       #
-       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+if test -n "$LIBXML2_LIBS"; then :
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether linking with libxml2 works" >&5
+$as_echo_n "checking whether linking with libxml2 works... " >&6; }
+       CFLAGS="$CFLAGS $LIBXML2_CFLAGS"
+       LIBS="$LIBS $LIBXML2_LIBS"
+       #
+       # Sanity check xml2-config output.
+       #
+       cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 #include <libxml/xmlwriter.h>
 int
@@ -18401,16 +18561,16 @@ if ac_fn_c_try_link "$LINENO"; then :
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 else
-  as_fn_error $? "xml2-config returns badness" "$LINENO" 5
+  as_fn_error $? "no" "$LINENO" 5
 fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
 
 $as_echo "#define HAVE_LIBXML2 1" >>confdefs.h
 
-       XMLSTATS=1
+       XMLSTATS=1
 else
-       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
index 4ab10a05f9d212db00fa520336e7047b6f99f5f4..dbe7c9f081fba9897abd558c19d8b277af154318 100644 (file)
@@ -2393,58 +2393,38 @@ AC_SUBST(NZDTARGETS)
 #
 # was --with-libxml2 specified?
 #
-AC_MSG_CHECKING(for libxml2 library)
-AC_ARG_WITH(libxml2,
-           AS_HELP_STRING([--with-libxml2[=PATH]],
-                          [build with libxml2 library [yes|no|path]]),
-           use_libxml2="$withval", use_libxml2="auto")
-
-case "$use_libxml2" in
-       no)
-               DST_LIBXML2_INC=""
-               ;;
-       auto|yes)
-               case X`(xml2-config --version) 2>/dev/null` in
-               X2.[[6789]].*)
-                       libxml2_libs=`xml2-config --libs`
-                       libxml2_cflags=`xml2-config --cflags`
-                       ;;
-               *)
-                       if test "yes" = "$use_libxml2" ; then
-                               AC_MSG_RESULT(no)
-                               AC_MSG_ERROR(required libxml2 version not available)
-                       else
-                               libxml2_libs=
-                               libxml2_cflags=
-                       fi
-                       ;;
-               esac
-               ;;
-       *)
-               if test -f "$use_libxml2/bin/xml2-config" ; then
-                       libxml2_libs=`$use_libxml2/bin/xml2-config --libs`
-                       libxml2_cflags=`$use_libxml2/bin/xml2-config --cflags`
-               fi
-               ;;
-esac
-
-if test "X$libxml2_libs" != "X"
-then
-       CFLAGS="$CFLAGS $libxml2_cflags"
-       LIBS="$LIBS $libxml2_libs"
-       #
-       # Sanity check xml2-config output.
-       #
-       AC_TRY_LINK([#include <libxml/xmlwriter.h>],
-                   [return(xmlTextWriterStartElement(NULL, NULL));],
-                   AC_MSG_RESULT(yes),
-                   AC_MSG_ERROR(xml2-config returns badness))
-       AC_DEFINE(HAVE_LIBXML2, 1, [Define if libxml2 was found])
-       XMLSTATS=1
-else
-       AC_MSG_RESULT(no)
-fi
-AC_SUBST(XMLSTATS)
+AC_ARG_WITH([libxml2],
+           [AS_HELP_STRING([--with-libxml2[=PATH]],
+                          [build with libxml2 library (auto|yes|no|path) [default=auto]])],
+           [:], [with_libxml2="auto"])
+
+LIBXML2_CFLAGS=
+LIBXML2_LIBS=
+AS_CASE([$with_libxml2],
+       [no],[:],
+       [auto],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0], [:], [:])],
+       [yes],[PKG_CHECK_MODULES([LIBXML2], [libxml-2.0 >= 2.6.0])],
+       [AC_MSG_CHECKING([for libxml2 library in $with_libxml2])
+        AS_IF([test -x "$with_libxml2/bin/xml2-config"],
+              [AC_MSG_RESULT([yes])
+               LIBXML2_LIBS=`$with_libxml2/bin/xml2-config --libs`
+               LIBXML2_CFLAGS=`$with_libxml2/bin/xml2-config --cflags`],
+              [AC_MSG_ERROR([not found])])])
+
+AS_IF([test -n "$LIBXML2_LIBS"],
+      [AC_MSG_CHECKING([whether linking with libxml2 works])
+       CFLAGS="$CFLAGS $LIBXML2_CFLAGS"
+       LIBS="$LIBS $LIBXML2_LIBS"
+       #
+       # Sanity check xml2-config output.
+       #
+       AC_TRY_LINK([#include <libxml/xmlwriter.h>],
+                  [return(xmlTextWriterStartElement(NULL, NULL));],
+                  [AC_MSG_RESULT([yes])],
+                  [AC_MSG_ERROR([no])])
+       AC_DEFINE([HAVE_LIBXML2], [1], [Define if libxml2 was found])
+       XMLSTATS=1])
+AC_SUBST([XMLSTATS])
 
 #
 # was --with-libjson specified?