warnings.m4 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # warnings.m4 serial 16
  2. dnl Copyright (C) 2008-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. dnl From Simon Josefsson
  7. # gl_AS_VAR_APPEND(VAR, VALUE)
  8. # ----------------------------
  9. # Provide the functionality of AS_VAR_APPEND if Autoconf does not have it.
  10. m4_ifdef([AS_VAR_APPEND],
  11. [m4_copy([AS_VAR_APPEND], [gl_AS_VAR_APPEND])],
  12. [m4_define([gl_AS_VAR_APPEND],
  13. [AS_VAR_SET([$1], [AS_VAR_GET([$1])$2])])])
  14. # gl_COMPILER_OPTION_IF(OPTION, [IF-SUPPORTED], [IF-NOT-SUPPORTED],
  15. # [PROGRAM = AC_LANG_PROGRAM()])
  16. # -----------------------------------------------------------------
  17. # Check if the compiler supports OPTION when compiling PROGRAM.
  18. #
  19. # The effects of this macro depend on the current language (_AC_LANG).
  20. AC_DEFUN([gl_COMPILER_OPTION_IF],
  21. [
  22. AS_VAR_PUSHDEF([gl_Warn], [gl_cv_warn_[]_AC_LANG_ABBREV[]_$1])dnl
  23. AS_VAR_PUSHDEF([gl_Flags], [_AC_LANG_PREFIX[]FLAGS])dnl
  24. AS_LITERAL_IF([$1],
  25. [m4_pushdef([gl_Positive], m4_bpatsubst([$1], [^-Wno-], [-W]))],
  26. [gl_positive="$1"
  27. case $gl_positive in
  28. -Wno-*) gl_positive=-W`expr "X$gl_positive" : 'X-Wno-\(.*\)'` ;;
  29. esac
  30. m4_pushdef([gl_Positive], [$gl_positive])])dnl
  31. AC_CACHE_CHECK([whether _AC_LANG compiler handles $1], [gl_Warn], [
  32. gl_save_compiler_FLAGS="$gl_Flags"
  33. gl_AS_VAR_APPEND(m4_defn([gl_Flags]),
  34. [" $gl_unknown_warnings_are_errors ]m4_defn([gl_Positive])["])
  35. AC_LINK_IFELSE([m4_default([$4], [AC_LANG_PROGRAM([[]])])],
  36. [AS_VAR_SET([gl_Warn], [yes])],
  37. [AS_VAR_SET([gl_Warn], [no])])
  38. gl_Flags="$gl_save_compiler_FLAGS"
  39. ])
  40. AS_VAR_IF(gl_Warn, [yes], [$2], [$3])
  41. m4_popdef([gl_Positive])dnl
  42. AS_VAR_POPDEF([gl_Flags])dnl
  43. AS_VAR_POPDEF([gl_Warn])dnl
  44. ])
  45. # gl_UNKNOWN_WARNINGS_ARE_ERRORS
  46. # ------------------------------
  47. # Clang doesn't complain about unknown warning options unless one also
  48. # specifies -Wunknown-warning-option -Werror. Detect this.
  49. #
  50. # The effects of this macro depend on the current language (_AC_LANG).
  51. AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS],
  52. [_AC_LANG_DISPATCH([$0], _AC_LANG, $@)])
  53. # Specialization for _AC_LANG = C. This macro can be AC_REQUIREd.
  54. AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C)],
  55. [
  56. AC_LANG_PUSH([C])
  57. gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
  58. AC_LANG_POP([C])
  59. ])
  60. # Specialization for _AC_LANG = C++. This macro can be AC_REQUIREd.
  61. AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(C++)],
  62. [
  63. AC_LANG_PUSH([C++])
  64. gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
  65. AC_LANG_POP([C++])
  66. ])
  67. # Specialization for _AC_LANG = Objective C. This macro can be AC_REQUIREd.
  68. AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS(Objective C)],
  69. [
  70. AC_LANG_PUSH([Objective C])
  71. gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL
  72. AC_LANG_POP([Objective C])
  73. ])
  74. AC_DEFUN([gl_UNKNOWN_WARNINGS_ARE_ERRORS_IMPL],
  75. [gl_COMPILER_OPTION_IF([-Werror -Wunknown-warning-option],
  76. [gl_unknown_warnings_are_errors='-Wunknown-warning-option -Werror'],
  77. [gl_unknown_warnings_are_errors=])])
  78. # gl_WARN_ADD(OPTION, [VARIABLE = WARN_CFLAGS/WARN_CXXFLAGS],
  79. # [PROGRAM = AC_LANG_PROGRAM()])
  80. # -----------------------------------------------------------
  81. # Adds parameter to WARN_CFLAGS/WARN_CXXFLAGS if the compiler supports it
  82. # when compiling PROGRAM. For example, gl_WARN_ADD([-Wparentheses]).
  83. #
  84. # If VARIABLE is a variable name, AC_SUBST it.
  85. #
  86. # The effects of this macro depend on the current language (_AC_LANG).
  87. AC_DEFUN([gl_WARN_ADD],
  88. [AC_REQUIRE([gl_UNKNOWN_WARNINGS_ARE_ERRORS(]_AC_LANG[)])
  89. gl_COMPILER_OPTION_IF([$1],
  90. [gl_AS_VAR_APPEND(m4_if([$2], [], [[WARN_]_AC_LANG_PREFIX[FLAGS]], [[$2]]), [" $1"])],
  91. [],
  92. [$3])
  93. m4_ifval([$2],
  94. [AS_LITERAL_IF([$2], [AC_SUBST([$2])])],
  95. [AC_SUBST([WARN_]_AC_LANG_PREFIX[FLAGS])])dnl
  96. ])
  97. # Local Variables:
  98. # mode: autoconf
  99. # End: