2007-01-11 Paolo Bonzini <bonzini@gnu.org>
[binutils.git] / config / warnings.m4
blobaf99ffec08349c37251b401bcb916000079e096d
1 # Autoconf include file defining macros related to compile-time warnings.
3 # Copyright 2004, 2005, 2007 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 2, or (at your option) any later
10 #version.
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.
17 #You should have received a copy of the GNU General Public License
18 #along with GCC; see the file COPYING.  If not, write to the Free
19 #Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20 #02110-1301, USA.
22 # ACX_PROG_CC_WARNING_OPTS(WARNINGS, [VARIABLE = WARN_CFLAGS@)
23 #   Sets @VARIABLE@ to the subset of the given options which the
24 #   compiler accepts.
25 AC_DEFUN([ACX_PROG_CC_WARNING_OPTS],
26 [AC_REQUIRE([AC_PROG_CC])dnl
27 m4_pushdef([acx_Var], [m4_default([$2], [WARN_CFLAGS])])dnl
28 AC_SUBST(acx_Var)dnl
29 acx_Var=
30 save_CFLAGS="$CFLAGS"
31 for option in $1; do
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:+ }$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
47 # ACX_PROG_CC_WARNING_ALMOST_PEDANTIC(WARNINGS, [VARIABLE = WARN_PEDANTIC)
48 #   Append to VARIABLE "-pedantic" + the argument, if the compiler is GCC
49 #   and accepts all of those options simultaneously, otherwise to nothing.
50 AC_DEFUN([ACX_PROG_CC_WARNING_ALMOST_PEDANTIC],
51 [AC_REQUIRE([AC_PROG_CC])dnl
52 m4_pushdef([acx_Var], [m4_default([$2], [WARN_PEDANTIC])])dnl
53 AC_SUBST(acx_Var)dnl
54 AS_VAR_PUSHDEF([acx_Pedantic], [acx_cv_prog_cc_pedantic_$1])dnl
55 acx_Var=
56 AS_IF([test "$GCC" = yes],
57 [AC_CACHE_CHECK([whether $CC supports -pedantic $1], acx_Pedantic,
58 [save_CFLAGS="$CFLAGS"
59 CFLAGS="-pedantic $1"
60 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
61    [AS_VAR_SET(acx_Pedantic, yes)],
62    [AS_VAR_SET(acx_Pedantic, no)])
63 CFLAGS="$save_CFLAGS"])
64 AS_IF([test AS_VAR_GET(acx_Pedantic) = yes],
65       [acx_Var="$acx_Var${acx_Var:+ }-pedantic $1"])
67 AS_VAR_POPDEF([acx_Pedantic])dnl
68 m4_popdef([acx_Var])dnl
69 ])# ACX_PROG_CC_WARNING_ALMOST_PEDANTIC
71 # ACX_PROG_CC_WARNINGS_ARE_ERRORS([x.y.z])
72 #   sets WERROR to "-Werror" if the compiler is GCC >=x.y.z, or if
73 #   --enable-werror-always was given on the command line, otherwise
74 #   to nothing.
75 #   If the argument is the word "manual" instead of a version number,
76 #   then WERROR will be set to -Werror only if --enable-werror-always
77 #   appeared on the configure command line.
78 AC_DEFUN([ACX_PROG_CC_WARNINGS_ARE_ERRORS],
79 [AC_REQUIRE([AC_PROG_CC])dnl
80 AC_SUBST([WERROR])dnl
81 WERROR=
82 AC_ARG_ENABLE(werror-always, 
83     AS_HELP_STRING([--enable-werror-always],
84                    [enable -Werror despite compiler version]),
85 [], [enable_werror_always=no])
86 AS_IF([test $enable_werror_always = yes],
87       [WERROR=-Werror],
88  m4_if($1, [manual],,
89  [AS_VAR_PUSHDEF([acx_GCCvers], [acx_cv_prog_cc_gcc_$1_or_newer])dnl
90   AC_CACHE_CHECK([whether $CC is GCC >=$1], acx_GCCvers,
91     [set fnord `echo $1 | tr '.' ' '`
92      shift
93      AC_PREPROC_IFELSE(
94 [#if __GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__ \
95   < [$]1 * 10000 + [$]2 * 100 + [$]3
96 #error insufficient
97 #endif],
98    [AS_VAR_SET(acx_GCCvers, yes)],
99    [AS_VAR_SET(acx_GCCvers, no)])])
100  AS_IF([test AS_VAR_GET(acx_GCCvers) = yes],
101        [WERROR=-WerrorB])
102   AS_VAR_POPDEF([acx_GCCvers])]))
103 ])# ACX_PROG_CC_WARNINGS_ARE_ERRORS