mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-24 07:40:52 +00:00
Fix up FIND_SYSTEM_LIBRARY to work with cross-compiling
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
This commit is contained in:
parent
3e597dee11
commit
f040a7b0f8
@ -4,74 +4,90 @@ 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 FIND_SYSTEM_LIBRARY(VARIABLE-PREFIX, MODULE, HEADER, HEADER-PREFIXES, LIBRARY, FUNCTIONS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
dnl ZFS_AC_FIND_SYSTEM_LIBRARY(VARIABLE-PREFIX, MODULE, HEADER, HEADER-PREFIXES, LIBRARY, FUNCTIONS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
|
||||
|
||||
AC_DEFUN([FIND_SYSTEM_LIBRARY], [
|
||||
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], [_library_found=1], [:])])
|
||||
AS_IF([test -n "$2"], [PKG_CHECK_MODULES([$1], [$2], [
|
||||
_header_found=1
|
||||
_library_found=1
|
||||
], [:])])
|
||||
|
||||
AS_IF([test -z "$_library_found"], [
|
||||
AS_IF([test -f /usr/include/[$3]], [
|
||||
AC_SUBST([$1][_CFLAGS], [])
|
||||
AC_SUBST([$1][_LIBS], ["-l[$5]]")
|
||||
_library_found=1
|
||||
],[ AS_IF([test -f /usr/local/include/[$3]], [
|
||||
AC_SUBST([$1][_CFLAGS], ["-I/usr/local/include"])
|
||||
AC_SUBST([$1][_LIBS], ["-L/usr/local -l[$5]]")
|
||||
_library_found=1
|
||||
],[dnl ELSE
|
||||
:
|
||||
m4_foreach([prefix], [$4], [
|
||||
AS_IF([test "x$_library_found" != "x1"], [
|
||||
AS_IF([test -f [/usr/include/]prefix[/][$3]], [
|
||||
AC_SUBST([$1][_CFLAGS], ["[-I/usr/include/]prefix["]])
|
||||
AC_SUBST([$1][_LIBS], ["-l[$5]]")
|
||||
_library_found=1
|
||||
],[ AS_IF([test -f [/usr/local/include/]prefix[/][$3]], [
|
||||
AC_SUBST([$1][_CFLAGS], ["[-I/usr/local/include/]prefix["]])
|
||||
AC_SUBST([$1][_LIBS], ["-L/usr/local -l[$5]"])
|
||||
_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])
|
||||
|
||||
AS_IF([test -z "$_library_found"], [
|
||||
AC_MSG_WARN([cannot find [$5] via pkg-config or in the standard locations])
|
||||
])
|
||||
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]])
|
||||
])
|
||||
|
||||
dnl do some further sanity checks
|
||||
AX_RESTORE_FLAGS
|
||||
|
||||
AS_IF([test -n "$_library_found"], [
|
||||
AX_SAVE_FLAGS
|
||||
|
||||
CPPFLAGS="$CPPFLAGS $(echo $[$1][_CFLAGS] | sed 's/-include */-include-/g; s/^/ /; s/ [^-][^ ]*//g; s/ -[^Ii][^ ]*//g; s/-include-/-include /g; s/^ //;')"
|
||||
CFLAGS="$CFLAGS $[$1][_CFLAGS]"
|
||||
LDFLAGS="$LDFLAGS $[$1][_LIBS]"
|
||||
|
||||
AC_CHECK_HEADER([$3], [], [
|
||||
AC_MSG_WARN([header [$3] for library [$5] is not usable])
|
||||
_library_found=
|
||||
])
|
||||
|
||||
m4_foreach([func], [$6], [
|
||||
AC_CHECK_LIB([$5], func, [], [
|
||||
AC_MSG_WARN([cannot find ]func[ in library [$5]])
|
||||
_library_found=
|
||||
])
|
||||
])
|
||||
|
||||
AX_RESTORE_FLAGS
|
||||
])
|
||||
|
||||
AS_IF([test -n "$_library_found"], [
|
||||
AC_DEFINE([HAVE_][$1], [1], [Define if you have [$5]])
|
||||
:;$7
|
||||
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
|
||||
:;$8
|
||||
AC_SUBST([$1]_CFLAGS, [])
|
||||
AC_SUBST([$1]_LIBS, [])
|
||||
AC_MSG_WARN([cannot find [$5] via pkg-config or in the standard locations])
|
||||
$8
|
||||
])
|
||||
])
|
||||
|
@ -2,5 +2,5 @@ dnl #
|
||||
dnl # Check for libaio - only used for libaiot test cases.
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBAIO], [
|
||||
FIND_SYSTEM_LIBRARY(LIBAIO, [], [libaio.h], [], [aio], [], [user_libaio=yes], [user_libaio=no])
|
||||
ZFS_AC_FIND_SYSTEM_LIBRARY(LIBAIO, [], [libaio.h], [], [aio], [], [user_libaio=yes], [user_libaio=no])
|
||||
])
|
||||
|
@ -3,7 +3,7 @@ dnl # Check for libblkid. Basic support for detecting ZFS pools
|
||||
dnl # has existing in blkid since 2008.
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBBLKID], [
|
||||
FIND_SYSTEM_LIBRARY(LIBBLKID, [blkid], [blkid/blkid.h], [], [blkid], [], [], [
|
||||
ZFS_AC_FIND_SYSTEM_LIBRARY(LIBBLKID, [blkid], [blkid/blkid.h], [], [blkid], [], [], [
|
||||
AC_MSG_FAILURE([
|
||||
*** blkid.h missing, libblkid-devel package required])])
|
||||
])
|
||||
|
@ -2,7 +2,7 @@ dnl #
|
||||
dnl # Check for libcrypto. Used for userspace password derivation via PBKDF2.
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBCRYPTO], [
|
||||
FIND_SYSTEM_LIBRARY(LIBCRYPTO, [libcrypto], [openssl/evp.h], [], [crypto], [PKCS5_PBKDF2_HMAC_SHA1], [], [
|
||||
ZFS_AC_FIND_SYSTEM_LIBRARY(LIBCRYPTO, [libcrypto], [openssl/evp.h], [], [crypto], [PKCS5_PBKDF2_HMAC_SHA1], [], [
|
||||
AC_MSG_FAILURE([
|
||||
*** evp.h missing, libssl-devel package required])])
|
||||
])
|
||||
|
@ -19,7 +19,7 @@ AC_DEFUN([ZFS_AC_CONFIG_USER_LIBTIRPC], [
|
||||
])
|
||||
|
||||
AS_IF([test "x$have_xdr" = "x"], [
|
||||
FIND_SYSTEM_LIBRARY(LIBTIRPC, [libtirpc], [rpc/xdr.h], [tirpc], [tirpc], [xdrmem_create], [], [
|
||||
ZFS_AC_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
|
||||
|
@ -2,17 +2,15 @@ dnl #
|
||||
dnl # Check for libudev - needed for vdev auto-online and auto-replace
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBUDEV], [
|
||||
FIND_SYSTEM_LIBRARY(LIBUDEV, [libudev], [libudev.h], [], [udev], [], [user_libudev=yes], [user_libudev=no])
|
||||
ZFS_AC_FIND_SYSTEM_LIBRARY(LIBUDEV, [libudev], [libudev.h], [], [udev], [], [user_libudev=yes], [user_libudev=no])
|
||||
|
||||
AS_IF([test "x$user_libudev" = xyes], [
|
||||
AX_SAVE_FLAGS
|
||||
|
||||
CFLAGS="$CFLAGS $LIBUDEV_CFLAGS"
|
||||
LDFLAGS="$LDFLAGS $LIBUDEV_LIBS"
|
||||
LIBS="$LIBUDEV_LIBS $LIBS"
|
||||
|
||||
AC_CHECK_LIB([udev], [udev_device_get_is_initialized], [
|
||||
AC_DEFINE([HAVE_LIBUDEV_UDEV_DEVICE_GET_IS_INITIALIZED], 1, [
|
||||
Define if udev_device_get_is_initialized is available])], [])
|
||||
AC_CHECK_FUNCS([udev_device_get_is_initialized])
|
||||
|
||||
AX_RESTORE_FLAGS
|
||||
])
|
||||
|
@ -2,7 +2,7 @@ dnl #
|
||||
dnl # Check for libuuid
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBUUID], [
|
||||
FIND_SYSTEM_LIBRARY(LIBUUID, [uuid], [uuid/uuid.h], [], [uuid], [uuid_generate, uuid_is_null], [], [
|
||||
ZFS_AC_FIND_SYSTEM_LIBRARY(LIBUUID, [uuid], [uuid/uuid.h], [], [uuid], [uuid_generate uuid_is_null], [], [
|
||||
AC_MSG_FAILURE([*** libuuid-devel package required])
|
||||
])
|
||||
])
|
||||
|
@ -2,7 +2,7 @@ dnl #
|
||||
dnl # Check for zlib
|
||||
dnl #
|
||||
AC_DEFUN([ZFS_AC_CONFIG_USER_ZLIB], [
|
||||
FIND_SYSTEM_LIBRARY(ZLIB, [zlib], [zlib.h], [], [z], [compress2, uncompress, crc32], [], [
|
||||
ZFS_AC_FIND_SYSTEM_LIBRARY(ZLIB, [zlib], [zlib.h], [], [z], [compress2 uncompress crc32], [], [
|
||||
AC_MSG_FAILURE([*** zlib-devel package required])
|
||||
])
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user