]> git.proxmox.com Git - mirror_zfs.git/blob - config/user-libblkid.m4
Add build system
[mirror_zfs.git] / config / user-libblkid.m4
1 dnl #
2 dnl # Check for ZFS support in libblkid. This test needs to check
3 dnl # more than if the library exists because we expect there are
4 dnl # at least 3 flavors of the library out in the wild:
5 dnl #
6 dnl # 1) blkid which has no ZFS support
7 dnl # 2) blkid with ZFS support and a flawed method of probing
8 dnl # 3) blkid with ZFS support and a working method of probing
9 dnl #
10 dnl # To handle this the check first validates that there is a version
11 dnl # of the library installed. If there is it creates a simulated
12 dnl # ZFS filesystem and then links a small test app which attempts
13 dnl # to detect the simualated filesystem type. If it correctly
14 dnl # identifies the filesystem as ZFS we can safely assume case 3).
15 dnl # Otherwise we disable blkid support and resort to manual probing.
16 dnl #
17 AC_DEFUN([ZFS_AC_CONFIG_USER_LIBBLKID], [
18 AC_ARG_WITH([blkid],
19 [AS_HELP_STRING([--with-blkid],
20 [support blkid caching @<:@default=check@:>@])],
21 [],
22 [with_blkid=check])
23
24 LIBBLKID=
25 AS_IF([test "x$with_blkid" != xno],
26 [
27 AC_CHECK_LIB([blkid], [blkid_get_cache],
28 [
29 AC_MSG_CHECKING([for blkid zfs support])
30
31 ZFS_DEV=`mktemp`
32 dd if=/dev/zero of=$ZFS_DEV bs=1024k count=8 \
33 >/dev/null 2>/dev/null
34 echo -en "\x0c\xb1\xba\0\0\0\0\0" | \
35 dd of=$ZFS_DEV bs=1k count=8 \
36 seek=132 conv=notrunc &>/dev/null \
37 >/dev/null 2>/dev/null
38
39 saved_LDFLAGS="$LDFLAGS"
40 LDFLAGS="-lblkid"
41
42 AC_RUN_IFELSE(AC_LANG_PROGRAM(
43 [
44 #include <stdio.h>
45 #include <blkid/blkid.h>
46 ],
47 [
48 blkid_cache cache;
49 char *value;
50
51 if (blkid_get_cache(&cache, NULL) < 0)
52 return 1;
53
54 value = blkid_get_tag_value(cache, "TYPE",
55 "$ZFS_DEV");
56 if (!value) {
57 blkid_put_cache(cache);
58 return 2;
59 }
60
61 if (strcmp(value, "zfs")) {
62 free(value);
63 blkid_put_cache(cache);
64 return 3;
65 }
66
67 free(value);
68 blkid_put_cache(cache);
69 ]),
70 [
71 rm -f $ZFS_DEV
72 AC_MSG_RESULT([yes])
73 AC_SUBST([LIBBLKID], ["-lblkid"])
74 AC_DEFINE([HAVE_LIBBLKID], 1,
75 [Define if you have libblkid])
76 ],
77 [
78 rm -f $ZFS_DEV
79 AC_MSG_RESULT([no])
80 AS_IF([test "x$with_blkid" != xcheck],
81 [AC_MSG_FAILURE(
82 [--with-blkid given but unavailable])])
83 ])
84
85 LDFLAGS="$saved_LDFLAGS"
86 ],
87 [
88 AS_IF([test "x$with_blkid" != xcheck],
89 [AC_MSG_FAILURE(
90 [--with-blkid given but unavailable])])
91 ]
92 [])
93 ])
94 ])