config: better libtirpc detection

Improve the autoconf code for finding libtirpc and do not assume the
headers are in /usr/include/tirpc.

Also remove this assumption from the `rpc/xdr.h` header in libspl and
use the same `#include_next` mechanism that is used for other libspl
headers.

Include pkg.m4 from pkg-config in config/ for PKG_CHECK_MODULES(), the
file license allows this.

Include ax_save_flags.m4 and ax_restore_flags.m4 from autoconf-archive,
the file licenses are compatible. Use the 2012 versions so as not rely
on a more recent autoconf feature AS_VAR_COPY(), which breaks some build
slaves.

Add new macro library `config/find_system_library.m4` which defines the
FIND_SYSTEM_LIBRARY() macro which is a convenience wrapper over using
PKG_CHECK_MODULES() with a fallback to standard library locations and
some sanity checks.

The parameters are:

```
FIND_SYSTEM_LIBRARY(VARIABLE-PREFIX, MODULE, HEADER, HEADER-PREFIXES,
    LIBRARY, FUNCTIONS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
```

`HEADER-PREFIXES` and `FUNCTIONS` are comma-separated m4 lists.

For libtirpc we are using:

```
FIND_SYSTEM_LIBRARY(LIBTIRPC, [libtirpc], [rpc/xdr.h], [tirpc], [tirpc],
    [xdrmem_create], [], [...])
```

The headers are first checked for without the prefixes and then with.

This system works with pkg-config and falls back on checking standard
header/library locations, it can be easily overridden by the user by
setting the `PREFIX_CFLAGS` and `PREFIX_LIBS` variables which are
automatically added to the `./configure --help` output.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
Closes #7422 
Closes #8313
This commit is contained in:
Rafael Kitover
2019-03-02 16:19:05 -08:00
committed by Brian Behlendorf
parent 0409679d88
commit 762f9ef3d9
9 changed files with 437 additions and 35 deletions
+18 -18
View File
@@ -4,27 +4,27 @@ dnl #
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBTIRPC], [
AC_ARG_WITH([tirpc],
[AS_HELP_STRING([--with-tirpc],
[use tirpc for xdr encoding @<:@default=check@:>@])],
[use tirpc for xdr encoding @<:@default=check@:>@])],
[],
[with_tirpc=check])
LIBTIRPC=
LIBTIRPC_CFLAGS=
have_xdr=
AS_IF([test "x$with_tirpc" != xno],
[AC_CHECK_LIB([tirpc], [xdrmem_create],
[AC_SUBST([LIBTIRPC], [-ltirpc])
AC_SUBST([LIBTIRPC_CFLAGS], [-I/usr/include/tirpc])
AC_DEFINE([HAVE_LIBTIRPC], [1], [Define if you have libtirpc])
],
[if test "x$with_tirpc" != xcheck; then
AC_MSG_FAILURE(
[--with-tirpc was given, but test for tirpc failed])
fi
AC_SEARCH_LIBS([xdrmem_create], [tirpc], [], [
AC_MSG_FAILURE([xdrmem_create() requires tirpc or libc])])
])],
[AC_SEARCH_LIBS([xdrmem_create], [tirpc], [], [
AC_MSG_FAILURE([xdrmem_create() requires libc])])
AS_IF([test "x$with_tirpc" != "xyes"], [
AC_SEARCH_LIBS([xdrmem_create], [], [have_xdr=1], [
AS_IF([test "x$with_tirpc" = "xno"], [
AC_MSG_FAILURE([xdrmem_create() requires sunrpc support in libc if not using libtirpc])
])
])
])
AS_IF([test "x$have_xdr" = "x"], [
FIND_SYSTEM_LIBRARY(LIBTIRPC, [libtirpc], [rpc/xdr.h], [tirpc], [tirpc], [xdrmem_create], [], [
AS_IF([test "x$with_tirpc" = "xyes"], [
AC_MSG_FAILURE([--with-tirpc was given, but libtirpc is not available, try installing libtirpc-devel])
],[dnl ELSE
AC_MSG_FAILURE([neither libc sunrpc support nor libtirpc is available, try installing libtirpc-devel])
])
])
])
])