Blame m4/00gnulib.m4

Packit Service 4684c1
# 00gnulib.m4 serial 7
Packit Service 4684c1
dnl Copyright (C) 2009-2020 Free Software Foundation, Inc.
Packit Service 4684c1
dnl This file is free software; the Free Software Foundation
Packit Service 4684c1
dnl gives unlimited permission to copy and/or distribute it,
Packit Service 4684c1
dnl with or without modifications, as long as this notice is preserved.
Packit Service 4684c1
Packit Service 4684c1
dnl This file must be named something that sorts before all other
Packit Service 4684c1
dnl gnulib-provided .m4 files.  The first part is needed until such time
Packit Service 4684c1
dnl as we can assume Autoconf 2.64, with its improved AC_DEFUN_ONCE and
Packit Service 4684c1
dnl m4_divert semantics.  The second part is needed until the clang fix
Packit Service 4684c1
dnl has been included in Autoconf.
Packit Service 4684c1
Packit Service 4684c1
# Until autoconf 2.63, handling of the diversion stack required m4_init
Packit Service 4684c1
# to be called first; but this does not happen with aclocal.  Wrapping
Packit Service 4684c1
# the entire execution in another layer of the diversion stack fixes this.
Packit Service 4684c1
# Worse, prior to autoconf 2.62, m4_wrap depended on the underlying m4
Packit Service 4684c1
# for whether it was FIFO or LIFO; in order to properly balance with
Packit Service 4684c1
# m4_init, we need to undo our push just before anything wrapped within
Packit Service 4684c1
# the m4_init body.  The way to ensure this is to wrap both sides of
Packit Service 4684c1
# m4_init with a one-shot macro that does the pop at the right time.
Packit Service 4684c1
m4_ifndef([_m4_divert_diversion],
Packit Service 4684c1
[m4_divert_push([KILL])
Packit Service 4684c1
m4_define([gl_divert_fixup], [m4_divert_pop()m4_define([$0])])
Packit Service 4684c1
m4_define([m4_init],
Packit Service 4684c1
  [gl_divert_fixup()]m4_defn([m4_init])[gl_divert_fixup()])])
Packit Service 4684c1
Packit Service 4684c1
Packit Service 4684c1
# AC_DEFUN_ONCE([NAME], VALUE)
Packit Service 4684c1
# ----------------------------
Packit Service 4684c1
# Define NAME to expand to VALUE on the first use (whether by direct
Packit Service 4684c1
# expansion, or by AC_REQUIRE), and to nothing on all subsequent uses.
Packit Service 4684c1
# Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier.  This
Packit Service 4684c1
# definition is slower than the version in Autoconf 2.64, because it
Packit Service 4684c1
# can only use interfaces that existed since 2.59; but it achieves the
Packit Service 4684c1
# same effect.  Quoting is necessary to avoid confusing Automake.
Packit Service 4684c1
m4_version_prereq([2.63.263], [],
Packit Service 4684c1
[m4_define([AC][_DEFUN_ONCE],
Packit Service 4684c1
  [AC][_DEFUN([$1],
Packit Service 4684c1
    [AC_REQUIRE([_gl_DEFUN_ONCE([$1])],
Packit Service 4684c1
      [m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl
Packit Service 4684c1
[AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])])
Packit Service 4684c1
Packit Service 4684c1
# The following definitions arrange to use a compiler option
Packit Service 4684c1
# -Werror=implicit-function-declaration in AC_CHECK_DECL, when the
Packit Service 4684c1
# compiler is clang.  Without it, clang implicitly declares "known"
Packit Service 4684c1
# library functions in C mode, but not in C++ mode, which would cause
Packit Service 4684c1
# Gnulib to omit a declaration and thus later produce an error in C++
Packit Service 4684c1
# mode.  As of clang 9.0, these "known" functions are identified through
Packit Service 4684c1
# LIBBUILTIN invocations in the LLVM source file
Packit Service 4684c1
# llvm/tools/clang/include/clang/Basic/Builtins.def.
Packit Service 4684c1
# It's not possible to AC_REQUIRE the extra tests from AC_CHECK_DECL,
Packit Service 4684c1
# because AC_CHECK_DECL, like other Autoconf built-ins, is not supposed
Packit Service 4684c1
# to AC_REQUIRE anything: some configure.ac files have their first
Packit Service 4684c1
# AC_CHECK_DECL executed conditionally.  Therefore append the extra tests
Packit Service 4684c1
# to AC_PROG_CC.
Packit Service 4684c1
AC_DEFUN([gl_COMPILER_CLANG],
Packit Service 4684c1
[
Packit Service 4684c1
dnl AC_REQUIRE([AC_PROG_CC])
Packit Service 4684c1
  AC_CACHE_CHECK([whether the compiler is clang],
Packit Service 4684c1
    [gl_cv_compiler_clang],
Packit Service 4684c1
    [dnl Use _AC_COMPILE_IFELSE instead of AC_EGREP_CPP, to avoid error
Packit Service 4684c1
     dnl "circular dependency of AC_LANG_COMPILER(C)" if AC_PROG_CC has
Packit Service 4684c1
     dnl not yet been invoked.
Packit Service 4684c1
     _AC_COMPILE_IFELSE(
Packit Service 4684c1
        [AC_LANG_PROGRAM([[
Packit Service 4684c1
           #ifdef __clang__
Packit Service 4684c1
           barfbarf
Packit Service 4684c1
           #endif
Packit Service 4684c1
           ]],[[]])
Packit Service 4684c1
        ],
Packit Service 4684c1
        [gl_cv_compiler_clang=no],
Packit Service 4684c1
        [gl_cv_compiler_clang=yes])
Packit Service 4684c1
    ])
Packit Service 4684c1
])
Packit Service 4684c1
AC_DEFUN([gl_COMPILER_PREPARE_CHECK_DECL],
Packit Service 4684c1
[
Packit Service 4684c1
dnl AC_REQUIRE([AC_PROG_CC])
Packit Service 4684c1
dnl AC_REQUIRE([gl_COMPILER_CLANG])
Packit Service 4684c1
  AC_CACHE_CHECK([for compiler option needed when checking for declarations],
Packit Service 4684c1
    [gl_cv_compiler_check_decl_option],
Packit Service 4684c1
    [if test $gl_cv_compiler_clang = yes; then
Packit Service 4684c1
       dnl Test whether the compiler supports the option
Packit Service 4684c1
       dnl '-Werror=implicit-function-declaration'.
Packit Service 4684c1
       save_ac_compile="$ac_compile"
Packit Service 4684c1
       ac_compile="$ac_compile -Werror=implicit-function-declaration"
Packit Service 4684c1
       dnl Use _AC_COMPILE_IFELSE instead of AC_COMPILE_IFELSE, to avoid a
Packit Service 4684c1
       dnl warning "AC_COMPILE_IFELSE was called before AC_USE_SYSTEM_EXTENSIONS".
Packit Service 4684c1
       _AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
Packit Service 4684c1
         [gl_cv_compiler_check_decl_option='-Werror=implicit-function-declaration'],
Packit Service 4684c1
         [gl_cv_compiler_check_decl_option=none])
Packit Service 4684c1
       ac_compile="$save_ac_compile"
Packit Service 4684c1
     else
Packit Service 4684c1
       gl_cv_compiler_check_decl_option=none
Packit Service 4684c1
     fi
Packit Service 4684c1
    ])
Packit Service 4684c1
  if test "x$gl_cv_compiler_check_decl_option" != xnone; then
Packit Service 4684c1
    ac_compile_for_check_decl="$ac_compile $gl_cv_compiler_check_decl_option"
Packit Service 4684c1
  else
Packit Service 4684c1
    ac_compile_for_check_decl="$ac_compile"
Packit Service 4684c1
  fi
Packit Service 4684c1
])
Packit Service 4684c1
dnl Redefine _AC_CHECK_DECL_BODY so that it references ac_compile_for_check_decl
Packit Service 4684c1
dnl instead of ac_compile.  If, for whatever reason, the override of AC_PROG_CC
Packit Service 4684c1
dnl in zzgnulib.m4 is inactive, use the original ac_compile.
Packit Service 4684c1
m4_define([_AC_CHECK_DECL_BODY],
Packit Service 4684c1
[  ac_save_ac_compile="$ac_compile"
Packit Service 4684c1
  if test -n "$ac_compile_for_check_decl"; then
Packit Service 4684c1
    ac_compile="$ac_compile_for_check_decl"
Packit Service 4684c1
  fi]
Packit Service 4684c1
m4_defn([_AC_CHECK_DECL_BODY])[  ac_compile="$ac_save_ac_compile"
Packit Service 4684c1
])
Packit Service 4684c1
Packit Service 4684c1
# gl_00GNULIB
Packit Service 4684c1
# -----------
Packit Service 4684c1
# Witness macro that this file has been included.  Needed to force
Packit Service 4684c1
# Automake to include this file prior to all other gnulib .m4 files.
Packit Service 4684c1
AC_DEFUN([gl_00GNULIB])