warn-on-use.m4 2.8 KB

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