git-merge-changelog: Simplify installation instructions.
[gnulib.git] / m4 / float_h.m4
blobc95d417161910bbe7eaf8453797b80ce37abd93c
1 # float_h.m4
2 # serial 14
3 dnl Copyright (C) 2007, 2009-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_FLOAT_H],
10   AC_REQUIRE([AC_PROG_CC])
11   AC_REQUIRE([AC_CANONICAL_HOST])
12   GL_GENERATE_FLOAT_H=false
13   REPLACE_FLOAT_LDBL=0
14   case "$host_os" in
15     aix* | beos* | openbsd* | mirbsd* | irix*)
16       GL_GENERATE_FLOAT_H=true
17       ;;
18     freebsd* | dragonfly*)
19       case "$host_cpu" in
20 changequote(,)dnl
21         i[34567]86 )
22 changequote([,])dnl
23           GL_GENERATE_FLOAT_H=true
24           ;;
25         x86_64 )
26           # On x86_64 systems, the C compiler may still be generating
27           # 32-bit code.
28           AC_COMPILE_IFELSE(
29             [AC_LANG_SOURCE(
30                [[#if defined __LP64__ || defined __x86_64__ || defined __amd64__
31                   int ok;
32                  #else
33                   error fail
34                  #endif
35                ]])],
36             [],
37             [GL_GENERATE_FLOAT_H=true])
38           ;;
39       esac
40       ;;
41     linux*)
42       case "$host_cpu" in
43         powerpc*)
44           GL_GENERATE_FLOAT_H=true
45           ;;
46       esac
47       ;;
48   esac
49   case "$host_os" in
50     aix* | freebsd* | dragonfly* | linux*)
51       if $GL_GENERATE_FLOAT_H; then
52         REPLACE_FLOAT_LDBL=1
53       fi
54       ;;
55   esac
57   dnl Test against glibc-2.7 Linux/SPARC64 bug.
58   REPLACE_ITOLD=0
59   AC_CACHE_CHECK([whether conversion from 'int' to 'long double' works],
60     [gl_cv_func_itold_works],
61     [
62       AC_RUN_IFELSE(
63         [AC_LANG_SOURCE([[
64 int i = -1;
65 volatile long double ld;
66 int main ()
68   ld += i * 1.0L;
69   if (ld > 0)
70     return 1;
71   return 0;
72 }]])],
73         [gl_cv_func_itold_works=yes],
74         [gl_cv_func_itold_works=no],
75         [case "$host" in
76            sparc*-*-linux*)
77              AC_COMPILE_IFELSE(
78                [AC_LANG_SOURCE(
79                  [[#if defined __LP64__ || defined __arch64__
80                     int ok;
81                    #else
82                     error fail
83                    #endif
84                  ]])],
85                [gl_cv_func_itold_works="guessing no"],
86                [gl_cv_func_itold_works="guessing yes"])
87              ;;
88              # Guess yes on native Windows.
89            mingw* | windows*)
90              gl_cv_func_itold_works="guessing yes" ;;
91            *)
92              gl_cv_func_itold_works="guessing yes" ;;
93          esac
94         ])
95     ])
96   case "$gl_cv_func_itold_works" in
97     *no)
98       REPLACE_ITOLD=1
99       dnl We add the workaround to <float.h> but also to <math.h>,
100       dnl to increase the chances that the fix function gets pulled in.
101       GL_GENERATE_FLOAT_H=true
102       ;;
103   esac
105   if $GL_GENERATE_FLOAT_H; then
106     gl_NEXT_HEADERS([float.h])
107   fi
108   AC_SUBST([REPLACE_ITOLD])