Debian Codegraph @

m4/error_h.m4

raw
1 # error_h.m4
2 # serial 6
3 dnl Copyright (C) 1996-2026 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 #include <signal.h>
68 #ifdef SIGALRM
69 # include <unistd.h> /* for alarm */
70 #endif
71 static void print_no_progname (void) {}
72 ]], [[
73 /* error (0, 0, ...) infloops on Intel OneAPI icx 2025.3.2. */
74 #ifdef SIGALRM
75 signal (SIGALRM, SIG_DFL);
76 alarm (2);
77 #endif
78
79 error_print_progname = print_no_progname;
80 error (0, 0, "foo");
81 ]])
82 ],
83 [rm -f conftest.out
84 if test -s conftest$ac_exeext \
85 && ./conftest$ac_exeext 2> conftest.out; then
86 if grep ' ' conftest.out >/dev/null; then
87 gl_cv_func_working_error=no
88 else
89 gl_cv_func_working_error=yes
90 fi
91 else
92 gl_cv_func_working_error=no
93 fi
94 rm -f conftest.out
95 ],
96 [gl_cv_func_working_error=no])
97 else
98 AC_COMPILE_IFELSE(
99 [AC_LANG_PROGRAM([[
100 #include <error.h>
101 ]], [[
102 error (0, 0, "foo");
103 ]])
104 ],
105 [case "$host_os" in
106 # Guess yes on glibc systems.
107 *-gnu* | gnu*) gl_cv_func_working_error="guessing yes" ;;
108 # Guess no on Android.
109 linux*-android*) gl_cv_func_working_error="guessing no" ;;
110 # If we don't know, obey --enable-cross-guesses.
111 *) gl_cv_func_working_error="$gl_cross_guess_normal" ;;
112 esac
113 ],
114 [gl_cv_func_working_error=no])
115 fi
116 ])
117 case "$gl_cv_func_working_error" in
118 *no)
119 REPLACE_ERROR=1
120 REPLACE_ERROR_AT_LINE=1
121 ;;
122 esac
123 fi
124
125 m4_ifdef([gl_HAVE_MODULE_VERROR],
126 [COMPILE_ERROR_C=1],
127 [if test $HAVE_ERROR = 0 || test $REPLACE_ERROR = 1 \
128 || test $HAVE_ERROR_AT_LINE = 0 \
129 || test $REPLACE_ERROR_AT_LINE = 1; then
130 COMPILE_ERROR_C=1
131 else
132 COMPILE_ERROR_C=0
133 fi])
134
135 AC_SUBST([HAVE_ERROR])
136 AC_SUBST([HAVE_ERROR_AT_LINE])
137 AC_SUBST([REPLACE_ERROR])
138 AC_SUBST([REPLACE_ERROR_AT_LINE])
139 ])