1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# 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
])
])
|