mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 01:51:00 +03:00
f040a7b0f8
Make FIND_SYSTEM_LIBRARY respect a configured sysroot, otherwise it might find headers from the build machine and assume the library is available on the host/target. Tighten up error checking: if pkg-config or the user specified _CFLAGS or _LIBS but we can't find the header/library, issue a fatal error. Fix the -L flag to /usr/local/lib instead of just /usr/local. Clean out the _CFLAGS and _LIBS if we located something that we later find doesn't work. Rename FIND_SYSTEM_LIBRARY into the ZFS_AC_ scope. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu> Closes #10538
94 lines
2.8 KiB
Plaintext
94 lines
2.8 KiB
Plaintext
# find_system_lib.m4 - Macros to search for a system library. -*- Autoconf -*-
|
|
|
|
dnl requires pkg.m4 from pkg-config
|
|
dnl requires ax_save_flags.m4 from autoconf-archive
|
|
dnl requires ax_restore_flags.m4 from autoconf-archive
|
|
|
|
dnl ZFS_AC_FIND_SYSTEM_LIBRARY(VARIABLE-PREFIX, MODULE, HEADER, HEADER-PREFIXES, LIBRARY, FUNCTIONS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
|
|
|
AC_DEFUN([ZFS_AC_FIND_SYSTEM_LIBRARY], [
|
|
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
|
|
|
|
_header_found=
|
|
_library_found=
|
|
|
|
AS_IF([test -n "$2"], [PKG_CHECK_MODULES([$1], [$2], [
|
|
_header_found=1
|
|
_library_found=1
|
|
], [:])])
|
|
|
|
# set _header_found/_library_found if the user passed in CFLAGS/LIBS
|
|
AS_IF([test "x$[$1][_CFLAGS]" != x], [_header_found=1])
|
|
AS_IF([test "x$[$1][_LIBS]" != x], [_library_found=1])
|
|
|
|
AX_SAVE_FLAGS
|
|
|
|
orig_CFLAGS="$CFLAGS"
|
|
|
|
for _prefixdir in /usr /usr/local
|
|
do
|
|
AS_VAR_PUSHDEF([header_cache], [ac_cv_header_$3])
|
|
AS_IF([test "x$_prefixdir" != "x/usr"], [
|
|
[$1][_CFLAGS]="-I$lt_sysroot$_prefixdir/include"
|
|
AS_IF([test "x$_library_found" = x], [
|
|
[$1][_LIBS]="-L$lt_sysroot$_prefixdir/lib"
|
|
])
|
|
])
|
|
CFLAGS="$orig_CFLAGS $[$1][_CFLAGS]"
|
|
AS_UNSET([header_cache])
|
|
AC_CHECK_HEADER([$3], [
|
|
_header_found=1
|
|
break
|
|
], [AS_IF([test "x$_header_found" = "x1"], [
|
|
# if pkg-config or the user set CFLAGS, fail if the header is unusable
|
|
AC_MSG_FAILURE([header [$3] for library [$5] is not usable])
|
|
])], [AC_INCLUDES_DEFAULT])
|
|
# search for header under HEADER-PREFIXES
|
|
m4_foreach_w([prefix], [$4], [
|
|
[$1][_CFLAGS]=["-I$lt_sysroot$_prefixdir/include/]prefix["]
|
|
CFLAGS="$orig_CFLAGS $[$1][_CFLAGS]"
|
|
AS_UNSET([header_cache])
|
|
AC_CHECK_HEADER([$3], [
|
|
_header_found=1
|
|
break
|
|
], [], [AC_INCLUDES_DEFAULT])
|
|
])
|
|
AS_VAR_POPDEF([header_cache])
|
|
done
|
|
|
|
AS_IF([test "x$_header_found" = "x1"], [
|
|
AS_IF([test "x$_library_found" = x], [
|
|
[$1][_LIBS]="$[$1]_LIBS -l[$5]"
|
|
])
|
|
LDFLAGS="$LDFLAGS $[$1][_LIBS]"
|
|
|
|
_libcheck=1
|
|
m4_ifval([$6],
|
|
[m4_foreach_w([func], [$6], [AC_CHECK_LIB([$5], func, [:], [_libcheck=])])],
|
|
[AC_CHECK_LIB([$5], [main], [:], [_libcheck=])])
|
|
|
|
AS_IF([test "x$_libcheck" = "x1"], [_library_found=1],
|
|
[test "x$_library_found" = "x1"], [
|
|
# if pkg-config or the user set LIBS, fail if the library is unusable
|
|
AC_MSG_FAILURE([library [$5] is not usable])
|
|
])
|
|
], [test "x$_library_found" = "x1"], [
|
|
# if the user set LIBS, fail if we didn't find the header
|
|
AC_MSG_FAILURE([cannot find header [$3] for library [$5]])
|
|
])
|
|
|
|
AX_RESTORE_FLAGS
|
|
|
|
AS_IF([test "x$_header_found" = "x1" && test "x$_library_found" = "x1"], [
|
|
AC_SUBST([$1]_CFLAGS)
|
|
AC_SUBST([$1]_LIBS)
|
|
AC_DEFINE([HAVE_][$1], [1], [Define if you have [$5]])
|
|
$7
|
|
],[dnl ELSE
|
|
AC_SUBST([$1]_CFLAGS, [])
|
|
AC_SUBST([$1]_LIBS, [])
|
|
AC_MSG_WARN([cannot find [$5] via pkg-config or in the standard locations])
|
|
$8
|
|
])
|
|
])
|