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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
|
#
# Check if we have a pwritev2 libc call (Linux)
#
AC_DEFUN([AC_HAVE_PWRITEV2],
[ AC_MSG_CHECKING([for pwritev2])
AC_LINK_IFELSE(
[ AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <sys/uio.h>
]], [[
pwritev2(0, 0, 0, 0, 0);
]])
], have_pwritev2=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_pwritev2)
])
#
# Check if we have a copy_file_range system call (Linux)
#
AC_DEFUN([AC_HAVE_COPY_FILE_RANGE],
[ AC_MSG_CHECKING([for copy_file_range])
AC_LINK_IFELSE(
[ AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <sys/syscall.h>
#include <unistd.h>
]], [[
syscall(__NR_copy_file_range, 0, 0, 0, 0, 0, 0);
]])
], have_copy_file_range=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_copy_file_range)
])
#
# Check if we have a cachestat system call (Linux)
#
AC_DEFUN([AC_HAVE_CACHESTAT],
[ AC_MSG_CHECKING([for cachestat])
AC_LINK_IFELSE(
[ AC_LANG_PROGRAM([[
#include <unistd.h>
#include <linux/mman.h>
#include <asm/unistd.h>
]], [[
syscall(__NR_cachestat, 0, 0, 0, 0);
]])
], have_cachestat=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_cachestat)
])
#
# Check if we need to override the system struct fsxattr with
# the internal definition. This /only/ happens if the system
# actually defines struct fsxattr /and/ the system definition
# is missing certain fields.
#
AC_DEFUN([AC_NEED_INTERNAL_FSXATTR],
[
AC_CHECK_TYPE(struct fsxattr,
[
AC_CHECK_MEMBER(struct fsxattr.fsx_cowextsize,
,
need_internal_fsxattr=yes,
[#include <linux/fs.h>]
)
],,
[#include <linux/fs.h>]
)
AC_SUBST(need_internal_fsxattr)
])
#
# Check if we need to override the system struct fscrypt_add_key_arg
# with the internal definition. This /only/ happens if the system
# actually defines struct fscrypt_add_key_arg /and/ the system
# definition is missing certain fields.
#
AC_DEFUN([AC_NEED_INTERNAL_FSCRYPT_ADD_KEY_ARG],
[
AC_CHECK_TYPE(struct fscrypt_add_key_arg,
[
AC_CHECK_MEMBER(struct fscrypt_add_key_arg.key_id,
,
need_internal_fscrypt_add_key_arg=yes,
[#include <linux/fs.h>]
)
],,
[#include <linux/fs.h>]
)
AC_SUBST(need_internal_fscrypt_add_key_arg)
])
#
# Check if we need to override the system struct fscrypt_policy_v2
# with the internal definition. This /only/ happens if the system
# actually defines struct fscrypt_policy_v2 /and/ the system
# definition is missing certain fields.
#
AC_DEFUN([AC_NEED_INTERNAL_FSCRYPT_POLICY_V2],
[
AC_CHECK_TYPE(struct fscrypt_policy_v2,
[
AC_CHECK_MEMBER(struct fscrypt_policy_v2.log2_data_unit_size,
,
need_internal_fscrypt_policy_v2=yes,
[#include <linux/fs.h>]
)
],,
[#include <linux/fs.h>]
)
AC_SUBST(need_internal_fscrypt_policy_v2)
])
#
# Check if we need to override the system struct statx with
# the internal definition. This /only/ happens if the system
# actually defines struct statx /and/ the system definition
# is missing certain fields.
#
AC_DEFUN([AC_NEED_INTERNAL_STATX],
[ AC_CHECK_TYPE(struct statx,
[
AC_CHECK_MEMBER(struct statx.stx_atomic_write_unit_max_opt,
,
need_internal_statx=yes,
[[
#define _GNU_SOURCE
#include <fcntl.h>
#include <sys/stat.h>
#ifndef STATX_TYPE
#include <linux/stat.h>
#endif
]]
)
],need_internal_statx=yes,
[#include <linux/stat.h>]
)
AC_SUBST(need_internal_statx)
])
#
# Check if we have a FS_IOC_GETFSMAP ioctl (Linux)
#
AC_DEFUN([AC_HAVE_GETFSMAP],
[ AC_MSG_CHECKING([for GETFSMAP])
AC_LINK_IFELSE(
[ AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <sys/syscall.h>
#include <unistd.h>
#include <linux/fs.h>
#include <linux/fsmap.h>
]], [[
unsigned long x = FS_IOC_GETFSMAP;
struct fsmap_head fh;
]])
], have_getfsmap=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_getfsmap)
])
#
# Check if we have MAP_SYNC defines (Linux)
#
AC_DEFUN([AC_HAVE_MAP_SYNC],
[ AC_MSG_CHECKING([for MAP_SYNC])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
#include <sys/mman.h>
]], [[
int flags = MAP_SYNC | MAP_SHARED_VALIDATE;
]])
], have_map_sync=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_map_sync)
])
#
# Check if we have a mallinfo libc call
#
AC_DEFUN([AC_HAVE_MALLINFO],
[ AC_MSG_CHECKING([for mallinfo ])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
#include <malloc.h>
]], [[
struct mallinfo test;
test.arena = 0; test.hblkhd = 0; test.uordblks = 0; test.fordblks = 0;
test = mallinfo();
]])
], have_mallinfo=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_mallinfo)
])
#
# Check if we have a mallinfo2 libc call
#
AC_DEFUN([AC_HAVE_MALLINFO2],
[ AC_MSG_CHECKING([for mallinfo2 ])
AC_COMPILE_IFELSE(
[ AC_LANG_PROGRAM([[
#include <malloc.h>
]], [[
struct mallinfo2 test;
test.arena = 0; test.hblkhd = 0; test.uordblks = 0; test.fordblks = 0;
test = mallinfo2();
]])
], have_mallinfo2=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_mallinfo2)
])
#
# Check if we have a memfd_create libc call (Linux)
#
AC_DEFUN([AC_HAVE_MEMFD_CREATE],
[ AC_MSG_CHECKING([for memfd_create])
AC_LINK_IFELSE(
[ AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <sys/mman.h>
]], [[
memfd_create(0, 0);
]])
], have_memfd_create=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_memfd_create)
])
#
# Check if we have a getrandom syscall with a GRND_NONBLOCK flag
#
AC_DEFUN([AC_HAVE_GETRANDOM_NONBLOCK],
[ AC_MSG_CHECKING([for getrandom and GRND_NONBLOCK])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
#include <sys/random.h>
]], [[
unsigned int moo;
return getrandom(&moo, sizeof(moo), GRND_NONBLOCK);
]])],[have_getrandom_nonblock=yes
AC_MSG_RESULT(yes)],[AC_MSG_RESULT(no)])
AC_SUBST(have_getrandom_nonblock)
])
AC_DEFUN([AC_PACKAGE_CHECK_LTO],
[ AC_MSG_CHECKING([if C compiler supports LTO])
OLD_CFLAGS="$CFLAGS"
OLD_LDFLAGS="$LDFLAGS"
LTO_FLAGS="-flto -ffat-lto-objects"
CFLAGS="$CFLAGS $LTO_FLAGS"
LDFLAGS="$LDFLAGS $LTO_FLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([])],
[AC_MSG_RESULT([yes])]
[lto_cflags=$LTO_FLAGS]
[lto_ldflags=$LTO_FLAGS]
[AC_PATH_PROG(gcc_ar, gcc-ar,,)]
[AC_PATH_PROG(gcc_ranlib, gcc-ranlib,,)],
[AC_MSG_RESULT([no])])
if test -x "$gcc_ar" && test -x "$gcc_ranlib"; then
have_lto=yes
fi
CFLAGS="${OLD_CFLAGS}"
LDFLAGS="${OLD_LDFLAGS}"
AC_SUBST(gcc_ar)
AC_SUBST(gcc_ranlib)
AC_SUBST(have_lto)
AC_SUBST(lto_cflags)
AC_SUBST(lto_ldflags)
])
#
# Check if we have a file_getattr system call (Linux)
#
AC_DEFUN([AC_HAVE_FILE_GETATTR],
[AC_MSG_CHECKING([for file_getattr syscall])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <sys/syscall.h>
#include <unistd.h>
]], [[
syscall(__NR_file_getattr, 0, 0, 0, 0, 0);
]])
], have_file_getattr=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
AC_SUBST(have_file_getattr)
])
#
# Check if strerror_r returns an int, as opposed to a char *, because there are
# two versions of this function, with differences that are hard to detect.
#
# GNU strerror_r returns a pointer to a string on success, but the returned
# pointer might point to a static buffer and not buf, so you have to use the
# return value. The declaration has the __warn_unused_result__ attribute to
# enforce this.
#
# XSI strerror_r always writes to buf and returns 0 on success, -1 on error.
#
# How do you select a particular version? By defining macros, of course!
# _GNU_SOURCE always gets you the GNU version, and _POSIX_C_SOURCE >= 200112L
# gets you the XSI version but only if _GNU_SOURCE isn't defined.
#
# The build system #defines _GNU_SOURCE unconditionally, so when compiling
# against glibc we get the GNU version. However, when compiling against musl,
# the _GNU_SOURCE definition does nothing and we get the XSI version anyway.
# Not definining _GNU_SOURCE breaks the build in many areas, so we'll create
# yet another #define for just this weird quirk so that we can patch around it
# in the one place we need it.
#
# Note that we have to force erroring out on the int conversion warnings
# because C doesn't consider it a hard error to cast a char pointer to an int
# even when CFLAGS contains -std=gnu11.
AC_DEFUN([AC_STRERROR_R_RETURNS_STRING],
[AC_MSG_CHECKING([if strerror_r returns char *])
OLD_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall -Werror"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
]], [[
char buf[1024];
puts(strerror_r(0, buf, sizeof(buf)));
]])
],
strerror_r_returns_string=yes
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no))
CFLAGS="$OLD_CFLAGS"
AC_SUBST(strerror_r_returns_string)
])
|