1 dnl Autoconf configure script for GDB, the GNU debugger.
2 dnl Copyright (C) 1995-2022 Free Software Foundation, Inc.
4 dnl This file is part of GDB.
6 dnl This program is free software; you can redistribute it and/or modify
7 dnl it under the terms of the GNU General Public License as published by
8 dnl the Free Software Foundation; either version 3 of the License, or
9 dnl (at your option) any later version.
11 dnl This program is distributed in the hope that it will be useful,
12 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 dnl GNU General Public License for more details.
16 dnl You should have received a copy of the GNU General Public License
17 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
19 AC_DEFUN([AM_GDB_WARNINGS],[
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) ;;
28 # Enable -Werror by default when using gcc. Turn it off for releases.
29 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; then
34 if test "${ERROR_ON_WARNING}" = yes ; then
35 WERROR_CFLAGS="-Werror"
38 # The options we'll try to enable.
39 build_warnings="-Wall -Wpointer-arith \
40 -Wno-unused -Wunused-value -Wunused-variable -Wunused-function \
41 -Wno-switch -Wno-char-subscripts \
42 -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \
43 -Wno-sign-compare -Wno-error=maybe-uninitialized \
44 -Wno-mismatched-tags \
45 -Wno-error=deprecated-register \
47 -Wimplicit-fallthrough=3 \
51 -Wdeprecated-copy-dtor \
53 -Wmissing-declarations \
54 -Wstrict-null-sentinel \
57 # The -Wmissing-prototypes flag will be accepted by GCC, but results
58 # in a warning being printed about the flag not being valid for C++,
59 # this is something to do with using ccache, and argument ordering.
60 if test "$GDB_COMPILER_TYPE" != gcc; then
61 build_warnings="$build_warnings -Wmissing-prototypes"
66 # Enable -Wno-format by default when using gcc on mingw since many
67 # GCC versions complain about %I64.
68 build_warnings="$build_warnings -Wno-format" ;;
70 # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
72 build_warnings="$build_warnings -Wno-unknown-pragmas"
73 # Solaris 11 <unistd.h> marks vfork deprecated.
74 build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
76 # Note that gcc requires -Wformat for -Wformat-nonliteral to work,
77 # but there's a special case for this below.
78 build_warnings="$build_warnings -Wformat-nonliteral" ;;
81 AC_ARG_ENABLE(build-warnings,
82 AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
83 [case "${enableval}" in
85 no) build_warnings="-w";;
86 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
87 build_warnings="${build_warnings} ${t}";;
88 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
89 build_warnings="${t} ${build_warnings}";;
90 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
92 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
93 echo "Setting compiler warning flags = $build_warnings" 6>&1
95 AC_ARG_ENABLE(gdb-build-warnings,
96 AS_HELP_STRING([--enable-gdb-build-warnings], [enable GDB specific build-time compiler warnings if gcc is used]),
97 [case "${enableval}" in
99 no) build_warnings="-w";;
100 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
101 build_warnings="${build_warnings} ${t}";;
102 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
103 build_warnings="${t} ${build_warnings}";;
104 *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
106 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
107 echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
110 # The set of warnings supported by a C++ compiler is not the same as
115 if test "x${build_warnings}" != x -a "x$GCC" = xyes
117 AC_MSG_CHECKING(compiler warning flags)
118 # Separate out the -Werror flag as some files just cannot be
119 # compiled with it enabled.
120 for w in ${build_warnings}; do
121 # GCC does not complain about -Wno-unknown-warning. Invert
122 # and test -Wunknown-warning instead.
125 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
127 # gcc requires -Wformat before -Wformat-nonliteral
128 # will work, so stick them together.
137 -Werr*) WERROR_CFLAGS=-Werror ;;
139 # Check whether GCC accepts it.
140 saved_CFLAGS="$CFLAGS"
141 CFLAGS="$CFLAGS -Werror $wtest"
142 saved_CXXFLAGS="$CXXFLAGS"
143 CXXFLAGS="$CXXFLAGS -Werror $wtest"
144 if test "x$w" = "x-Wunused-variable"; then
145 # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958,
146 # fixed in GCC 4.9. This test is derived from the gdb
147 # source code that triggered this bug in GCC.
150 [struct scoped_restore_base {};
151 struct scoped_restore_tmpl : public scoped_restore_base {
152 ~scoped_restore_tmpl() {}
154 [const scoped_restore_base &b = scoped_restore_tmpl();]
156 [WARN_CFLAGS="${WARN_CFLAGS} $w"],
161 [AC_LANG_PROGRAM([], [])],
162 [WARN_CFLAGS="${WARN_CFLAGS} $w"],
166 CFLAGS="$saved_CFLAGS"
167 CXXFLAGS="$saved_CXXFLAGS"
170 AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
172 AC_SUBST(WARN_CFLAGS)
173 AC_SUBST(WERROR_CFLAGS)