Debian Codegraph @

m4/error_h.m4

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