Debian Codegraph @

m4/00gnulib.m4

raw
1 # 00gnulib.m4
2 # serial 9
3 dnl Copyright (C) 2009-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.
7 dnl This file is offered as-is, without any warranty.
8
9 dnl This file must be named something that sorts before all other
10 dnl gnulib-provided .m4 files. It is needed until the clang fix has
11 dnl been included in Autoconf.
12
13 # The following definitions arrange to use a compiler option
14 # -Werror=implicit-function-declaration in AC_CHECK_DECL, when the
15 # compiler is clang. Without it, clang implicitly declares "known"
16 # library functions in C mode, but not in C++ mode, which would cause
17 # Gnulib to omit a declaration and thus later produce an error in C++
18 # mode. As of clang 9.0, these "known" functions are identified through
19 # LIBBUILTIN invocations in the LLVM source file
20 # llvm/tools/clang/include/clang/Basic/Builtins.def.
21 # It's not possible to AC_REQUIRE the extra tests from AC_CHECK_DECL,
22 # because AC_CHECK_DECL, like other Autoconf built-ins, is not supposed
23 # to AC_REQUIRE anything: some configure.ac files have their first
24 # AC_CHECK_DECL executed conditionally. Therefore append the extra tests
25 # to AC_PROG_CC.
26 AC_DEFUN([gl_COMPILER_CLANG],
27 [
28 dnl AC_REQUIRE([AC_PROG_CC])
29 AC_CACHE_CHECK([whether the compiler is clang],
30 [gl_cv_compiler_clang],
31 [dnl Use _AC_COMPILE_IFELSE instead of AC_EGREP_CPP, to avoid error
32 dnl "circular dependency of AC_LANG_COMPILER(C)" if AC_PROG_CC has
33 dnl not yet been invoked.
34 _AC_COMPILE_IFELSE(
35 [AC_LANG_PROGRAM([[
36 #ifdef __clang__
37 barfbarf
38 #endif
39 ]],[[]])
40 ],
41 [gl_cv_compiler_clang=no],
42 [gl_cv_compiler_clang=yes])
43 ])
44 ])
45 AC_DEFUN([gl_COMPILER_PREPARE_CHECK_DECL],
46 [
47 dnl AC_REQUIRE([AC_PROG_CC])
48 dnl AC_REQUIRE([gl_COMPILER_CLANG])
49 AC_CACHE_CHECK([for compiler option needed when checking for declarations],
50 [gl_cv_compiler_check_decl_option],
51 [if test $gl_cv_compiler_clang = yes; then
52 dnl Test whether the compiler supports the option
53 dnl '-Werror=implicit-function-declaration'.
54 saved_ac_compile="$ac_compile"
55 ac_compile="$ac_compile -Werror=implicit-function-declaration"
56 dnl Use _AC_COMPILE_IFELSE instead of AC_COMPILE_IFELSE, to avoid a
57 dnl warning "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
58 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
59 [gl_cv_compiler_check_decl_option='-Werror=implicit-function-declaration'],
60 [gl_cv_compiler_check_decl_option=none])
61 ac_compile="$saved_ac_compile"
62 else
63 gl_cv_compiler_check_decl_option=none
64 fi
65 ])
66 if test "x$gl_cv_compiler_check_decl_option" != xnone; then
67 ac_compile_for_check_decl="$ac_compile $gl_cv_compiler_check_decl_option"
68 else
69 ac_compile_for_check_decl="$ac_compile"
70 fi
71 ])
72 dnl Redefine _AC_CHECK_DECL_BODY so that it references ac_compile_for_check_decl
73 dnl instead of ac_compile. If, for whatever reason, the override of AC_PROG_CC
74 dnl in zzgnulib.m4 is inactive, use the original ac_compile.
75 m4_define([_AC_CHECK_DECL_BODY],
76 [ ac_saved_ac_compile="$ac_compile"
77 if test -n "$ac_compile_for_check_decl"; then
78 ac_compile="$ac_compile_for_check_decl"
79 fi]
80 m4_defn([_AC_CHECK_DECL_BODY])[ ac_compile="$ac_saved_ac_compile"
81 ])
82
83 # gl_00GNULIB
84 # -----------
85 # Witness macro that this file has been included. Needed to force
86 # Automake to include this file prior to all other gnulib .m4 files.
87 AC_DEFUN([gl_00GNULIB])