diff options
Diffstat (limited to 'gl/m4/error_h.m4')
| -rw-r--r-- | gl/m4/error_h.m4 | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/gl/m4/error_h.m4 b/gl/m4/error_h.m4 new file mode 100644 index 00000000..4ef5cbff --- /dev/null +++ b/gl/m4/error_h.m4 | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | # error_h.m4 | ||
| 2 | # serial 5 | ||
| 3 | dnl Copyright (C) 1996-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 From Bruno Haible. | ||
| 10 | dnl Provide a working <error.h>. | ||
| 11 | |||
| 12 | AC_DEFUN_ONCE([gl_ERROR_H], | ||
| 13 | [ | ||
| 14 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles | ||
| 15 | |||
| 16 | gl_CHECK_NEXT_HEADERS([error.h]) | ||
| 17 | if test $ac_cv_header_error_h = yes; then | ||
| 18 | HAVE_ERROR_H=1 | ||
| 19 | else | ||
| 20 | HAVE_ERROR_H=0 | ||
| 21 | fi | ||
| 22 | AC_SUBST([HAVE_ERROR_H]) | ||
| 23 | |||
| 24 | REPLACE_ERROR=0 | ||
| 25 | |||
| 26 | gl_CHECK_FUNCS_ANDROID([error], [[#include <error.h>]]) | ||
| 27 | if test $ac_cv_func_error = yes; then | ||
| 28 | HAVE_ERROR=1 | ||
| 29 | else | ||
| 30 | HAVE_ERROR=0 | ||
| 31 | case "$gl_cv_onwards_func_error" in | ||
| 32 | future*) REPLACE_ERROR=1 ;; | ||
| 33 | esac | ||
| 34 | fi | ||
| 35 | |||
| 36 | dnl We don't use AC_FUNC_ERROR_AT_LINE any more, because it is no longer | ||
| 37 | dnl maintained in Autoconf and because it invokes AC_LIBOBJ. | ||
| 38 | dnl We need to notice a missing declaration, like gl_CHECK_FUNCS_ANDROID does. | ||
| 39 | AC_CHECK_DECL([error_at_line], , , [[#include <error.h>]]) | ||
| 40 | if test $ac_cv_have_decl_error_at_line = yes; then | ||
| 41 | AC_CACHE_CHECK([for error_at_line], [ac_cv_lib_error_at_line], | ||
| 42 | [AC_LINK_IFELSE( | ||
| 43 | [AC_LANG_PROGRAM( | ||
| 44 | [[#include <error.h>]], | ||
| 45 | [[error_at_line (0, 0, "", 0, "an error occurred");]])], | ||
| 46 | [ac_cv_lib_error_at_line=yes], | ||
| 47 | [ac_cv_lib_error_at_line=no])]) | ||
| 48 | else | ||
| 49 | ac_cv_lib_error_at_line=no | ||
| 50 | fi | ||
| 51 | if test $ac_cv_lib_error_at_line = yes; then | ||
| 52 | HAVE_ERROR_AT_LINE=1 | ||
| 53 | else | ||
| 54 | HAVE_ERROR_AT_LINE=0 | ||
| 55 | fi | ||
| 56 | REPLACE_ERROR_AT_LINE=0 | ||
| 57 | |||
| 58 | if test $ac_cv_func_error = yes && test $ac_cv_lib_error_at_line = yes; then | ||
| 59 | dnl On Android 11, when error_print_progname is set, the output of the | ||
| 60 | dnl error() function contains an extra space. | ||
| 61 | AC_CACHE_CHECK([for working error function], | ||
| 62 | [gl_cv_func_working_error], | ||
| 63 | [if test $cross_compiling != yes; then | ||
| 64 | AC_LINK_IFELSE( | ||
| 65 | [AC_LANG_PROGRAM([[ | ||
| 66 | #include <error.h> | ||
| 67 | static void print_no_progname (void) {} | ||
| 68 | ]], [[ | ||
| 69 | error_print_progname = print_no_progname; | ||
| 70 | error (0, 0, "foo"); | ||
| 71 | ]]) | ||
| 72 | ], | ||
| 73 | [rm -f conftest.out | ||
| 74 | if test -s conftest$ac_exeext \ | ||
| 75 | && ./conftest$ac_exeext 2> conftest.out; then | ||
| 76 | if grep ' ' conftest.out >/dev/null; then | ||
| 77 | gl_cv_func_working_error=no | ||
| 78 | else | ||
| 79 | gl_cv_func_working_error=yes | ||
| 80 | fi | ||
| 81 | else | ||
| 82 | gl_cv_func_working_error=no | ||
| 83 | fi | ||
| 84 | rm -f conftest.out | ||
| 85 | ], | ||
| 86 | [gl_cv_func_working_error=no]) | ||
| 87 | else | ||
| 88 | AC_COMPILE_IFELSE( | ||
| 89 | [AC_LANG_PROGRAM([[ | ||
| 90 | #include <error.h> | ||
| 91 | ]], [[ | ||
| 92 | error (0, 0, "foo"); | ||
| 93 | ]]) | ||
| 94 | ], | ||
| 95 | [case "$host_os" in | ||
| 96 | # Guess yes on glibc systems. | ||
| 97 | *-gnu* | gnu*) gl_cv_func_working_error="guessing yes" ;; | ||
| 98 | # Guess no on Android. | ||
| 99 | linux*-android*) gl_cv_func_working_error="guessing no" ;; | ||
| 100 | # If we don't know, obey --enable-cross-guesses. | ||
| 101 | *) gl_cv_func_working_error="$gl_cross_guess_normal" ;; | ||
| 102 | esac | ||
| 103 | ], | ||
| 104 | [gl_cv_func_working_error=no]) | ||
| 105 | fi | ||
| 106 | ]) | ||
| 107 | case "$gl_cv_func_working_error" in | ||
| 108 | *no) | ||
| 109 | REPLACE_ERROR=1 | ||
| 110 | REPLACE_ERROR_AT_LINE=1 | ||
| 111 | ;; | ||
| 112 | esac | ||
| 113 | fi | ||
| 114 | |||
| 115 | m4_ifdef([gl_HAVE_MODULE_VERROR], | ||
| 116 | [COMPILE_ERROR_C=1], | ||
| 117 | [if test $HAVE_ERROR = 0 || test $REPLACE_ERROR = 1 \ | ||
| 118 | || test $HAVE_ERROR_AT_LINE = 0 \ | ||
| 119 | || test $REPLACE_ERROR_AT_LINE = 1; then | ||
| 120 | COMPILE_ERROR_C=1 | ||
| 121 | else | ||
| 122 | COMPILE_ERROR_C=0 | ||
| 123 | fi]) | ||
| 124 | |||
| 125 | AC_SUBST([HAVE_ERROR]) | ||
| 126 | AC_SUBST([HAVE_ERROR_AT_LINE]) | ||
| 127 | AC_SUBST([REPLACE_ERROR]) | ||
| 128 | AC_SUBST([REPLACE_ERROR_AT_LINE]) | ||
| 129 | ]) | ||
