Commit | Line | Data |
---|---|---|
5df4cba6 SM |
1 | # 00gnulib.m4 serial 7 |
2 | dnl Copyright (C) 2009-2020 Free Software Foundation, Inc. | |
f434ba03 PA |
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 This file must be named something that sorts before all other | |
5df4cba6 SM |
8 | dnl gnulib-provided .m4 files. The first part is needed until such time |
9 | dnl as we can assume Autoconf 2.64, with its improved AC_DEFUN_ONCE and | |
10 | dnl m4_divert semantics. The second part is needed until the clang fix | |
11 | dnl has been included in Autoconf. | |
4a626d0a PA |
12 | |
13 | # Until autoconf 2.63, handling of the diversion stack required m4_init | |
14 | # to be called first; but this does not happen with aclocal. Wrapping | |
15 | # the entire execution in another layer of the diversion stack fixes this. | |
16 | # Worse, prior to autoconf 2.62, m4_wrap depended on the underlying m4 | |
17 | # for whether it was FIFO or LIFO; in order to properly balance with | |
18 | # m4_init, we need to undo our push just before anything wrapped within | |
19 | # the m4_init body. The way to ensure this is to wrap both sides of | |
20 | # m4_init with a one-shot macro that does the pop at the right time. | |
21 | m4_ifndef([_m4_divert_diversion], | |
22 | [m4_divert_push([KILL]) | |
23 | m4_define([gl_divert_fixup], [m4_divert_pop()m4_define([$0])]) | |
24 | m4_define([m4_init], | |
25 | [gl_divert_fixup()]m4_defn([m4_init])[gl_divert_fixup()])]) | |
26 | ||
f434ba03 PA |
27 | |
28 | # AC_DEFUN_ONCE([NAME], VALUE) | |
29 | # ---------------------------- | |
30 | # Define NAME to expand to VALUE on the first use (whether by direct | |
31 | # expansion, or by AC_REQUIRE), and to nothing on all subsequent uses. | |
32 | # Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier. This | |
33 | # definition is slower than the version in Autoconf 2.64, because it | |
34 | # can only use interfaces that existed since 2.59; but it achieves the | |
35 | # same effect. Quoting is necessary to avoid confusing Automake. | |
36 | m4_version_prereq([2.63.263], [], | |
37 | [m4_define([AC][_DEFUN_ONCE], | |
38 | [AC][_DEFUN([$1], | |
39 | [AC_REQUIRE([_gl_DEFUN_ONCE([$1])], | |
40 | [m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl | |
41 | [AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])]) | |
42 | ||
5df4cba6 SM |
43 | # The following definitions arrange to use a compiler option |
44 | # -Werror=implicit-function-declaration in AC_CHECK_DECL, when the | |
45 | # compiler is clang. Without it, clang implicitly declares "known" | |
46 | # library functions in C mode, but not in C++ mode, which would cause | |
47 | # Gnulib to omit a declaration and thus later produce an error in C++ | |
48 | # mode. As of clang 9.0, these "known" functions are identified through | |
49 | # LIBBUILTIN invocations in the LLVM source file | |
50 | # llvm/tools/clang/include/clang/Basic/Builtins.def. | |
51 | # It's not possible to AC_REQUIRE the extra tests from AC_CHECK_DECL, | |
52 | # because AC_CHECK_DECL, like other Autoconf built-ins, is not supposed | |
53 | # to AC_REQUIRE anything: some configure.ac files have their first | |
54 | # AC_CHECK_DECL executed conditionally. Therefore append the extra tests | |
55 | # to AC_PROG_CC. | |
56 | AC_DEFUN([gl_COMPILER_CLANG], | |
57 | [ | |
58 | dnl AC_REQUIRE([AC_PROG_CC]) | |
59 | AC_CACHE_CHECK([whether the compiler is clang], | |
60 | [gl_cv_compiler_clang], | |
61 | [dnl Use _AC_COMPILE_IFELSE instead of AC_EGREP_CPP, to avoid error | |
62 | dnl "circular dependency of AC_LANG_COMPILER(C)" if AC_PROG_CC has | |
63 | dnl not yet been invoked. | |
64 | _AC_COMPILE_IFELSE( | |
65 | [AC_LANG_PROGRAM([[ | |
66 | #ifdef __clang__ | |
67 | barfbarf | |
68 | #endif | |
69 | ]],[[]]) | |
70 | ], | |
71 | [gl_cv_compiler_clang=no], | |
72 | [gl_cv_compiler_clang=yes]) | |
73 | ]) | |
74 | ]) | |
75 | AC_DEFUN([gl_COMPILER_PREPARE_CHECK_DECL], | |
76 | [ | |
77 | dnl AC_REQUIRE([AC_PROG_CC]) | |
78 | dnl AC_REQUIRE([gl_COMPILER_CLANG]) | |
79 | AC_CACHE_CHECK([for compiler option needed when checking for declarations], | |
80 | [gl_cv_compiler_check_decl_option], | |
81 | [if test $gl_cv_compiler_clang = yes; then | |
82 | dnl Test whether the compiler supports the option | |
83 | dnl '-Werror=implicit-function-declaration'. | |
84 | save_ac_compile="$ac_compile" | |
85 | ac_compile="$ac_compile -Werror=implicit-function-declaration" | |
86 | dnl Use _AC_COMPILE_IFELSE instead of AC_COMPILE_IFELSE, to avoid a | |
87 | dnl warning "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS". | |
88 | _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])], | |
89 | [gl_cv_compiler_check_decl_option='-Werror=implicit-function-declaration'], | |
90 | [gl_cv_compiler_check_decl_option=none]) | |
91 | ac_compile="$save_ac_compile" | |
92 | else | |
93 | gl_cv_compiler_check_decl_option=none | |
94 | fi | |
95 | ]) | |
96 | if test "x$gl_cv_compiler_check_decl_option" != xnone; then | |
97 | ac_compile_for_check_decl="$ac_compile $gl_cv_compiler_check_decl_option" | |
98 | else | |
99 | ac_compile_for_check_decl="$ac_compile" | |
100 | fi | |
101 | ]) | |
102 | dnl Redefine _AC_CHECK_DECL_BODY so that it references ac_compile_for_check_decl | |
103 | dnl instead of ac_compile. If, for whatever reason, the override of AC_PROG_CC | |
104 | dnl in zzgnulib.m4 is inactive, use the original ac_compile. | |
105 | m4_define([_AC_CHECK_DECL_BODY], | |
106 | [ ac_save_ac_compile="$ac_compile" | |
107 | if test -n "$ac_compile_for_check_decl"; then | |
108 | ac_compile="$ac_compile_for_check_decl" | |
109 | fi] | |
110 | m4_defn([_AC_CHECK_DECL_BODY])[ ac_compile="$ac_save_ac_compile" | |
111 | ]) | |
112 | ||
f434ba03 PA |
113 | # gl_00GNULIB |
114 | # ----------- | |
115 | # Witness macro that this file has been included. Needed to force | |
116 | # Automake to include this file prior to all other gnulib .m4 files. | |
117 | AC_DEFUN([gl_00GNULIB]) |