havelib: Fix for Solaris 11 OpenIndiana and Solaris 11 OmniOS.
[gnulib.git] / m4 / gc-random.m4
bloba7812a3264193b51315069db350031ccd2f8e85f
1 # gc-random.m4 serial 9
2 dnl Copyright (C) 2005-2020 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_GC_RANDOM],
9   # Devices with randomness.
10   # FIXME: Are these the best defaults?
12   AC_REQUIRE([AC_CANONICAL_HOST])
14   case "$host_os" in
15     *mirbsd*)
16       NAME_OF_RANDOM_DEVICE="/dev/srandom"
17       NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/prandom"
18       NAME_OF_NONCE_DEVICE="/dev/urandom"
19       ;;
21     *irix* | *dec-osf* )
22       NAME_OF_RANDOM_DEVICE="/dev/random"
23       NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/random"
24       NAME_OF_NONCE_DEVICE="/dev/random"
25       ;;
27     *)
28       NAME_OF_RANDOM_DEVICE="/dev/random"
29       NAME_OF_PSEUDO_RANDOM_DEVICE="/dev/urandom"
30       NAME_OF_NONCE_DEVICE="/dev/urandom"
31       ;;
32   esac
34   AC_MSG_CHECKING([device with (strong) random data...])
35   AC_ARG_ENABLE([random-device],
36         AS_HELP_STRING([--enable-random-device],
37                 [device with (strong) randomness (for Nettle)]),
38         NAME_OF_RANDOM_DEVICE=$enableval)
39   AC_MSG_RESULT([$NAME_OF_RANDOM_DEVICE])
41   AC_MSG_CHECKING([device with pseudo random data...])
42   AC_ARG_ENABLE([pseudo-random-device],
43         AS_HELP_STRING([--enable-pseudo-random-device],
44                 [device with pseudo randomness (for Nettle)]),
45         NAME_OF_PSEUDO_RANDOM_DEVICE=$enableval)
46   AC_MSG_RESULT([$NAME_OF_PSEUDO_RANDOM_DEVICE])
48   AC_MSG_CHECKING([device with unpredictable data for nonces...])
49   AC_ARG_ENABLE([nonce-device],
50         AS_HELP_STRING([--enable-nonce-device],
51                 [device with unpredictable nonces (for Nettle)]),
52         NAME_OF_NONCE_DEVICE=$enableval)
53   AC_MSG_RESULT([$NAME_OF_NONCE_DEVICE])
55   if test "$cross_compiling" != yes; then
56     if test "$NAME_OF_RANDOM_DEVICE" != "no"; then
57       AC_CHECK_FILE([$NAME_OF_RANDOM_DEVICE],,
58         AC_MSG_WARN([[Device '$NAME_OF_RANDOM_DEVICE' does not exist, consider to use --enable-random-device]]))
59     fi
60     if test "$NAME_OF_PSEUDO_RANDOM_DEVICE" != "no"; then
61       AC_CHECK_FILE([$NAME_OF_PSEUDO_RANDOM_DEVICE],,
62         AC_MSG_WARN([[Device '$NAME_OF_PSEUDO_RANDOM_DEVICE' does not exist, consider to use --enable-pseudo-random-device]]))
63     fi
64     if test "$NAME_OF_NONCE_DEVICE" != "no"; then
65       AC_CHECK_FILE([$NAME_OF_NONCE_DEVICE],,
66         AC_MSG_WARN([[Device '$NAME_OF_NONCE_DEVICE' does not exist, consider to use --enable-nonce-device]]))
67     fi
68   else
69     AC_MSG_NOTICE([[Cross compiling, assuming random devices exists on the target host...]])
70   fi
72   # FIXME?: Open+read 42 bytes+close twice and compare data.  Should differ.
74   AC_DEFINE_UNQUOTED([NAME_OF_RANDOM_DEVICE], ["$NAME_OF_RANDOM_DEVICE"],
75                    [defined to the name of the (strong) random device])
76   AC_DEFINE_UNQUOTED([NAME_OF_PSEUDO_RANDOM_DEVICE],
77                          "$NAME_OF_PSEUDO_RANDOM_DEVICE",
78                    [defined to the name of the pseudo random device])
79   AC_DEFINE_UNQUOTED([NAME_OF_NONCE_DEVICE], ["$NAME_OF_NONCE_DEVICE"],
80                    [defined to the name of the unpredictable nonce device])
82   case $host_os in
83     mingw*)
84       LIB_GC_RANDOM='-ladvapi32' ;;
85     *)
86       LIB_GC_RANDOM= ;;
87   esac
88   AC_SUBST([LIB_GC_RANDOM])