The current code to check XDR support was obsolete and way to
complicated.
On linux we can use pkg-config to check for libtirpc and have
the CFLAGS and LIBS configured by it as well.
On MinGW there is portablexdr library which installs header files
directly into system include directory.
On FreeBSD and macOS XDR functions are part of libc so there is
no library needed, we just need to call AM_CONDITIONAL to silence
configure which otherwise complains about missing WITH_XDR.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
libvirt.spec.in | 4 ++++
m4/virt-xdr.m4 | 39 +++++++++++--------------------------
src/Makefile.am | 4 +++-
src/admin/Makefile.inc.am | 1 +
src/locking/Makefile.inc.am | 2 ++
src/logging/Makefile.inc.am | 1 +
src/remote/Makefile.inc.am | 1 +
7 files changed, 23 insertions(+), 29 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 9f24e06aa46..6413d0e4e7a 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -406,8 +406,12 @@ BuildRequires: wireshark-devel >= 2.4.0
BuildRequires: libssh-devel >= 0.7.0
%endif
+# On RHEL-7 rpcgen is still part of glibc-common package
%if 0%{?fedora} || 0%{?rhel} > 7
BuildRequires: rpcgen
+%endif
+
+%if 0%{?fedora} || 0%{?rhel}
BuildRequires: libtirpc-devel
%endif
diff --git a/m4/virt-xdr.m4 b/m4/virt-xdr.m4
index 83754157d9a..09d0c2ba2f4 100644
--- a/m4/virt-xdr.m4
+++ b/m4/virt-xdr.m4
@@ -18,37 +18,20 @@ dnl <
http://www.gnu.org/licenses/>.
dnl
AC_DEFUN([LIBVIRT_CHECK_XDR], [
- with_xdr="no"
if test x"$with_remote" = x"yes" || test
x"$with_libvirtd" = x"yes"; then
- dnl Where are the XDR functions?
- dnl If portablexdr is installed, prefer that.
- dnl Otherwise try -lxdr (some MinGW)
- dnl -ltirpc (glibc 2.13.90 or newer) or none (most Unix)
- AC_CHECK_LIB([portablexdr],[xdrmem_create],[],[
- AC_SEARCH_LIBS([xdrmem_create],[xdr tirpc],[],
- [AC_MSG_ERROR([Cannot find a XDR library])])
- ])
+ dnl On MinGW portablexdr provides XDR functions, on linux they are
+ dnl provided by libtirpc and on FreeBSD/macOS there is no need to
+ dnl use extra library as it's provided by libc directly.
+
with_xdr="yes"
- dnl Recent glibc requires -I/usr/include/tirpc for <rpc/rpc.h>
- old_CFLAGS=$CFLAGS
- AC_CACHE_CHECK([where to find <rpc/rpc.h>], [lv_cv_xdr_cflags], [
- for add_CFLAGS in '' '-I/usr/include/tirpc' 'missing'; do
- if test x"$add_CFLAGS" = xmissing; then
- lv_cv_xdr_cflags=missing; break
- fi
- CFLAGS="$old_CFLAGS $add_CFLAGS"
- AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <rpc/rpc.h>
- ]])], [lv_cv_xdr_cflags=${add_CFLAGS:-none}; break])
- done
- ])
- CFLAGS=$old_CFLAGS
- case $lv_cv_xdr_cflags in
- none) XDR_CFLAGS= ;;
- missing) AC_MSG_ERROR([Unable to find <rpc/rpc.h>]) ;;
- *) XDR_CFLAGS=$lv_cv_xdr_cflags ;;
- esac
- AC_SUBST([XDR_CFLAGS])
+ if test "$with_win" = "yes"; then
+ LIBVIRT_CHECK_LIB([XDR], [portablexdr], [xdrmem_create], [rpc/rpc.h])
+ elif test "$with_linux" = "yes"; then
+ LIBVIRT_CHECK_PKG([XDR], [libtirpc], [0.1.10])
+ else
+ AM_CONDITIONAL([WITH_XDR], [test "x$with_xdr" = "xyes"])
+ fi
fi
])
diff --git a/src/Makefile.am b/src/Makefile.am
index 57e1d4d95b3..834e356b68b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -434,7 +434,9 @@ libvirt_la_LDFLAGS = \
$(AM_LDFLAGS) \
$(NULL)
libvirt_la_LIBADD += \
- $(DLOPEN_LIBS)
+ $(DLOPEN_LIBS) \
+ $(XDR_LIBS) \
+ $(NULL)
libvirt_la_CFLAGS = -DIN_LIBVIRT $(AM_CFLAGS)
# Because we specify libvirt_la_DEPENDENCIES for $(LIBVIRT_SYMBOL_FILE), we
# lose automake's automatic dependencies on an appropriate subset of
diff --git a/src/admin/Makefile.inc.am b/src/admin/Makefile.inc.am
index 0a9717adec6..8556a3b8523 100644
--- a/src/admin/Makefile.inc.am
+++ b/src/admin/Makefile.inc.am
@@ -72,6 +72,7 @@ libvirt_admin_la_LDFLAGS = \
libvirt_admin_la_LIBADD = \
libvirt.la \
+ $(XDR_LIBS) \
$(CAPNG_LIBS) \
$(YAJL_LIBS) \
$(DEVMAPPER_LIBS) \
diff --git a/src/locking/Makefile.inc.am b/src/locking/Makefile.inc.am
index d1bf49cd3fb..ab01d8e0482 100644
--- a/src/locking/Makefile.inc.am
+++ b/src/locking/Makefile.inc.am
@@ -120,6 +120,7 @@ lockd_la_LDFLAGS = $(AM_LDFLAGS_MOD_NOUNDEF)
lockd_la_LIBADD = \
libvirt.la \
$(GLIB_LIBS) \
+ $(XDR_LIBS) \
$(NULL)
augeas_DATA += locking/libvirt_lockd.aug
if WITH_DTRACE_PROBES
@@ -161,6 +162,7 @@ virtlockd_CFLAGS = \
virtlockd_LDFLAGS = \
$(AM_LDFLAGS) \
$(PIE_LDFLAGS) \
+ $(XDR_LIBS) \
$(NO_UNDEFINED_LDFLAGS) \
$(NULL)
virtlockd_LDADD = \
diff --git a/src/logging/Makefile.inc.am b/src/logging/Makefile.inc.am
index 64023aa672c..873e6029dd5 100644
--- a/src/logging/Makefile.inc.am
+++ b/src/logging/Makefile.inc.am
@@ -98,6 +98,7 @@ virtlogd_CFLAGS = \
virtlogd_LDFLAGS = \
$(AM_LDFLAGS) \
$(PIE_LDFLAGS) \
+ $(XDR_LIBS) \
$(NO_UNDEFINED_LDFLAGS) \
$(NULL)
virtlogd_LDADD = \
diff --git a/src/remote/Makefile.inc.am b/src/remote/Makefile.inc.am
index 5b8eb59bab3..80f4aad7828 100644
--- a/src/remote/Makefile.inc.am
+++ b/src/remote/Makefile.inc.am
@@ -64,6 +64,7 @@ REMOTE_DAEMON_LD_ADD = \
$(LIBXML_LIBS) \
$(GNUTLS_LIBS) \
$(SASL_LIBS) \
+ $(XDR_LIBS) \
$(DBUS_LIBS) \
$(LIBNL_LIBS) \
$(NULL)
--
2.26.2