From 69d526f2f57e3245fc2bb3601dde0df68fe723eb Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Mon, 13 Feb 2017 02:34:01 -0500
Subject: [PATCH] Look for libxml2 via pkg-config first.

If no explicit path is specified, try pkg-config first, before
xml2-config. The reason is that pkg-config knows the difference between
static and shared dependencies and thus doesn't cause libxslt to be
linked against a bunch of extra stuff.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 configure.in | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index 019f022..1d14357 100644
--- a/configure.in
+++ b/configure.in
@@ -118,6 +118,7 @@ AC_PATH_PROG(MV, mv, /bin/mv)
 AC_PATH_PROG(TAR, tar, /bin/tar)
 AC_PATH_PROG(XMLLINT, xmllint, /usr/bin/xmllint)
 AC_PATH_PROG(XSLTPROC, xsltproc, /usr/bin/xsltproc)
+PKG_PROG_PKG_CONFIG
 
 AC_HEADER_STDC
 
@@ -501,6 +502,26 @@ AC_ARG_WITH(libxml-src,
 AC_SUBST(LIBXML_SRC)
 
 dnl
+dnl Try pkg-config first if nothing is set
+dnl
+
+if test "x$LIBXML_CONFIG_PREFIX" == "x" -a "x$LIBXML_SRC" == "x"
+then
+	PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= $LIBXML_REQUIRED_VERSION], [
+		LIBXML_MANUAL_SEARCH=no
+		WITH_MODULES="`$PKG_CONFIG --variable=modules libxml-2.0`"
+	],
+	[
+		LIBXML_MANUAL_SEARCH=yes
+	])
+else
+	LIBXML_MANUAL_SEARCH=yes
+fi
+
+if test "x$LIBXML_MANUAL_SEARCH" != "xno"
+then
+
+dnl
 dnl where is xml2-config
 dnl
 
@@ -578,6 +599,10 @@ else
 	AC_MSG_ERROR([Could not find libxml2 anywhere, check ftp://xmlsoft.org/.])
 fi
 
+WITH_MODULES="`$XML_CONFIG --modules`"
+
+fi  # LIBXML_MANUAL_SEARCH
+
 
 AC_SUBST(CFLAGS)
 AC_SUBST(CPPFLAGS)
@@ -602,7 +627,6 @@ fi
 
 if test "$with_plugins" = "yes" ; then
   AC_MSG_CHECKING([libxml2 module support])
-  WITH_MODULES="`$XML_CONFIG --modules`"
   if test "${WITH_MODULES}" = "1"; then
     AC_MSG_RESULT(yes)
   else
-- 
2.9.3

