]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - sim/m4/sim_ac_option_warnings.m4
sim: move -Werror disabling to Makefile
[thirdparty/binutils-gdb.git] / sim / m4 / sim_ac_option_warnings.m4
CommitLineData
760b3e8b
MF
1dnl Copyright (C) 1997-2021 Free Software Foundation, Inc.
2dnl
3dnl This program is free software; you can redistribute it and/or modify
4dnl it under the terms of the GNU General Public License as published by
5dnl the Free Software Foundation; either version 3 of the License, or
6dnl (at your option) any later version.
7dnl
8dnl This program is distributed in the hope that it will be useful,
9dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11dnl GNU General Public License for more details.
12dnl
13dnl You should have received a copy of the GNU General Public License
14dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
15dnl
16dnl --enable-build-warnings is for developers of the simulator.
17dnl it enables extra GCC specific warnings.
760b3e8b
MF
18AC_DEFUN([SIM_AC_OPTION_WARNINGS],
19[
20AC_ARG_ENABLE(werror,
21 AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]),
22 [case "${enableval}" in
23 yes | y) ERROR_ON_WARNING="yes" ;;
24 no | n) ERROR_ON_WARNING="no" ;;
25 *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
26 esac])
27
982c3a65 28dnl Enable -Werror by default when using gcc
760b3e8b 29if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
982c3a65 30 ERROR_ON_WARNING=yes
760b3e8b
MF
31fi
32
33WERROR_CFLAGS=""
982c3a65
MF
34if test "${ERROR_ON_WARNING}" = yes ; then
35 WERROR_CFLAGS="-Werror"
36fi
760b3e8b
MF
37
38build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \
39-Wpointer-sign \
40-Wno-unused -Wunused-value -Wunused-function \
41-Wno-switch -Wno-char-subscripts -Wmissing-prototypes
42-Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type \
43-Wold-style-declaration -Wold-style-definition"
44
45# Enable -Wno-format by default when using gcc on mingw since many
46# GCC versions complain about %I64.
47case "${host}" in
48 *-*-mingw32*) build_warnings="$build_warnings -Wno-format" ;;
49 *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
50esac
51
52AC_ARG_ENABLE(build-warnings,
53AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
54[case "${enableval}" in
55 yes) ;;
56 no) build_warnings="-w";;
57 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
58 build_warnings="${build_warnings} ${t}";;
59 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
60 build_warnings="${t} ${build_warnings}";;
61 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
62esac
63if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
64 echo "Setting compiler warning flags = $build_warnings" 6>&1
65fi])dnl
66AC_ARG_ENABLE(sim-build-warnings,
67AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
68[case "${enableval}" in
69 yes) ;;
70 no) build_warnings="-w";;
71 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
72 build_warnings="${build_warnings} ${t}";;
73 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
74 build_warnings="${t} ${build_warnings}";;
75 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
76esac
77if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
78 echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
79fi])dnl
80WARN_CFLAGS=""
81if test "x${build_warnings}" != x -a "x$GCC" = xyes
82then
83 AC_MSG_CHECKING(compiler warning flags)
84 # Separate out the -Werror flag as some files just cannot be
85 # compiled with it enabled.
86 for w in ${build_warnings}; do
87 case $w in
88 -Werr*) WERROR_CFLAGS=-Werror ;;
89 *) # Check that GCC accepts it
90 saved_CFLAGS="$CFLAGS"
1f195bc3 91 CFLAGS="$CFLAGS -Werror $w"
760b3e8b
MF
92 AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
93 CFLAGS="$saved_CFLAGS"
94 esac
95 done
96 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
97fi
98])
99AC_SUBST(WARN_CFLAGS)
100AC_SUBST(WERROR_CFLAGS)