| 1 |
# random.m4 |
| 2 |
# serial 8 |
| 3 |
dnl Copyright (C) 2012-2025 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 |
AC_DEFUN([gl_FUNC_RANDOM], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 13 |
|
| 14 |
dnl We can't use AC_CHECK_FUNC here, because random() is defined as a |
| 15 |
dnl static inline function when compiling for Android 4.4 or older. |
| 16 |
AC_CACHE_CHECK([for random], [gl_cv_func_random], |
| 17 |
[AC_LINK_IFELSE( |
| 18 |
[AC_LANG_PROGRAM( |
| 19 |
[[#include <stdlib.h>]], |
| 20 |
[[return random() == 0;]]) |
| 21 |
], |
| 22 |
[gl_cv_func_random=yes], |
| 23 |
[gl_cv_func_random=no]) |
| 24 |
]) |
| 25 |
gl_CHECK_FUNCS_ANDROID([initstate], [[#include <stdlib.h>]]) |
| 26 |
gl_CHECK_FUNCS_ANDROID([setstate], [[#include <stdlib.h>]]) |
| 27 |
if test $gl_cv_func_random = no; then |
| 28 |
HAVE_RANDOM=0 |
| 29 |
HAVE_INITSTATE=0 |
| 30 |
HAVE_SETSTATE=0 |
| 31 |
else |
| 32 |
if test $ac_cv_func_initstate = no; then |
| 33 |
HAVE_INITSTATE=0 |
| 34 |
fi |
| 35 |
if test $ac_cv_func_setstate = no; then |
| 36 |
HAVE_SETSTATE=0 |
| 37 |
fi |
| 38 |
fi |
| 39 |
if test $HAVE_INITSTATE = 0; then |
| 40 |
case "$gl_cv_onwards_func_initstate" in |
| 41 |
future*) REPLACE_INITSTATE=1 ;; |
| 42 |
esac |
| 43 |
fi |
| 44 |
if test $HAVE_SETSTATE = 0; then |
| 45 |
case "$gl_cv_onwards_func_setstate" in |
| 46 |
future*) REPLACE_SETSTATE=1 ;; |
| 47 |
esac |
| 48 |
fi |
| 49 |
dnl On several platforms, random() is not multithread-safe. |
| 50 |
if test $ac_cv_func_initstate = no || test $ac_cv_func_setstate = no \ |
| 51 |
|| case "$host_os" in \ |
| 52 |
darwin* | freebsd* | solaris* | cygwin* | haiku*) true ;; \ |
| 53 |
*) false ;; \ |
| 54 |
esac |
| 55 |
then |
| 56 |
dnl In order to define initstate or setstate, we need to define all the |
| 57 |
dnl functions at once. |
| 58 |
REPLACE_RANDOM=1 |
| 59 |
if test $ac_cv_func_initstate = yes; then |
| 60 |
REPLACE_INITSTATE=1 |
| 61 |
fi |
| 62 |
if test $ac_cv_func_setstate = yes; then |
| 63 |
REPLACE_SETSTATE=1 |
| 64 |
fi |
| 65 |
fi |
| 66 |
|
| 67 |
AC_CHECK_DECLS_ONCE([initstate]) |
| 68 |
if test $ac_cv_have_decl_initstate = no; then |
| 69 |
HAVE_DECL_INITSTATE=0 |
| 70 |
fi |
| 71 |
|
| 72 |
AC_CHECK_DECLS_ONCE([setstate]) |
| 73 |
if test $ac_cv_have_decl_setstate = no; then |
| 74 |
HAVE_DECL_SETSTATE=0 |
| 75 |
fi |
| 76 |
]) |
| 77 |
|
| 78 |
# Prerequisites of lib/random.c. |
| 79 |
AC_DEFUN([gl_PREREQ_RANDOM], [ |
| 80 |
: |
| 81 |
]) |