immutable: Add tests.
[gnulib.git] / m4 / rintl.m4
bloba67b63cc3192c176974bf1a8d9298c7098df1331
1 # rintl.m4 serial 8
2 dnl Copyright (C) 2011-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_RINTL],
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   dnl Persuade glibc <math.h> to declare rintl().
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15   dnl Determine RINTL_LIBM.
16   gl_MATHFUNC([rintl], [long double], [(long double)])
17   if test $gl_cv_func_rintl_no_libm = yes \
18      || test $gl_cv_func_rintl_in_libm = yes; then
19     if test $REPLACE_RINTL = 0; then
20       AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
21       AC_CACHE_CHECK([whether rintl works],
22         [gl_cv_func_rintl_works],
23         [
24           save_LIBS="$LIBS"
25           LIBS="$LIBS $RINTL_LIBM"
26           AC_RUN_IFELSE(
27             [AC_LANG_SOURCE([[
28 #include <math.h>
29 #undef rintl
30 extern
31 #ifdef __cplusplus
32 "C"
33 #endif
34 long double rintl (long double);
35 static long double dummy (long double x) { return 0; }
36 int main (int argc, char *argv[])
38   long double (* volatile my_rintl) (long double) = argc ? rintl : dummy;
39   int result = 0;
40   /* This test fails on NetBSD 9.0.  */
41   {
42     volatile long double x = -0.3L;
43     long double y = my_rintl (x);
44     if (!(y == 0.0L))
45       result |= 1;
46   }
47   return result;
49             ]])],
50             [gl_cv_func_rintl_works=yes],
51             [gl_cv_func_rintl_works=no],
52             [case "$host_os" in
53                               # Guess yes on glibc systems.
54                *-gnu* | gnu*) gl_cv_func_rintl_works="guessing yes" ;;
55                               # Guess yes on musl systems.
56                *-musl*)       gl_cv_func_rintl_works="guessing yes" ;;
57                               # Guess yes on native Windows.
58                mingw*)        gl_cv_func_rintl_works="guessing yes" ;;
59                               # If we don't know, obey --enable-cross-guesses.
60                *)             gl_cv_func_rintl_works="$gl_cross_guess_normal" ;;
61              esac
62             ])
63           LIBS="$save_LIBS"
64         ])
65       case "$gl_cv_func_rintl_works" in
66         *yes) ;;
67         *) REPLACE_RINTL=1 ;;
68       esac
69     fi
70   else
71     HAVE_RINTL=0
72   fi
73   if test $HAVE_RINTL = 0 || test $REPLACE_RINTL = 1; then
74     dnl Find libraries needed to link lib/rintl.c.
75     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
76       AC_REQUIRE([gl_FUNC_RINT])
77       RINTL_LIBM="$RINT_LIBM"
78     else
79       RINTL_LIBM=
80     fi
81   fi
82   AC_SUBST([RINTL_LIBM])