Blame m4/00gnulib.m4

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