warnings.m4 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Autoconf include file defining macros related to compile-time warnings.
  2. # Copyright 2004, 2005, 2007, 2009, 2011 Free Software Foundation, Inc.
  3. #This file is part of GCC.
  4. #GCC is free software; you can redistribute it and/or modify it under
  5. #the terms of the GNU General Public License as published by the Free
  6. #Software Foundation; either version 3, or (at your option) any later
  7. #version.
  8. #GCC is distributed in the hope that it will be useful, but WITHOUT
  9. #ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. #FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. #for more details.
  12. #You should have received a copy of the GNU General Public License
  13. #along with GCC; see the file COPYING3. If not see
  14. #<http://www.gnu.org/licenses/>.
  15. # ACX_PROG_CC_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CFLAGS)
  16. # Sets @VARIABLE@ to the subset of the given options which the
  17. # compiler accepts.
  18. AC_DEFUN([ACX_PROG_CC_WARNING_OPTS],
  19. [AC_REQUIRE([AC_PROG_CC])dnl
  20. m4_pushdef([acx_Var], [m4_default([$2], [WARN_CFLAGS])])dnl
  21. AC_SUBST(acx_Var)dnl
  22. m4_expand_once([acx_Var=
  23. ],m4_quote(acx_Var=))dnl
  24. save_CFLAGS="$CFLAGS"
  25. for real_option in $1; do
  26. # Do the check with the no- prefix removed since gcc silently
  27. # accepts any -Wno-* option on purpose
  28. case $real_option in
  29. -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;;
  30. *) option=$real_option ;;
  31. esac
  32. AS_VAR_PUSHDEF([acx_Woption], [acx_cv_prog_cc_warning_$option])
  33. AC_CACHE_CHECK([whether $CC supports $option], acx_Woption,
  34. [CFLAGS="$option"
  35. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  36. [AS_VAR_SET(acx_Woption, yes)],
  37. [AS_VAR_SET(acx_Woption, no)])
  38. ])
  39. AS_IF([test AS_VAR_GET(acx_Woption) = yes],
  40. [acx_Var="$acx_Var${acx_Var:+ }$real_option"])
  41. AS_VAR_POPDEF([acx_Woption])dnl
  42. done
  43. CFLAGS="$save_CFLAGS"
  44. m4_popdef([acx_Var])dnl
  45. ])# ACX_PROG_CC_WARNING_OPTS
  46. # ACX_PROG_CC_WARNING_ALMOST_PEDANTIC(WARNINGS, [VARIABLE = WARN_PEDANTIC])
  47. # Append to VARIABLE "-pedantic" + the argument, if the compiler is GCC
  48. # and accepts all of those options simultaneously, otherwise to nothing.
  49. AC_DEFUN([ACX_PROG_CC_WARNING_ALMOST_PEDANTIC],
  50. [AC_REQUIRE([AC_PROG_CC])dnl
  51. m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl
  52. AC_SUBST(acx_Var)dnl
  53. m4_expand_once([acx_Var=
  54. ],m4_quote(acx_Var=))dnl
  55. # Do the check with the no- prefix removed from the warning options
  56. # since gcc silently accepts any -Wno-* option on purpose
  57. m4_pushdef([acx_Woptions], [m4_bpatsubst([$1], [-Wno-], [-W])])dnl
  58. AS_VAR_PUSHDEF([acx_Pedantic], [acx_cv_prog_cc_pedantic_]acx_Woptions)dnl
  59. AS_IF([test "$GCC" = yes],
  60. [AC_CACHE_CHECK([whether $CC supports -pedantic ]acx_Woptions, acx_Pedantic,
  61. [save_CFLAGS="$CFLAGS"
  62. CFLAGS="-pedantic acx_Woptions"
  63. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  64. [AS_VAR_SET(acx_Pedantic, yes)],
  65. [AS_VAR_SET(acx_Pedantic, no)])
  66. CFLAGS="$save_CFLAGS"])
  67. AS_IF([test AS_VAR_GET(acx_Pedantic) = yes],
  68. [acx_Var="$acx_Var${acx_Var:+ }-pedantic $1"])
  69. ])
  70. AS_VAR_POPDEF([acx_Pedantic])dnl
  71. m4_popdef([acx_Woptions])dnl
  72. m4_popdef([acx_Var])dnl
  73. ])# ACX_PROG_CC_WARNING_ALMOST_PEDANTIC
  74. # ACX_PROG_CC_WARNINGS_ARE_ERRORS([x.y.z], [VARIABLE = WERROR])
  75. # sets @VARIABLE@ to "-Werror" if the compiler is GCC >=x.y.z, or if
  76. # --enable-werror-always was given on the command line, otherwise
  77. # to nothing.
  78. # If the argument is the word "manual" instead of a version number,
  79. # then @VARIABLE@ will be set to -Werror only if --enable-werror-always
  80. # appeared on the configure command line.
  81. AC_DEFUN([ACX_PROG_CC_WARNINGS_ARE_ERRORS],
  82. [AC_REQUIRE([AC_PROG_CC])dnl
  83. m4_pushdef([acx_Var], [m4_default([$2], [WERROR])])dnl
  84. AC_SUBST(acx_Var)dnl
  85. m4_expand_once([acx_Var=
  86. ],m4_quote(acx_Var=))dnl
  87. AC_ARG_ENABLE(werror-always,
  88. AS_HELP_STRING([--enable-werror-always],
  89. [enable -Werror despite compiler version]),
  90. [], [enable_werror_always=no])
  91. AS_IF([test $enable_werror_always = yes],
  92. [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
  93. m4_if($1, [manual],,
  94. [AS_VAR_PUSHDEF([acx_GCCvers], [acx_cv_prog_cc_gcc_$1_or_newer])dnl
  95. AC_CACHE_CHECK([whether $CC is GCC >=$1], acx_GCCvers,
  96. [set fnord `echo $1 | tr '.' ' '`
  97. shift
  98. AC_PREPROC_IFELSE(
  99. [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \
  100. < [$]1 * 10000 + [$]2 * 100 + [$]3
  101. #error insufficient
  102. #endif],
  103. [AS_VAR_SET(acx_GCCvers, yes)],
  104. [AS_VAR_SET(acx_GCCvers, no)])])
  105. AS_IF([test AS_VAR_GET(acx_GCCvers) = yes],
  106. [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
  107. AS_VAR_POPDEF([acx_GCCvers])])
  108. m4_popdef([acx_Var])dnl
  109. ])# ACX_PROG_CC_WARNINGS_ARE_ERRORS