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