libgcrypt-1.10.2 fails to build on systems where getrandom(2) is not availalble, like macOS (aka Darwin) or NetBSD 9.
getrandom() presence should be detected by configure and the function must be used conditionally.
My set of quick patches:
--- configure.orig 2023-04-06 19:07:18.000000000 +0000 +++ configure @@ -18809,7 +18809,7 @@ _ACEOF fi done -for ac_func in explicit_bzero explicit_memset getentropy +for ac_func in explicit_bzero explicit_memset getentropy getrandom do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
--- config.h.in.orig 2023-04-07 08:54:23.000000000 +0000 +++ config.h.in @@ -294,6 +294,9 @@ /* Define to 1 if you have the `getpid' function. */ #undef HAVE_GETPID +/* Define to 1 if you have the `getrandom' function. */ +#undef HAVE_GETRANDOM + /* Define to 1 if you have the `getrusage' function. */ #undef HAVE_GETRUSAGE
--- random/rndgetentropy.c.orig 2023-04-07 08:56:42.000000000 +0000 +++ random/rndgetentropy.c @@ -81,6 +81,7 @@ _gcry_rndgetentropy_gather_random (void do { _gcry_pre_syscall (); +#ifdef HAVE_GETRANDOM if (fips_mode ()) { /* DRBG chaining defined in SP 800-90A (rev 1) specify @@ -98,6 +99,7 @@ _gcry_rndgetentropy_gather_random (void ret = getrandom (buffer, nbytes, GRND_RANDOM); } else +#endif { nbytes = length < sizeof (buffer) ? length : sizeof (buffer); ret = getentropy (buffer, nbytes);