immutable: Add tests.
[gnulib.git] / m4 / random.m4
blob39c62e97cdaddb0a6dfe42d99e56ac79302b76d3
1 # random.m4 serial 4
2 dnl Copyright (C) 2012-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.
7 AC_DEFUN([gl_FUNC_RANDOM],
9   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
11   dnl We can't use AC_CHECK_FUNC here, because random() is defined as a
12   dnl static inline function when compiling for Android 4.4 or older.
13   AC_CACHE_CHECK([for random], [gl_cv_func_random],
14     [AC_LINK_IFELSE(
15        [AC_LANG_PROGRAM(
16           [[#include <stdlib.h>]],
17           [[return random() == 0;]])
18        ],
19        [gl_cv_func_random=yes],
20        [gl_cv_func_random=no])
21     ])
22   if test $gl_cv_func_random = no; then
23     HAVE_RANDOM=0
24     HAVE_INITSTATE=0
25     HAVE_SETSTATE=0
26   else
27     AC_CHECK_FUNCS([initstate setstate])
28     if test $ac_cv_func_initstate = no; then
29       HAVE_INITSTATE=0
30     fi
31     if test $ac_cv_func_setstate = no; then
32       HAVE_SETSTATE=0
33     fi
34     if test $ac_cv_func_initstate = no || test $ac_cv_func_setstate = no; then
35       dnl In order to define initstate or setstate, we need to define all the
36       dnl functions at once.
37       REPLACE_RANDOM=1
38       if test $ac_cv_func_initstate = yes; then
39         REPLACE_INITSTATE=1
40       fi
41       if test $ac_cv_func_setstate = yes; then
42         REPLACE_SETSTATE=1
43       fi
44     fi
45   fi
47   AC_CHECK_DECLS_ONCE([initstate])
48   if test $ac_cv_have_decl_initstate = no; then
49     HAVE_DECL_INITSTATE=0
50   fi
52   AC_CHECK_DECLS_ONCE([setstate])
53   if test $ac_cv_have_decl_setstate = no; then
54     HAVE_DECL_SETSTATE=0
55   fi
58 # Prerequisites of lib/random.c.
59 AC_DEFUN([gl_PREREQ_RANDOM], [
60   :