1 # Autoconf include file defining macros related to compile-time warnings. 2 3 # Copyright 2004, 2005, 2007, 2009, 2011 Free Software Foundation, Inc. 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 9 #Software Foundation; either version 3, or (at your option) any later 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 18 #along with GCC; see the file COPYING3. If not see 19 #<http://www.gnu.org/licenses/>. 20 21 # ACX_PROG_CC_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CFLAGS]) 22 # Sets @VARIABLE@ to the subset of the given options which the 23 # compiler accepts. 24 AC_DEFUN([ACX_PROG_CC_WARNING_OPTS], 25 [AC_REQUIRE([AC_PROG_CC])dnl 26 AC_LANG_PUSH(C) 27 m4_pushdef([acx_Var], [m4_default([$2], [WARN_CFLAGS])])dnl 28 AC_SUBST(acx_Var)dnl 29 m4_expand_once([acx_Var= 30 ],m4_quote(acx_Var=))dnl 31 save_CFLAGS="$CFLAGS" 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 36 -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;; 37 *) option=$real_option ;; 38 esac 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], 47 [acx_Var="$acx_Var${acx_Var:+ }$real_option"]) 48 AS_VAR_POPDEF([acx_Woption])dnl 49 done 50 CFLAGS="$save_CFLAGS" 51 m4_popdef([acx_Var])dnl 52 AC_LANG_POP(C) 53 ])# ACX_PROG_CC_WARNING_OPTS 54 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 60 AC_LANG_PUSH(C) 61 m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl 62 AC_SUBST(acx_Var)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"]) 79 ]) 80 AS_VAR_POPDEF([acx_Pedantic])dnl 81 m4_popdef([acx_Woptions])dnl 82 m4_popdef([acx_Var])dnl 83 AC_LANG_POP(C) 84 ])# ACX_PROG_CC_WARNING_ALMOST_PEDANTIC 85 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 89 # to nothing. 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 95 AC_LANG_PUSH(C) 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 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"]) 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], 119 [acx_Var="$acx_Var${acx_Var:+ }-Werror"]) 120 AS_VAR_POPDEF([acx_GCCvers])]) 121 m4_popdef([acx_Var])dnl 122 AC_LANG_POP(C) 123 ])# ACX_PROG_CC_WARNINGS_ARE_ERRORS 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 228