Home | History | Annotate | Line # | Download | only in m4
      1  1.1.1.2  christos # warn-on-use.m4 serial 9
      2  1.1.1.2  christos dnl Copyright (C) 2010-2022 Free Software Foundation, Inc.
      3      1.1  christos dnl This file is free software; the Free Software Foundation
      4      1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      5      1.1  christos dnl with or without modifications, as long as this notice is preserved.
      6      1.1  christos 
      7      1.1  christos # gl_WARN_ON_USE_PREPARE(INCLUDES, NAMES)
      8      1.1  christos # ---------------------------------------
      9      1.1  christos # If the module 'posixcheck' is in use:
     10      1.1  christos #
     11      1.1  christos # For each whitespace-separated element in the list of NAMES, define
     12      1.1  christos # HAVE_RAW_DECL_name if the function has a declaration among INCLUDES
     13      1.1  christos # even after being undefined as a macro.
     14      1.1  christos #
     15      1.1  christos # See warn-on-use.h for some hints on how to poison function names, as
     16      1.1  christos # well as ideas on poisoning global variables and macros.  NAMES may
     17      1.1  christos # include global variables, but remember that only functions work with
     18      1.1  christos # _GL_WARN_ON_USE.  Typically, INCLUDES only needs to list a single
     19      1.1  christos # header, but if the replacement header pulls in other headers because
     20      1.1  christos # some systems declare functions in the wrong header, then INCLUDES
     21      1.1  christos # should do likewise.
     22      1.1  christos #
     23      1.1  christos # It is generally safe to assume declarations for functions declared
     24      1.1  christos # in the intersection of C89 and C11 (such as printf) without
     25      1.1  christos # needing gl_WARN_ON_USE_PREPARE.
     26      1.1  christos AC_DEFUN([gl_WARN_ON_USE_PREPARE],
     27      1.1  christos [
     28      1.1  christos   m4_ifdef([gl_POSIXCHECK],
     29      1.1  christos     [m4_foreach_w([gl_decl], [$2],
     30      1.1  christos        [AH_TEMPLATE([HAVE_RAW_DECL_]AS_TR_CPP(m4_defn([gl_decl])),
     31      1.1  christos          [Define to 1 if ]m4_defn([gl_decl])[ is declared even after
     32      1.1  christos           undefining macros.])])dnl
     33      1.1  christos      for gl_func in m4_flatten([$2]); do
     34      1.1  christos        AS_VAR_PUSHDEF([gl_Symbol], [gl_cv_have_raw_decl_$gl_func])dnl
     35      1.1  christos        AC_CACHE_CHECK([whether $gl_func is declared without a macro],
     36  1.1.1.2  christos          [gl_Symbol],
     37      1.1  christos          [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$1],
     38  1.1.1.2  christos [[#undef $gl_func
     39  1.1.1.2  christos   (void) $gl_func;]])],
     40  1.1.1.2  christos            [AS_VAR_SET([gl_Symbol], [yes])], [AS_VAR_SET([gl_Symbol], [no])])])
     41  1.1.1.2  christos        AS_VAR_IF([gl_Symbol], [yes],
     42      1.1  christos          [AC_DEFINE_UNQUOTED(AS_TR_CPP([HAVE_RAW_DECL_$gl_func]), [1])
     43      1.1  christos           dnl shortcut - if the raw declaration exists, then set a cache
     44      1.1  christos           dnl variable to allow skipping any later AC_CHECK_DECL efforts
     45      1.1  christos           eval ac_cv_have_decl_$gl_func=yes])
     46      1.1  christos        AS_VAR_POPDEF([gl_Symbol])dnl
     47      1.1  christos      done
     48      1.1  christos     ])
     49      1.1  christos ])
     50