summaryrefslogtreecommitdiff
path: root/gnulib-m4/stdckdint_h.m4
blob: d269faa5c928b6e76aa0c9ec558b31ac2e839dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# stdckdint_h.m4
# serial 1
dnl Copyright 2025 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl This file is offered as-is, without any warranty.

dnl Written by Collin Funk.

AC_DEFUN_ONCE([gl_STDCKDINT_H],
[
  gl_CHECK_NEXT_HEADERS([stdckdint.h])
  if test $ac_cv_header_stdckdint_h = yes; then
    HAVE_STDCKDINT_H=1
  else
    HAVE_STDCKDINT_H=0
  fi
  AC_SUBST([HAVE_STDCKDINT_H])

  if test $HAVE_STDCKDINT_H = 1; then
    AC_CACHE_CHECK([whether stdckdint.h can be included in C],
      [gl_cv_header_c_stdckdint_h],
      [AC_COMPILE_IFELSE(
         [AC_LANG_PROGRAM(
            [[#include <stdckdint.h>
            ]])],
         [gl_cv_header_c_stdckdint_h=yes],
         [gl_cv_header_c_stdckdint_h=no])])
    if test $gl_cv_header_c_stdckdint_h = yes; then
      HAVE_C_STDCKDINT_H=1
      AC_CACHE_CHECK([checking for an ISO C23 compliant stdckdint.h in C],
        [gl_cv_header_c_stdckdint_h_works],
        [AC_COMPILE_IFELSE(
           [AC_LANG_PROGRAM(
              [[#include <stdckdint.h>
              ]],
              [[int r;
                int a = 1;
                int b = 1;
                return !!(ckd_add (&r, a, b) || ckd_sub (&r, a, b)
                          || ckd_mul (&r, a, b));
              ]])],
           [gl_cv_header_c_stdckdint_h_works=yes],
           [gl_cv_header_c_stdckdint_h_works=no])])
      if test $gl_cv_header_c_stdckdint_h_works = yes; then
        HAVE_WORKING_C_STDCKDINT_H=1
      else
        HAVE_WORKING_C_STDCKDINT_H=0
      fi
    else
      HAVE_C_STDCKDINT_H=0
      HAVE_WORKING_C_STDCKDINT_H=0
    fi
    if test "$CXX" != no; then
      AC_CACHE_CHECK([whether stdckdint.h can be included in C++],
        [gl_cv_header_cxx_stdckdint_h],
        [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
         dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
         cat > conftest.cpp <<\EOF
#include <stdckdint.h>
EOF
         gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
         if AC_TRY_EVAL([gl_command]); then
           gl_cv_header_cxx_stdckdint_h=yes
         else
           gl_cv_header_cxx_stdckdint_h=no
         fi
         rm -fr conftest*
        ])
      if test $gl_cv_header_cxx_stdckdint_h = yes; then
        HAVE_CXX_STDCKDINT_H=1
        AC_CACHE_CHECK([checking for an ISO C++26 compliant stdckdint.h in C++],
          [gl_cv_header_cxx_stdckdint_h_works],
          [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to
           dnl an autoconf bug <https://savannah.gnu.org/support/?110294>.
           cat > conftest.cpp <<\EOF
#include <stdckdint.h>
int
main (void)
{
  int r;
  int a = 1;
  int b = 1;
  return !!(ckd_add (&r, a, b) || ckd_sub (&r, a, b) || ckd_mul (&r, a, b));
}
EOF
           gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp"
           if AC_TRY_EVAL([gl_command]); then
             gl_cv_header_cxx_stdckdint_h_works=yes
           else
             gl_cv_header_cxx_stdckdint_h_works=no
           fi
           rm -fr conftest*
          ])
        if test $gl_cv_header_cxx_stdckdint_h_works = yes; then
          HAVE_WORKING_CXX_STDCKDINT_H=1
        else
          HAVE_WORKING_CXX_STDCKDINT_H=0
        fi
      else
        HAVE_CXX_STDCKDINT_H=0
        HAVE_WORKING_CXX_STDCKDINT_H=0
      fi
    fi
  else
    HAVE_C_STDCKDINT_H=0
    HAVE_WORKING_C_STDCKDINT_H=0
    HAVE_CXX_STDCKDINT_H=0
    HAVE_WORKING_CXX_STDCKDINT_H=0
  fi
  AC_SUBST([HAVE_C_STDCKDINT_H])
  AC_SUBST([HAVE_WORKING_C_STDCKDINT_H])
  AC_SUBST([HAVE_CXX_STDCKDINT_H])
  AC_SUBST([HAVE_WORKING_CXX_STDCKDINT_H])

  if test "$CXX" != no; then
    dnl We might need the header for C or C++.
    if test $HAVE_C_STDCKDINT_H = 1 \
       && test $HAVE_WORKING_C_STDCKDINT_H = 1 \
       && test $HAVE_CXX_STDCKDINT_H = 1 \
       && test $HAVE_WORKING_CXX_STDCKDINT_H = 1; then
      GL_GENERATE_STDCKDINT_H=false
    else
      GL_GENERATE_STDCKDINT_H=true
    fi
  else
    dnl We don't care about C++ here.
    if test $HAVE_C_STDCKDINT_H = 1 \
       && test $HAVE_WORKING_C_STDCKDINT_H = 1; then
      GL_GENERATE_STDCKDINT_H=false
    else
      GL_GENERATE_STDCKDINT_H=true
    fi
  fi
])