00gnulib.m4 3.5 KB

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