]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m4/sim_ac_option_warnings.m4
sim: common: split up acinclude.m4 into individual m4 files
[thirdparty/binutils-gdb.git] / sim / m4 / sim_ac_option_warnings.m4
1 dnl Copyright (C) 1997-2021 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 dnl arg[1] Enable -Werror by default? ("yes" or "no")
19 AC_DEFUN([SIM_AC_OPTION_WARNINGS],
20 [
21 AC_ARG_ENABLE(werror,
22 AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]),
23 [case "${enableval}" in
24 yes | y) ERROR_ON_WARNING="yes" ;;
25 no | n) ERROR_ON_WARNING="no" ;;
26 *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
27 esac])
28
29 # Enable -Werror by default when using gcc
30 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
31 ERROR_ON_WARNING=yes
32 fi
33
34 WERROR_CFLAGS=""
35 m4_if(m4_default([$1], [yes]), [yes], [dnl
36 if test "${ERROR_ON_WARNING}" = yes ; then
37 WERROR_CFLAGS="-Werror"
38 fi
39 ])dnl
40
41 build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith \
42 -Wpointer-sign \
43 -Wno-unused -Wunused-value -Wunused-function \
44 -Wno-switch -Wno-char-subscripts -Wmissing-prototypes
45 -Wdeclaration-after-statement -Wempty-body -Wmissing-parameter-type \
46 -Wold-style-declaration -Wold-style-definition"
47
48 # Enable -Wno-format by default when using gcc on mingw since many
49 # GCC versions complain about %I64.
50 case "${host}" in
51 *-*-mingw32*) build_warnings="$build_warnings -Wno-format" ;;
52 *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
53 esac
54
55 AC_ARG_ENABLE(build-warnings,
56 AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
57 [case "${enableval}" in
58 yes) ;;
59 no) build_warnings="-w";;
60 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
61 build_warnings="${build_warnings} ${t}";;
62 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
63 build_warnings="${t} ${build_warnings}";;
64 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
65 esac
66 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
67 echo "Setting compiler warning flags = $build_warnings" 6>&1
68 fi])dnl
69 AC_ARG_ENABLE(sim-build-warnings,
70 AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
71 [case "${enableval}" in
72 yes) ;;
73 no) build_warnings="-w";;
74 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
75 build_warnings="${build_warnings} ${t}";;
76 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
77 build_warnings="${t} ${build_warnings}";;
78 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
79 esac
80 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
81 echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
82 fi])dnl
83 WARN_CFLAGS=""
84 if test "x${build_warnings}" != x -a "x$GCC" = xyes
85 then
86 AC_MSG_CHECKING(compiler warning flags)
87 # Separate out the -Werror flag as some files just cannot be
88 # compiled with it enabled.
89 for w in ${build_warnings}; do
90 case $w in
91 -Werr*) WERROR_CFLAGS=-Werror ;;
92 *) # Check that GCC accepts it
93 saved_CFLAGS="$CFLAGS"
94 CFLAGS="$CFLAGS $w"
95 AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
96 CFLAGS="$saved_CFLAGS"
97 esac
98 done
99 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
100 fi
101 ])
102 AC_SUBST(WARN_CFLAGS)
103 AC_SUBST(WERROR_CFLAGS)