Debian Codegraph @

m4/getrandom.m4

raw
1 # getrandom.m4
2 # serial 13
3 dnl Copyright 2020-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl Written by Paul Eggert.
10
11 AC_DEFUN([gl_FUNC_GETRANDOM],
12 [
13 AC_REQUIRE([gl_SYS_RANDOM_H_DEFAULTS])
14 AC_REQUIRE([AC_CANONICAL_HOST])
15
16 gl_CHECK_FUNCS_ANDROID([getrandom],
17 [[/* Additional includes are needed before <sys/random.h> on uClibc
18 and Mac OS X. */
19 #include <sys/types.h>
20 #include <stdlib.h>
21 #include <sys/random.h>
22 ]])
23 if test "$ac_cv_func_getrandom" != yes; then
24 HAVE_GETRANDOM=0
25 case "$gl_cv_onwards_func_getrandom" in
26 future*) REPLACE_GETRANDOM=1 ;;
27 esac
28 else
29 dnl On Solaris 11.4 the return type is 'int', not 'ssize_t'.
30 AC_CACHE_CHECK([whether getrandom is compatible with its GNU+BSD signature],
31 [gl_cv_func_getrandom_ok],
32 [AC_COMPILE_IFELSE(
33 [AC_LANG_PROGRAM(
34 [[/* Additional includes are needed before <sys/random.h> on uClibc
35 and Mac OS X. */
36 #include <sys/types.h>
37 #include <stdlib.h>
38 #include <sys/random.h>
39 ssize_t getrandom (void *, size_t, unsigned int);
40 ]],
41 [[]])
42 ],
43 [gl_cv_func_getrandom_ok=yes],
44 [gl_cv_func_getrandom_ok=no])
45 ])
46 if test $gl_cv_func_getrandom_ok = no; then
47 REPLACE_GETRANDOM=1
48 fi
49 fi
50
51 case "$host_os" in
52 mingw* | windows*)
53 AC_CHECK_HEADERS([bcrypt.h], [], [],
54 [[#include <windows.h>
55 ]])
56 AC_CACHE_CHECK([whether the bcrypt library is guaranteed to be present],
57 [gl_cv_lib_assume_bcrypt],
58 [AC_COMPILE_IFELSE(
59 [AC_LANG_PROGRAM(
60 [[#include <windows.h>]],
61 [[#if !(_WIN32_WINNT >= _WIN32_WINNT_WIN7)
62 cannot assume it
63 #endif
64 ]])
65 ],
66 [gl_cv_lib_assume_bcrypt=yes],
67 [gl_cv_lib_assume_bcrypt=no])
68 ])
69 if test $gl_cv_lib_assume_bcrypt = yes; then
70 AC_DEFINE([HAVE_LIB_BCRYPT], [1],
71 [Define to 1 if the bcrypt library is guaranteed to be present.])
72 GETRANDOM_LIB='-lbcrypt'
73 else
74 GETRANDOM_LIB='-ladvapi32'
75 fi
76 ;;
77 *)
78 GETRANDOM_LIB= ;;
79 esac
80 AC_SUBST([GETRANDOM_LIB])
81 dnl For backward compatibility.
82 LIB_GETRANDOM="$GETRANDOM_LIB"
83 AC_SUBST([LIB_GETRANDOM])
84 ])