getrandom.m4 2.1 KB

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