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