diff options
Diffstat (limited to 'gl/m4/stdckdint_h.m4')
| -rw-r--r-- | gl/m4/stdckdint_h.m4 | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/gl/m4/stdckdint_h.m4 b/gl/m4/stdckdint_h.m4 new file mode 100644 index 00000000..d269faa5 --- /dev/null +++ b/gl/m4/stdckdint_h.m4 | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | # stdckdint_h.m4 | ||
| 2 | # serial 1 | ||
| 3 | dnl Copyright 2025 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. | ||
| 7 | dnl This file is offered as-is, without any warranty. | ||
| 8 | |||
| 9 | dnl Written by Collin Funk. | ||
| 10 | |||
| 11 | AC_DEFUN_ONCE([gl_STDCKDINT_H], | ||
| 12 | [ | ||
| 13 | gl_CHECK_NEXT_HEADERS([stdckdint.h]) | ||
| 14 | if test $ac_cv_header_stdckdint_h = yes; then | ||
| 15 | HAVE_STDCKDINT_H=1 | ||
| 16 | else | ||
| 17 | HAVE_STDCKDINT_H=0 | ||
| 18 | fi | ||
| 19 | AC_SUBST([HAVE_STDCKDINT_H]) | ||
| 20 | |||
| 21 | if test $HAVE_STDCKDINT_H = 1; then | ||
| 22 | AC_CACHE_CHECK([whether stdckdint.h can be included in C], | ||
| 23 | [gl_cv_header_c_stdckdint_h], | ||
| 24 | [AC_COMPILE_IFELSE( | ||
| 25 | [AC_LANG_PROGRAM( | ||
| 26 | [[#include <stdckdint.h> | ||
| 27 | ]])], | ||
| 28 | [gl_cv_header_c_stdckdint_h=yes], | ||
| 29 | [gl_cv_header_c_stdckdint_h=no])]) | ||
| 30 | if test $gl_cv_header_c_stdckdint_h = yes; then | ||
| 31 | HAVE_C_STDCKDINT_H=1 | ||
| 32 | AC_CACHE_CHECK([checking for an ISO C23 compliant stdckdint.h in C], | ||
| 33 | [gl_cv_header_c_stdckdint_h_works], | ||
| 34 | [AC_COMPILE_IFELSE( | ||
| 35 | [AC_LANG_PROGRAM( | ||
| 36 | [[#include <stdckdint.h> | ||
| 37 | ]], | ||
| 38 | [[int r; | ||
| 39 | int a = 1; | ||
| 40 | int b = 1; | ||
| 41 | return !!(ckd_add (&r, a, b) || ckd_sub (&r, a, b) | ||
| 42 | || ckd_mul (&r, a, b)); | ||
| 43 | ]])], | ||
| 44 | [gl_cv_header_c_stdckdint_h_works=yes], | ||
| 45 | [gl_cv_header_c_stdckdint_h_works=no])]) | ||
| 46 | if test $gl_cv_header_c_stdckdint_h_works = yes; then | ||
| 47 | HAVE_WORKING_C_STDCKDINT_H=1 | ||
| 48 | else | ||
| 49 | HAVE_WORKING_C_STDCKDINT_H=0 | ||
| 50 | fi | ||
| 51 | else | ||
| 52 | HAVE_C_STDCKDINT_H=0 | ||
| 53 | HAVE_WORKING_C_STDCKDINT_H=0 | ||
| 54 | fi | ||
| 55 | if test "$CXX" != no; then | ||
| 56 | AC_CACHE_CHECK([whether stdckdint.h can be included in C++], | ||
| 57 | [gl_cv_header_cxx_stdckdint_h], | ||
| 58 | [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to | ||
| 59 | dnl an autoconf bug <https://savannah.gnu.org/support/?110294>. | ||
| 60 | cat > conftest.cpp <<\EOF | ||
| 61 | #include <stdckdint.h> | ||
| 62 | EOF | ||
| 63 | gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp" | ||
| 64 | if AC_TRY_EVAL([gl_command]); then | ||
| 65 | gl_cv_header_cxx_stdckdint_h=yes | ||
| 66 | else | ||
| 67 | gl_cv_header_cxx_stdckdint_h=no | ||
| 68 | fi | ||
| 69 | rm -fr conftest* | ||
| 70 | ]) | ||
| 71 | if test $gl_cv_header_cxx_stdckdint_h = yes; then | ||
| 72 | HAVE_CXX_STDCKDINT_H=1 | ||
| 73 | AC_CACHE_CHECK([checking for an ISO C++26 compliant stdckdint.h in C++], | ||
| 74 | [gl_cv_header_cxx_stdckdint_h_works], | ||
| 75 | [dnl We can't use AC_LANG_PUSH([C++]) and AC_LANG_POP([C++]) here, due to | ||
| 76 | dnl an autoconf bug <https://savannah.gnu.org/support/?110294>. | ||
| 77 | cat > conftest.cpp <<\EOF | ||
| 78 | #include <stdckdint.h> | ||
| 79 | int | ||
| 80 | main (void) | ||
| 81 | { | ||
| 82 | int r; | ||
| 83 | int a = 1; | ||
| 84 | int b = 1; | ||
| 85 | return !!(ckd_add (&r, a, b) || ckd_sub (&r, a, b) || ckd_mul (&r, a, b)); | ||
| 86 | } | ||
| 87 | EOF | ||
| 88 | gl_command="$CXX $CXXFLAGS $CPPFLAGS -c conftest.cpp" | ||
| 89 | if AC_TRY_EVAL([gl_command]); then | ||
| 90 | gl_cv_header_cxx_stdckdint_h_works=yes | ||
| 91 | else | ||
| 92 | gl_cv_header_cxx_stdckdint_h_works=no | ||
| 93 | fi | ||
| 94 | rm -fr conftest* | ||
| 95 | ]) | ||
| 96 | if test $gl_cv_header_cxx_stdckdint_h_works = yes; then | ||
| 97 | HAVE_WORKING_CXX_STDCKDINT_H=1 | ||
| 98 | else | ||
| 99 | HAVE_WORKING_CXX_STDCKDINT_H=0 | ||
| 100 | fi | ||
| 101 | else | ||
| 102 | HAVE_CXX_STDCKDINT_H=0 | ||
| 103 | HAVE_WORKING_CXX_STDCKDINT_H=0 | ||
| 104 | fi | ||
| 105 | fi | ||
| 106 | else | ||
| 107 | HAVE_C_STDCKDINT_H=0 | ||
| 108 | HAVE_WORKING_C_STDCKDINT_H=0 | ||
| 109 | HAVE_CXX_STDCKDINT_H=0 | ||
| 110 | HAVE_WORKING_CXX_STDCKDINT_H=0 | ||
| 111 | fi | ||
| 112 | AC_SUBST([HAVE_C_STDCKDINT_H]) | ||
| 113 | AC_SUBST([HAVE_WORKING_C_STDCKDINT_H]) | ||
| 114 | AC_SUBST([HAVE_CXX_STDCKDINT_H]) | ||
| 115 | AC_SUBST([HAVE_WORKING_CXX_STDCKDINT_H]) | ||
| 116 | |||
| 117 | if test "$CXX" != no; then | ||
| 118 | dnl We might need the header for C or C++. | ||
| 119 | if test $HAVE_C_STDCKDINT_H = 1 \ | ||
| 120 | && test $HAVE_WORKING_C_STDCKDINT_H = 1 \ | ||
| 121 | && test $HAVE_CXX_STDCKDINT_H = 1 \ | ||
| 122 | && test $HAVE_WORKING_CXX_STDCKDINT_H = 1; then | ||
| 123 | GL_GENERATE_STDCKDINT_H=false | ||
| 124 | else | ||
| 125 | GL_GENERATE_STDCKDINT_H=true | ||
| 126 | fi | ||
| 127 | else | ||
| 128 | dnl We don't care about C++ here. | ||
| 129 | if test $HAVE_C_STDCKDINT_H = 1 \ | ||
| 130 | && test $HAVE_WORKING_C_STDCKDINT_H = 1; then | ||
| 131 | GL_GENERATE_STDCKDINT_H=false | ||
| 132 | else | ||
| 133 | GL_GENERATE_STDCKDINT_H=true | ||
| 134 | fi | ||
| 135 | fi | ||
| 136 | ]) | ||
