Commit | Line | Data |
---|---|---|
9a8371d2 DD |
1 | # Autoconf include file defining macros related to compile-time warnings. |
2 | ||
a53e62cf | 3 | # Copyright 2004, 2005, 2007, 2009, 2011 Free Software Foundation, Inc. |
9a8371d2 DD |
4 | |
5 | #This file is part of GCC. | |
6 | ||
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 | |
ca892441 | 9 | #Software Foundation; either version 3, or (at your option) any later |
9a8371d2 DD |
10 | #version. |
11 | ||
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 | |
15 | #for more details. | |
16 | ||
17 | #You should have received a copy of the GNU General Public License | |
ca892441 RW |
18 | #along with GCC; see the file COPYING3. If not see |
19 | #<http://www.gnu.org/licenses/>. | |
9a8371d2 | 20 | |
8a643cc3 | 21 | # ACX_PROG_CC_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CFLAGS]) |
aa075251 | 22 | # Sets @VARIABLE@ to the subset of the given options which the |
9a8371d2 DD |
23 | # compiler accepts. |
24 | AC_DEFUN([ACX_PROG_CC_WARNING_OPTS], | |
25 | [AC_REQUIRE([AC_PROG_CC])dnl | |
8a643cc3 | 26 | AC_LANG_PUSH(C) |
aa075251 PB |
27 | m4_pushdef([acx_Var], [m4_default([$2], [WARN_CFLAGS])])dnl |
28 | AC_SUBST(acx_Var)dnl | |
ceb92e78 PB |
29 | m4_expand_once([acx_Var= |
30 | ],m4_quote(acx_Var=))dnl | |
9a8371d2 | 31 | save_CFLAGS="$CFLAGS" |
a53e62cf AS |
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 | |
35 | case $real_option in | |
604fcd65 | 36 | -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;; |
a53e62cf AS |
37 | *) option=$real_option ;; |
38 | esac | |
9a8371d2 DD |
39 | AS_VAR_PUSHDEF([acx_Woption], [acx_cv_prog_cc_warning_$option]) |
40 | AC_CACHE_CHECK([whether $CC supports $option], acx_Woption, | |
41 | [CFLAGS="$option" | |
42 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], | |
43 | [AS_VAR_SET(acx_Woption, yes)], | |
44 | [AS_VAR_SET(acx_Woption, no)]) | |
45 | ]) | |
46 | AS_IF([test AS_VAR_GET(acx_Woption) = yes], | |
a53e62cf | 47 | [acx_Var="$acx_Var${acx_Var:+ }$real_option"]) |
9a8371d2 DD |
48 | AS_VAR_POPDEF([acx_Woption])dnl |
49 | done | |
50 | CFLAGS="$save_CFLAGS" | |
aa075251 | 51 | m4_popdef([acx_Var])dnl |
8a643cc3 | 52 | AC_LANG_POP(C) |
9a8371d2 DD |
53 | ])# ACX_PROG_CC_WARNING_OPTS |
54 | ||
a53e62cf | 55 | # ACX_PROG_CC_WARNING_ALMOST_PEDANTIC(WARNINGS, [VARIABLE = WARN_PEDANTIC]) |
aa075251 | 56 | # Append to VARIABLE "-pedantic" + the argument, if the compiler is GCC |
5452212a | 57 | # and accepts all of those options simultaneously, otherwise to nothing. |
9a8371d2 DD |
58 | AC_DEFUN([ACX_PROG_CC_WARNING_ALMOST_PEDANTIC], |
59 | [AC_REQUIRE([AC_PROG_CC])dnl | |
8a643cc3 | 60 | AC_LANG_PUSH(C) |
aa075251 PB |
61 | m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl |
62 | AC_SUBST(acx_Var)dnl | |
ceb92e78 PB |
63 | m4_expand_once([acx_Var= |
64 | ],m4_quote(acx_Var=))dnl | |
a53e62cf AS |
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 | |
f1166a09 | 69 | AS_IF([test "$GCC" = yes], |
a53e62cf | 70 | [AC_CACHE_CHECK([whether $CC supports -pedantic ]acx_Woptions, acx_Pedantic, |
9a8371d2 | 71 | [save_CFLAGS="$CFLAGS" |
a53e62cf | 72 | CFLAGS="-pedantic acx_Woptions" |
9a8371d2 DD |
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], | |
aa075251 | 78 | [acx_Var="$acx_Var${acx_Var:+ }-pedantic $1"]) |
5452212a | 79 | ]) |
9a8371d2 | 80 | AS_VAR_POPDEF([acx_Pedantic])dnl |
a53e62cf | 81 | m4_popdef([acx_Woptions])dnl |
aa075251 | 82 | m4_popdef([acx_Var])dnl |
8a643cc3 | 83 | AC_LANG_POP(C) |
9a8371d2 DD |
84 | ])# ACX_PROG_CC_WARNING_ALMOST_PEDANTIC |
85 | ||
ceb92e78 PB |
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 | |
9a8371d2 DD |
88 | # --enable-werror-always was given on the command line, otherwise |
89 | # to nothing. | |
90 | # If the argument is the word "manual" instead of a version number, | |
ceb92e78 | 91 | # then @VARIABLE@ will be set to -Werror only if --enable-werror-always |
9a8371d2 DD |
92 | # appeared on the configure command line. |
93 | AC_DEFUN([ACX_PROG_CC_WARNINGS_ARE_ERRORS], | |
94 | [AC_REQUIRE([AC_PROG_CC])dnl | |
8a643cc3 | 95 | AC_LANG_PUSH(C) |
ceb92e78 PB |
96 | m4_pushdef([acx_Var], [m4_default([$2], [WERROR])])dnl |
97 | AC_SUBST(acx_Var)dnl | |
98 | m4_expand_once([acx_Var= | |
99 | ],m4_quote(acx_Var=))dnl | |
9a8371d2 DD |
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], | |
ceb92e78 | 105 | [acx_Var="$acx_Var${acx_Var:+ }-Werror"]) |
9a8371d2 DD |
106 | m4_if($1, [manual],, |
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 '.' ' '` | |
110 | shift | |
111 | AC_PREPROC_IFELSE( | |
112 | [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \ | |
113 | < [$]1 * 10000 + [$]2 * 100 + [$]3 | |
114 | #error insufficient | |
115 | #endif], | |
116 | [AS_VAR_SET(acx_GCCvers, yes)], | |
117 | [AS_VAR_SET(acx_GCCvers, no)])]) | |
118 | AS_IF([test AS_VAR_GET(acx_GCCvers) = yes], | |
ceb92e78 PB |
119 | [acx_Var="$acx_Var${acx_Var:+ }-Werror"]) |
120 | AS_VAR_POPDEF([acx_GCCvers])]) | |
121 | m4_popdef([acx_Var])dnl | |
8a643cc3 | 122 | AC_LANG_POP(C) |
9a8371d2 | 123 | ])# ACX_PROG_CC_WARNINGS_ARE_ERRORS |
8a643cc3 L |
124 | |
125 | # ACX_PROG_CXX_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CXXFLAGS]) | |
126 | # Sets @VARIABLE@ to the subset of the given options which the | |
127 | # compiler accepts. | |
128 | AC_DEFUN([ACX_PROG_CXX_WARNING_OPTS], | |
129 | [AC_REQUIRE([AC_PROG_CXX])dnl | |
130 | AC_LANG_PUSH(C++) | |
131 | m4_pushdef([acx_Var], [m4_default([$2], [WARN_CXXFLAGS])])dnl | |
132 | AC_SUBST(acx_Var)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 | |
139 | case $real_option in | |
140 | -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;; | |
141 | *) option=$real_option ;; | |
142 | esac | |
143 | AS_VAR_PUSHDEF([acx_Woption], [acx_cv_prog_cc_warning_$option]) | |
144 | AC_CACHE_CHECK([whether $CXX supports $option], acx_Woption, | |
145 | [CXXFLAGS="$option" | |
146 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])], | |
147 | [AS_VAR_SET(acx_Woption, yes)], | |
148 | [AS_VAR_SET(acx_Woption, no)]) | |
149 | ]) | |
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 | |
153 | done | |
154 | CXXFLAGS="$save_CXXFLAGS" | |
155 | m4_popdef([acx_Var])dnl | |
156 | AC_LANG_POP(C++) | |
157 | ])# ACX_PROG_CXX_WARNING_OPTS | |
158 | ||
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 | |
164 | AC_LANG_PUSH(C++) | |
165 | m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl | |
166 | AC_SUBST(acx_Var)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"]) | |
183 | ]) | |
184 | AS_VAR_POPDEF([acx_Pedantic])dnl | |
185 | m4_popdef([acx_Woptions])dnl | |
186 | m4_popdef([acx_Var])dnl | |
187 | AC_LANG_POP(C++) | |
188 | ])# ACX_PROG_CXX_WARNING_ALMOST_PEDANTIC | |
189 | ||
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 | |
193 | # to nothing. | |
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 | |
199 | AC_LANG_PUSH(C++) | |
200 | m4_pushdef([acx_Var], [m4_default([$2], [WERROR])])dnl | |
201 | AC_SUBST(acx_Var)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"]) | |
210 | m4_if($1, [manual],, | |
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 '.' ' '` | |
214 | shift | |
215 | AC_PREPROC_IFELSE( | |
216 | [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \ | |
217 | < [$]1 * 10000 + [$]2 * 100 + [$]3 | |
218 | #error insufficient | |
219 | #endif], | |
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 | |
226 | AC_LANG_POP(C++) | |
227 | ])# ACX_PROG_CXX_WARNINGS_ARE_ERRORS |