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