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