Debian Codegraph @

m4/warn-on-use.m4

raw
1 # warn-on-use.m4
2 # serial 11
3 dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 # gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES)
10 # ---------------------------------------
11 # If the module 'posixcheck' is in use:
12 #
13 # For each whitespace-separated element in the list of NAMES, define
14 # HAVE_RAW_DECL_name if the function has a declaration among INCLUDES
15 # even after being undefined as a macro.
16 #
17 # See warn-on-use.h for some hints on how to poison function names, as
18 # well as ideas on poisoning global variables and macros. NAMES may
19 # include global variables, but remember that only functions work with
20 # _GL_WARN_ON_USE. Typically, INCLUDES only needs to list a single
21 # header, but if the replacement header pulls in other headers because
22 # some systems declare functions in the wrong header, then INCLUDES
23 # should do likewise.
24 #
25 # It is generally safe to assume declarations for functions declared
26 # in the intersection of C89 and C11 (such as printf) without
27 # needing gl_WARN_ON_USE_PREPARE.
28 AC_DEFUN([gl_WARN_ON_USE_PREPARE],
29 [
30 m4_ifdef([gl_POSIXCHECK],
31 [m4_foreach_w([gl_decl], [$2],
32 [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])),
33 [Define to 1 if ]m4_defn([gl_decl])[ is declared even after
34 undefining macros.])])dnl
35 for gl_func in m4_flatten([$2]); do
36 AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl
37 dnl As a workaround to implicit built-in function declarations in
38 dnl clang (e.g. strndup), reference ac_compile_for_check_decl instead
39 dnl of ac_compile. If, for whatever reason, the override of AC_PROG_CC
40 dnl in zzgnulib.m4 is inactive, use the original ac_compile.
41 ac_saved_ac_compile="$ac_compile"
42 if test -n "$ac_compile_for_check_decl"; then
43 ac_compile="$ac_compile_for_check_decl"
44 fi
45 AC_CACHE_CHECK([whether $gl_func is declared without a macro],
46 [gl_Symbol],
47 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1],
48 [[#undef $gl_func
49 (void) $gl_func;]])],
50 [AS_VAR_SET([gl_Symbol], [yes])], [AS_VAR_SET([gl_Symbol], [no])])])
51 ac_compile="$ac_saved_ac_compile"
52 AS_VAR_IF([gl_Symbol], [yes],
53 [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
54 dnl Shortcut for an AC_CHECK_DECL invocation that may come later:
55 dnl If the raw declaration exists with the given includes, then
56 dnl AC_CHECK_DECL with its many includes would see it as well.
57 dnl So, set a cache variable to allow skipping any later
58 dnl AC_CHECK_DECL invocation for $gl_func.
59 eval "ac_cv_have_decl_$gl_func=yes"
60 ])
61 AS_VAR_POPDEF([gl_Symbol])dnl
62 done
63 ])
64 ])