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