Imported Upstream version 1.22.3
[platform/upstream/groff.git] / gnulib_m4 / warn-on-use.m4
1 # warn-on-use.m4 serial 6
2 dnl Copyright (C) 2010-2018 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
7 # gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES)
8 # ---------------------------------------
9 # If the module 'posixcheck' is in use:
10 #
11 # For each whitespace-separated element in the list of NAMES, define
12 # HAVE_RAW_DECL_name if the function has a declaration among INCLUDES
13 # even after being undefined as a macro.
14 #
15 # See warn-on-use.h for some hints on how to poison function names, as
16 # well as ideas on poisoning global variables and macros.  NAMES may
17 # include global variables, but remember that only functions work with
18 # _GL_WARN_ON_USE.  Typically, INCLUDES only needs to list a single
19 # header, but if the replacement header pulls in other headers because
20 # some systems declare functions in the wrong header, then INCLUDES
21 # should do likewise.
22 #
23 # It is generally safe to assume declarations for functions declared
24 # in the intersection of C89 and C11 (such as printf) without
25 # needing gl_WARN_ON_USE_PREPARE.
26 AC_DEFUN([gl_WARN_ON_USE_PREPARE],
27 [
28   m4_ifdef([gl_POSIXCHECK],
29     [m4_foreach_w([gl_decl], [$2],
30        [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])),
31          [Define to 1 if ]m4_defn([gl_decl])[ is declared even after
32           undefining macros.])])dnl
33 dnl FIXME: gl_Symbol must be used unquoted until we can assume
34 dnl autoconf 2.64 or newer.
35      for gl_func in m4_flatten([$2]); do
36        AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl
37        AC_CACHE_CHECK([whether $gl_func is declared without a macro],
38          gl_Symbol,
39          [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1],
40 [@%:@undef $gl_func
41   (void) $gl_func;])],
42            [AS_VAR_SET(gl_Symbol, [yes])], [AS_VAR_SET(gl_Symbol, [no])])])
43        AS_VAR_IF(gl_Symbol, [yes],
44          [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
45           dnl shortcut - if the raw declaration exists, then set a cache
46           dnl variable to allow skipping any later AC_CHECK_DECL efforts
47           eval ac_cv_have_decl_$gl_func=yes])
48        AS_VAR_POPDEF([gl_Symbol])dnl
49      done
50     ])
51 ])