warnings.m4 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. AC_LANG_PUSH(C)
  21. m4_pushdef([acx_Var], [m4_default([$2], [WARN_CFLAGS])])dnl
  22. AC_SUBST(acx_Var)dnl
  23. m4_expand_once([acx_Var=
  24. ],m4_quote(acx_Var=))dnl
  25. save_CFLAGS="$CFLAGS"
  26. for real_option in $1; do
  27. # Do the check with the no- prefix removed since gcc silently
  28. # accepts any -Wno-* option on purpose
  29. case $real_option in
  30. -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;;
  31. *) option=$real_option ;;
  32. esac
  33. AS_VAR_PUSHDEF([acx_Woption], [acx_cv_prog_cc_warning_$option])
  34. AC_CACHE_CHECK([whether $CC supports $option], acx_Woption,
  35. [CFLAGS="$option"
  36. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  37. [AS_VAR_SET(acx_Woption, yes)],
  38. [AS_VAR_SET(acx_Woption, no)])
  39. ])
  40. AS_IF([test AS_VAR_GET(acx_Woption) = yes],
  41. [acx_Var="$acx_Var${acx_Var:+ }$real_option"])
  42. AS_VAR_POPDEF([acx_Woption])dnl
  43. done
  44. CFLAGS="$save_CFLAGS"
  45. m4_popdef([acx_Var])dnl
  46. AC_LANG_POP(C)
  47. ])# ACX_PROG_CC_WARNING_OPTS
  48. # ACX_PROG_CC_WARNING_ALMOST_PEDANTIC(WARNINGS, [VARIABLE = WARN_PEDANTIC])
  49. # Append to VARIABLE "-pedantic" + the argument, if the compiler is GCC
  50. # and accepts all of those options simultaneously, otherwise to nothing.
  51. AC_DEFUN([ACX_PROG_CC_WARNING_ALMOST_PEDANTIC],
  52. [AC_REQUIRE([AC_PROG_CC])dnl
  53. AC_LANG_PUSH(C)
  54. m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl
  55. AC_SUBST(acx_Var)dnl
  56. m4_expand_once([acx_Var=
  57. ],m4_quote(acx_Var=))dnl
  58. # Do the check with the no- prefix removed from the warning options
  59. # since gcc silently accepts any -Wno-* option on purpose
  60. m4_pushdef([acx_Woptions], [m4_bpatsubst([$1], [-Wno-], [-W])])dnl
  61. AS_VAR_PUSHDEF([acx_Pedantic], [acx_cv_prog_cc_pedantic_]acx_Woptions)dnl
  62. AS_IF([test "$GCC" = yes],
  63. [AC_CACHE_CHECK([whether $CC supports -pedantic ]acx_Woptions, acx_Pedantic,
  64. [save_CFLAGS="$CFLAGS"
  65. CFLAGS="-pedantic acx_Woptions"
  66. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  67. [AS_VAR_SET(acx_Pedantic, yes)],
  68. [AS_VAR_SET(acx_Pedantic, no)])
  69. CFLAGS="$save_CFLAGS"])
  70. AS_IF([test AS_VAR_GET(acx_Pedantic) = yes],
  71. [acx_Var="$acx_Var${acx_Var:+ }-pedantic $1"])
  72. ])
  73. AS_VAR_POPDEF([acx_Pedantic])dnl
  74. m4_popdef([acx_Woptions])dnl
  75. m4_popdef([acx_Var])dnl
  76. AC_LANG_POP(C)
  77. ])# ACX_PROG_CC_WARNING_ALMOST_PEDANTIC
  78. # ACX_PROG_CC_WARNINGS_ARE_ERRORS([x.y.z], [VARIABLE = WERROR])
  79. # sets @VARIABLE@ to "-Werror" if the compiler is GCC >=x.y.z, or if
  80. # --enable-werror-always was given on the command line, otherwise
  81. # to nothing.
  82. # If the argument is the word "manual" instead of a version number,
  83. # then @VARIABLE@ will be set to -Werror only if --enable-werror-always
  84. # appeared on the configure command line.
  85. AC_DEFUN([ACX_PROG_CC_WARNINGS_ARE_ERRORS],
  86. [AC_REQUIRE([AC_PROG_CC])dnl
  87. AC_LANG_PUSH(C)
  88. m4_pushdef([acx_Var], [m4_default([$2], [WERROR])])dnl
  89. AC_SUBST(acx_Var)dnl
  90. m4_expand_once([acx_Var=
  91. ],m4_quote(acx_Var=))dnl
  92. AC_ARG_ENABLE(werror-always,
  93. AS_HELP_STRING([--enable-werror-always],
  94. [enable -Werror despite compiler version]),
  95. [], [enable_werror_always=no])
  96. AS_IF([test $enable_werror_always = yes],
  97. [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
  98. m4_if($1, [manual],,
  99. [AS_VAR_PUSHDEF([acx_GCCvers], [acx_cv_prog_cc_gcc_$1_or_newer])dnl
  100. AC_CACHE_CHECK([whether $CC is GCC >=$1], acx_GCCvers,
  101. [set fnord `echo $1 | tr '.' ' '`
  102. shift
  103. AC_PREPROC_IFELSE(
  104. [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \
  105. < [$]1 * 10000 + [$]2 * 100 + [$]3
  106. #error insufficient
  107. #endif],
  108. [AS_VAR_SET(acx_GCCvers, yes)],
  109. [AS_VAR_SET(acx_GCCvers, no)])])
  110. AS_IF([test AS_VAR_GET(acx_GCCvers) = yes],
  111. [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
  112. AS_VAR_POPDEF([acx_GCCvers])])
  113. m4_popdef([acx_Var])dnl
  114. AC_LANG_POP(C)
  115. ])# ACX_PROG_CC_WARNINGS_ARE_ERRORS
  116. # ACX_PROG_CXX_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CXXFLAGS])
  117. # Sets @VARIABLE@ to the subset of the given options which the
  118. # compiler accepts.
  119. AC_DEFUN([ACX_PROG_CXX_WARNING_OPTS],
  120. [AC_REQUIRE([AC_PROG_CXX])dnl
  121. AC_LANG_PUSH(C++)
  122. m4_pushdef([acx_Var], [m4_default([$2], [WARN_CXXFLAGS])])dnl
  123. AC_SUBST(acx_Var)dnl
  124. m4_expand_once([acx_Var=
  125. ],m4_quote(acx_Var=))dnl
  126. save_CXXFLAGS="$CXXFLAGS"
  127. for real_option in $1; do
  128. # Do the check with the no- prefix removed since gcc silently
  129. # accepts any -Wno-* option on purpose
  130. case $real_option in
  131. -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;;
  132. *) option=$real_option ;;
  133. esac
  134. AS_VAR_PUSHDEF([acx_Woption], [acx_cv_prog_cc_warning_$option])
  135. AC_CACHE_CHECK([whether $CXX supports $option], acx_Woption,
  136. [CXXFLAGS="$option"
  137. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  138. [AS_VAR_SET(acx_Woption, yes)],
  139. [AS_VAR_SET(acx_Woption, no)])
  140. ])
  141. AS_IF([test AS_VAR_GET(acx_Woption) = yes],
  142. [acx_Var="$acx_Var${acx_Var:+ }$real_option"])
  143. AS_VAR_POPDEF([acx_Woption])dnl
  144. done
  145. CXXFLAGS="$save_CXXFLAGS"
  146. m4_popdef([acx_Var])dnl
  147. AC_LANG_POP(C++)
  148. ])# ACX_PROG_CXX_WARNING_OPTS
  149. # ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC(WARNINGS, [VARIABLE = WARN_PEDANTIC])
  150. # Append to VARIABLE "-pedantic" + the argument, if the compiler is G++
  151. # and accepts all of those options simultaneously, otherwise to nothing.
  152. AC_DEFUN([ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC],
  153. [AC_REQUIRE([AC_PROG_CXX])dnl
  154. AC_LANG_PUSH(C++)
  155. m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl
  156. AC_SUBST(acx_Var)dnl
  157. m4_expand_once([acx_Var=
  158. ],m4_quote(acx_Var=))dnl
  159. # Do the check with the no- prefix removed from the warning options
  160. # since gcc silently accepts any -Wno-* option on purpose
  161. m4_pushdef([acx_Woptions], [m4_bpatsubst([$1], [-Wno-], [-W])])dnl
  162. AS_VAR_PUSHDEF([acx_Pedantic], [acx_cv_prog_cc_pedantic_]acx_Woptions)dnl
  163. AS_IF([test "$GXX" = yes],
  164. [AC_CACHE_CHECK([whether $CXX supports -pedantic ]acx_Woptions, acx_Pedantic,
  165. [save_CXXFLAGS="$CXXFLAGS"
  166. CXXFLAGS="-pedantic acx_Woptions"
  167. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  168. [AS_VAR_SET(acx_Pedantic, yes)],
  169. [AS_VAR_SET(acx_Pedantic, no)])
  170. CXXFLAGS="$save_CXXFLAGS"])
  171. AS_IF([test AS_VAR_GET(acx_Pedantic) = yes],
  172. [acx_Var="$acx_Var${acx_Var:+ }-pedantic $1"])
  173. ])
  174. AS_VAR_POPDEF([acx_Pedantic])dnl
  175. m4_popdef([acx_Woptions])dnl
  176. m4_popdef([acx_Var])dnl
  177. AC_LANG_POP(C++)
  178. ])# ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC
  179. # ACX_PROG_CXX_WARNINGS_ARE_ERRORS([x.y.z], [VARIABLE = WERROR])
  180. # sets @VARIABLE@ to "-Werror" if the compiler is G++ >=x.y.z, or if
  181. # --enable-werror-always was given on the command line, otherwise
  182. # to nothing.
  183. # If the argument is the word "manual" instead of a version number,
  184. # then @VARIABLE@ will be set to -Werror only if --enable-werror-always
  185. # appeared on the configure command line.
  186. AC_DEFUN([ACX_PROG_CXX_WARNINGS_ARE_ERRORS],
  187. [AC_REQUIRE([AC_PROG_CXX])dnl
  188. AC_LANG_PUSH(C++)
  189. m4_pushdef([acx_Var], [m4_default([$2], [WERROR])])dnl
  190. AC_SUBST(acx_Var)dnl
  191. m4_expand_once([acx_Var=
  192. ],m4_quote(acx_Var=))dnl
  193. AC_ARG_ENABLE(werror-always,
  194. AS_HELP_STRING([--enable-werror-always],
  195. [enable -Werror despite compiler version]),
  196. [], [enable_werror_always=no])
  197. AS_IF([test $enable_werror_always = yes],
  198. [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
  199. m4_if($1, [manual],,
  200. [AS_VAR_PUSHDEF([acx_GXXvers], [acx_cv_prog_cxx_gxx_$1_or_newer])dnl
  201. AC_CACHE_CHECK([whether $CXX is G++ >=$1], acx_GXXvers,
  202. [set fnord `echo $1 | tr '.' ' '`
  203. shift
  204. AC_PREPROC_IFELSE(
  205. [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \
  206. < [$]1 * 10000 + [$]2 * 100 + [$]3
  207. #error insufficient
  208. #endif],
  209. [AS_VAR_SET(acx_GXXvers, yes)],
  210. [AS_VAR_SET(acx_GXXvers, no)])])
  211. AS_IF([test AS_VAR_GET(acx_GXXvers) = yes],
  212. [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
  213. AS_VAR_POPDEF([acx_GXXvers])])
  214. m4_popdef([acx_Var])dnl
  215. AC_LANG_POP(C++)
  216. ])# ACX_PROG_CXX_WARNINGS_ARE_ERRORS