rintl: Override broken implementation on NetBSD.
[gnulib.git] / m4 / rintl.m4
blob66831191e47eeb179ad774e8bf7ac89194546bb9
1 # rintl.m4 serial 5
2 dnl Copyright (C) 2011-2019 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 8.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 native Windows.
56                mingw*)        gl_cv_func_rintl_works="guessing yes" ;;
57                               # If we don't know, assume the worst.
58                *)             gl_cv_func_rintl_works="guessing no" ;;
59              esac
60             ])
61           LIBS="$save_LIBS"
62         ])
63       case "$gl_cv_func_rintl_works" in
64         *yes) ;;
65         *) REPLACE_RINTL=1 ;;
66       esac
67     fi
68   else
69     HAVE_RINTL=0
70   fi
71   if test $HAVE_RINTL = 0 || test $REPLACE_RINTL = 1; then
72     dnl Find libraries needed to link lib/rintl.c.
73     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
74       AC_REQUIRE([gl_FUNC_RINT])
75       RINTL_LIBM="$RINT_LIBM"
76     else
77       RINTL_LIBM=
78     fi
79   fi
80   AC_SUBST([RINTL_LIBM])