1 # find_system_lib.m4 - Macros to search for a system library. -*- Autoconf -*-
3 dnl requires pkg.m4 from pkg-config
4 dnl requires ax_save_flags.m4 from autoconf-archive
5 dnl requires ax_restore_flags.m4 from autoconf-archive
7 dnl ZFS_AC_FIND_SYSTEM_LIBRARY(VARIABLE-PREFIX, MODULE, HEADER, HEADER-PREFIXES, LIBRARY, FUNCTIONS, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
9 AC_DEFUN([ZFS_AC_FIND_SYSTEM_LIBRARY], [
10 AC_REQUIRE([PKG_PROG_PKG_CONFIG])
16 AS_IF([test -n "$2"], [PKG_CHECK_MODULES([$1], [$2], [
22 # set _header_found/_library_found if the user passed in CFLAGS/LIBS
23 AS_IF([test "x$[$1][_CFLAGS]" != x], [_header_found=1])
24 AS_IF([test "x$[$1][_LIBS]" != x], [_library_found=1])
30 for _prefixdir in /usr /usr/local
32 AS_VAR_PUSHDEF([header_cache], [ac_cv_header_$3])
33 AS_IF([test "x$_prefixdir" != "x/usr"], [
34 [$1][_CFLAGS]="-I$lt_sysroot$_prefixdir/include"
35 AS_IF([test "x$_library_found" = x], [
36 [$1][_LIBS]="-L$lt_sysroot$_prefixdir/lib"
39 CFLAGS="$orig_CFLAGS $[$1][_CFLAGS]"
40 AS_UNSET([header_cache])
41 AC_CHECK_HEADER([$3], [
44 ], [AS_IF([test "x$_header_found" = "x1"], [
45 # if pkg-config or the user set CFLAGS, fail if the header is unusable
46 AC_MSG_FAILURE([header [$3] for library [$5] is not usable])
47 ])], [AC_INCLUDES_DEFAULT])
48 # search for header under HEADER-PREFIXES
49 m4_foreach_w([prefix], [$4], [
50 [$1][_CFLAGS]=["-I$lt_sysroot$_prefixdir/include/]prefix["]
51 CFLAGS="$orig_CFLAGS $[$1][_CFLAGS]"
52 AS_UNSET([header_cache])
53 AC_CHECK_HEADER([$3], [
56 ], [], [AC_INCLUDES_DEFAULT])
58 AS_VAR_POPDEF([header_cache])
61 AS_IF([test "x$_header_found" = "x1"], [
62 AS_IF([test "x$_library_found" = x], [
63 [$1][_LIBS]="$[$1]_LIBS -l[$5]"
65 LDFLAGS="$LDFLAGS $[$1][_LIBS]"
69 [m4_foreach_w([func], [$6], [AC_CHECK_LIB([$5], func, [:], [_libcheck=])])],
70 [AC_CHECK_LIB([$5], [main], [:], [_libcheck=])])
72 AS_IF([test "x$_libcheck" = "x1"], [_library_found=1],
73 [test "x$_library_found" = "x1"], [
74 # if pkg-config or the user set LIBS, fail if the library is unusable
75 AC_MSG_FAILURE([library [$5] is not usable])
77 ], [test "x$_library_found" = "x1"], [
78 # if the user set LIBS, fail if we didn't find the header
79 AC_MSG_FAILURE([cannot find header [$3] for library [$5]])
84 AS_IF([test "x$_header_found" = "x1" && test "x$_library_found" = "x1"], [
87 AS_IF([test "x$_pc_found" = "x1"], [
88 AC_SUBST([$1]_PC, [$2])
90 AC_DEFINE([HAVE_][$1], [1], [Define if you have [$5]])
93 AC_SUBST([$1]_CFLAGS, [""])
94 AC_SUBST([$1]_LIBS, [""])
95 AC_MSG_WARN([cannot find [$5] via pkg-config or in the standard locations])