1 # Autoconf include file defining macros related to compile-time warnings.
3 # Copyright 2004, 2005, 2007, 2009, 2011 Free Software Foundation, Inc.
5 #This file is part of GCC.
7 #GCC is free software; you can redistribute it and/or modify it under
8 #the terms of the GNU General Public License as published by the Free
9 #Software Foundation; either version 3, or (at your option) any later
12 #GCC is distributed in the hope that it will be useful, but WITHOUT
13 #ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 #FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #You should have received a copy of the GNU General Public License
18 #along with GCC; see the file COPYING3. If not see
19 #<http://www.gnu.org/licenses/>.
21 # ACX_PROG_CC_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CFLAGS])
22 # Sets @VARIABLE@ to the subset of the given options which the
24 AC_DEFUN([ACX_PROG_CC_WARNING_OPTS],
25 [AC_REQUIRE([AC_PROG_CC])dnl
27 m4_pushdef([acx_Var], [m4_default([$2], [WARN_CFLAGS])])dnl
29 m4_expand_once([acx_Var=
30 ],m4_quote(acx_Var=))dnl
32 for real_option in $1; do
33 # Do the check with the no- prefix removed since gcc silently
34 # accepts any -Wno-* option on purpose
36 -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;;
37 *) option=$real_option ;;
39 AS_VAR_PUSHDEF([acx_Woption], [acx_cv_prog_cc_warning_$option])
40 AC_CACHE_CHECK([whether $CC supports $option], acx_Woption,
42 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
43 [AS_VAR_SET(acx_Woption, yes)],
44 [AS_VAR_SET(acx_Woption, no)])
46 AS_IF([test AS_VAR_GET(acx_Woption) = yes],
47 [acx_Var="$acx_Var${acx_Var:+ }$real_option"])
48 AS_VAR_POPDEF([acx_Woption])dnl
51 m4_popdef([acx_Var])dnl
53 ])# ACX_PROG_CC_WARNING_OPTS
55 # ACX_PROG_CC_WARNING_ALMOST_PEDANTIC(WARNINGS, [VARIABLE = WARN_PEDANTIC])
56 # Append to VARIABLE "-pedantic" + the argument, if the compiler is GCC
57 # and accepts all of those options simultaneously, otherwise to nothing.
58 AC_DEFUN([ACX_PROG_CC_WARNING_ALMOST_PEDANTIC],
59 [AC_REQUIRE([AC_PROG_CC])dnl
61 m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl
63 m4_expand_once([acx_Var=
64 ],m4_quote(acx_Var=))dnl
65 # Do the check with the no- prefix removed from the warning options
66 # since gcc silently accepts any -Wno-* option on purpose
67 m4_pushdef([acx_Woptions], [m4_bpatsubst([$1], [-Wno-], [-W])])dnl
68 AS_VAR_PUSHDEF([acx_Pedantic], [acx_cv_prog_cc_pedantic_]acx_Woptions)dnl
69 AS_IF([test "$GCC" = yes],
70 [AC_CACHE_CHECK([whether $CC supports -pedantic ]acx_Woptions, acx_Pedantic,
71 [save_CFLAGS="$CFLAGS"
72 CFLAGS="-pedantic acx_Woptions"
73 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
74 [AS_VAR_SET(acx_Pedantic, yes)],
75 [AS_VAR_SET(acx_Pedantic, no)])
76 CFLAGS="$save_CFLAGS"])
77 AS_IF([test AS_VAR_GET(acx_Pedantic) = yes],
78 [acx_Var="$acx_Var${acx_Var:+ }-pedantic $1"])
80 AS_VAR_POPDEF([acx_Pedantic])dnl
81 m4_popdef([acx_Woptions])dnl
82 m4_popdef([acx_Var])dnl
84 ])# ACX_PROG_CC_WARNING_ALMOST_PEDANTIC
86 # ACX_PROG_CC_WARNINGS_ARE_ERRORS([x.y.z], [VARIABLE = WERROR])
87 # sets @VARIABLE@ to "-Werror" if the compiler is GCC >=x.y.z, or if
88 # --enable-werror-always was given on the command line, otherwise
90 # If the argument is the word "manual" instead of a version number,
91 # then @VARIABLE@ will be set to -Werror only if --enable-werror-always
92 # appeared on the configure command line.
93 AC_DEFUN([ACX_PROG_CC_WARNINGS_ARE_ERRORS],
94 [AC_REQUIRE([AC_PROG_CC])dnl
96 m4_pushdef([acx_Var], [m4_default([$2], [WERROR])])dnl
98 m4_expand_once([acx_Var=
99 ],m4_quote(acx_Var=))dnl
100 AC_ARG_ENABLE(werror-always,
101 AS_HELP_STRING([--enable-werror-always],
102 [enable -Werror despite compiler version]),
103 [], [enable_werror_always=no])
104 AS_IF([test $enable_werror_always = yes],
105 [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
107 [AS_VAR_PUSHDEF([acx_GCCvers], [acx_cv_prog_cc_gcc_$1_or_newer])dnl
108 AC_CACHE_CHECK([whether $CC is GCC >=$1], acx_GCCvers,
109 [set fnord `echo $1 | tr '.' ' '`
112 [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \
113 < [$]1 * 10000 + [$]2 * 100 + [$]3
116 [AS_VAR_SET(acx_GCCvers, yes)],
117 [AS_VAR_SET(acx_GCCvers, no)])])
118 AS_IF([test AS_VAR_GET(acx_GCCvers) = yes],
119 [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
120 AS_VAR_POPDEF([acx_GCCvers])])
121 m4_popdef([acx_Var])dnl
123 ])# ACX_PROG_CC_WARNINGS_ARE_ERRORS
125 # ACX_PROG_CXX_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CXXFLAGS])
126 # Sets @VARIABLE@ to the subset of the given options which the
128 AC_DEFUN([ACX_PROG_CXX_WARNING_OPTS],
129 [AC_REQUIRE([AC_PROG_CXX])dnl
131 m4_pushdef([acx_Var], [m4_default([$2], [WARN_CXXFLAGS])])dnl
133 m4_expand_once([acx_Var=
134 ],m4_quote(acx_Var=))dnl
135 save_CXXFLAGS="$CXXFLAGS"
136 for real_option in $1; do
137 # Do the check with the no- prefix removed since gcc silently
138 # accepts any -Wno-* option on purpose
140 -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;;
141 *) option=$real_option ;;
143 AS_VAR_PUSHDEF([acx_Woption], [acx_cv_prog_cc_warning_$option])
144 AC_CACHE_CHECK([whether $CXX supports $option], acx_Woption,
146 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
147 [AS_VAR_SET(acx_Woption, yes)],
148 [AS_VAR_SET(acx_Woption, no)])
150 AS_IF([test AS_VAR_GET(acx_Woption) = yes],
151 [acx_Var="$acx_Var${acx_Var:+ }$real_option"])
152 AS_VAR_POPDEF([acx_Woption])dnl
154 CXXFLAGS="$save_CXXFLAGS"
155 m4_popdef([acx_Var])dnl
157 ])# ACX_PROG_CXX_WARNING_OPTS
159 # ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC(WARNINGS, [VARIABLE = WARN_PEDANTIC])
160 # Append to VARIABLE "-pedantic" + the argument, if the compiler is G++
161 # and accepts all of those options simultaneously, otherwise to nothing.
162 AC_DEFUN([ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC],
163 [AC_REQUIRE([AC_PROG_CXX])dnl
165 m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl
167 m4_expand_once([acx_Var=
168 ],m4_quote(acx_Var=))dnl
169 # Do the check with the no- prefix removed from the warning options
170 # since gcc silently accepts any -Wno-* option on purpose
171 m4_pushdef([acx_Woptions], [m4_bpatsubst([$1], [-Wno-], [-W])])dnl
172 AS_VAR_PUSHDEF([acx_Pedantic], [acx_cv_prog_cc_pedantic_]acx_Woptions)dnl
173 AS_IF([test "$GXX" = yes],
174 [AC_CACHE_CHECK([whether $CXX supports -pedantic ]acx_Woptions, acx_Pedantic,
175 [save_CXXFLAGS="$CXXFLAGS"
176 CXXFLAGS="-pedantic acx_Woptions"
177 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
178 [AS_VAR_SET(acx_Pedantic, yes)],
179 [AS_VAR_SET(acx_Pedantic, no)])
180 CXXFLAGS="$save_CXXFLAGS"])
181 AS_IF([test AS_VAR_GET(acx_Pedantic) = yes],
182 [acx_Var="$acx_Var${acx_Var:+ }-pedantic $1"])
184 AS_VAR_POPDEF([acx_Pedantic])dnl
185 m4_popdef([acx_Woptions])dnl
186 m4_popdef([acx_Var])dnl
188 ])# ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC
190 # ACX_PROG_CXX_WARNINGS_ARE_ERRORS([x.y.z], [VARIABLE = WERROR])
191 # sets @VARIABLE@ to "-Werror" if the compiler is G++ >=x.y.z, or if
192 # --enable-werror-always was given on the command line, otherwise
194 # If the argument is the word "manual" instead of a version number,
195 # then @VARIABLE@ will be set to -Werror only if --enable-werror-always
196 # appeared on the configure command line.
197 AC_DEFUN([ACX_PROG_CXX_WARNINGS_ARE_ERRORS],
198 [AC_REQUIRE([AC_PROG_CXX])dnl
200 m4_pushdef([acx_Var], [m4_default([$2], [WERROR])])dnl
202 m4_expand_once([acx_Var=
203 ],m4_quote(acx_Var=))dnl
204 AC_ARG_ENABLE(werror-always,
205 AS_HELP_STRING([--enable-werror-always],
206 [enable -Werror despite compiler version]),
207 [], [enable_werror_always=no])
208 AS_IF([test $enable_werror_always = yes],
209 [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
211 [AS_VAR_PUSHDEF([acx_GXXvers], [acx_cv_prog_cxx_gxx_$1_or_newer])dnl
212 AC_CACHE_CHECK([whether $CXX is G++ >=$1], acx_GXXvers,
213 [set fnord `echo $1 | tr '.' ' '`
216 [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \
217 < [$]1 * 10000 + [$]2 * 100 + [$]3
220 [AS_VAR_SET(acx_GXXvers, yes)],
221 [AS_VAR_SET(acx_GXXvers, no)])])
222 AS_IF([test AS_VAR_GET(acx_GXXvers) = yes],
223 [acx_Var="$acx_Var${acx_Var:+ }-Werror"])
224 AS_VAR_POPDEF([acx_GXXvers])])
225 m4_popdef([acx_Var])dnl
227 ])# ACX_PROG_CXX_WARNINGS_ARE_ERRORS