Commit | Line | Data |
---|---|---|
b835bb52 | 1 | dnl Autoconf configure script for GDB, the GNU debugger. |
b811d2c2 | 2 | dnl Copyright (C) 1995-2020 Free Software Foundation, Inc. |
b835bb52 MF |
3 | dnl |
4 | dnl This file is part of GDB. | |
5 | dnl | |
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. | |
10 | dnl | |
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. | |
15 | dnl | |
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/>. | |
18 | ||
19 | AC_DEFUN([AM_GDB_WARNINGS],[ | |
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 | # Enable -Werror by default when using gcc. Turn it off for releases. | |
29 | if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; 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 | ||
cf6de44d | 38 | # The options we'll try to enable. |
b835bb52 | 39 | build_warnings="-Wall -Wpointer-arith \ |
a0de763e | 40 | -Wno-unused -Wunused-value -Wunused-variable -Wunused-function \ |
b835bb52 | 41 | -Wno-switch -Wno-char-subscripts \ |
cf6de44d | 42 | -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \ |
d3d8724a | 43 | -Wno-sign-compare -Wno-error=maybe-uninitialized \ |
7f8a5d38 | 44 | -Wno-mismatched-tags \ |
632e107b | 45 | -Wno-error=deprecated-register \ |
85e26832 | 46 | -Wsuggest-override \ |
1a34f210 | 47 | -Wimplicit-fallthrough=3 \ |
96643e35 | 48 | -Wduplicated-cond \ |
33a6bc35 TT |
49 | -Wshadow=local \ |
50 | -Wdeprecated-copy \ | |
51 | -Wdeprecated-copy-dtor \ | |
bb564c58 | 52 | -Wredundant-move \ |
8ddd8e0e SM |
53 | -Wmissing-declarations \ |
54 | -Wstrict-null-sentinel \ | |
55 | " | |
b835bb52 | 56 | |
b835bb52 | 57 | case "${host}" in |
4fa7574e RO |
58 | *-*-mingw32*) |
59 | # Enable -Wno-format by default when using gcc on mingw since many | |
60 | # GCC versions complain about %I64. | |
61 | build_warnings="$build_warnings -Wno-format" ;; | |
62 | *-*-solaris*) | |
63 | # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC | |
64 | # doesn't understand. | |
65 | build_warnings="$build_warnings -Wno-unknown-pragmas" | |
66 | # Solaris 11 <unistd.h> marks vfork deprecated. | |
67 | build_warnings="$build_warnings -Wno-deprecated-declarations" ;; | |
f1628857 TT |
68 | *) |
69 | # Note that gcc requires -Wformat for -Wformat-nonliteral to work, | |
70 | # but there's a special case for this below. | |
71 | build_warnings="$build_warnings -Wformat-nonliteral" ;; | |
b835bb52 MF |
72 | esac |
73 | ||
74 | AC_ARG_ENABLE(build-warnings, | |
75 | AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]), | |
76 | [case "${enableval}" in | |
77 | yes) ;; | |
78 | no) build_warnings="-w";; | |
79 | ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"` | |
80 | build_warnings="${build_warnings} ${t}";; | |
81 | *,) t=`echo "${enableval}" | sed -e "s/,/ /g"` | |
82 | build_warnings="${t} ${build_warnings}";; | |
83 | *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;; | |
84 | esac | |
85 | if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then | |
86 | echo "Setting compiler warning flags = $build_warnings" 6>&1 | |
87 | fi])dnl | |
88 | AC_ARG_ENABLE(gdb-build-warnings, | |
89 | AS_HELP_STRING([--enable-gdb-build-warnings], [enable GDB specific build-time compiler warnings if gcc is used]), | |
90 | [case "${enableval}" in | |
91 | yes) ;; | |
92 | no) build_warnings="-w";; | |
93 | ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"` | |
94 | build_warnings="${build_warnings} ${t}";; | |
95 | *,) t=`echo "${enableval}" | sed -e "s/,/ /g"` | |
96 | build_warnings="${t} ${build_warnings}";; | |
97 | *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;; | |
98 | esac | |
99 | if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then | |
100 | echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1 | |
101 | fi])dnl | |
102 | ||
103 | # The set of warnings supported by a C++ compiler is not the same as | |
104 | # of the C compiler. | |
cf6de44d | 105 | AC_LANG_PUSH([C++]) |
b835bb52 MF |
106 | |
107 | WARN_CFLAGS="" | |
108 | if test "x${build_warnings}" != x -a "x$GCC" = xyes | |
109 | then | |
110 | AC_MSG_CHECKING(compiler warning flags) | |
111 | # Separate out the -Werror flag as some files just cannot be | |
112 | # compiled with it enabled. | |
113 | for w in ${build_warnings}; do | |
114 | # GCC does not complain about -Wno-unknown-warning. Invert | |
115 | # and test -Wunknown-warning instead. | |
116 | case $w in | |
117 | -Wno-*) | |
118 | wtest=`echo $w | sed 's/-Wno-/-W/g'` ;; | |
f1628857 TT |
119 | -Wformat-nonliteral) |
120 | # gcc requires -Wformat before -Wformat-nonliteral | |
121 | # will work, so stick them together. | |
122 | w="-Wformat $w" | |
123 | wtest="$w" | |
124 | ;; | |
b835bb52 MF |
125 | *) |
126 | wtest=$w ;; | |
127 | esac | |
128 | ||
129 | case $w in | |
130 | -Werr*) WERROR_CFLAGS=-Werror ;; | |
131 | *) | |
132 | # Check whether GCC accepts it. | |
133 | saved_CFLAGS="$CFLAGS" | |
3e019bdc | 134 | CFLAGS="$CFLAGS -Werror $wtest" |
b835bb52 | 135 | saved_CXXFLAGS="$CXXFLAGS" |
3e019bdc | 136 | CXXFLAGS="$CXXFLAGS -Werror $wtest" |
a0de763e TT |
137 | if test "x$w" = "x-Wunused-variable"; then |
138 | # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958, | |
139 | # fixed in GCC 4.9. This test is derived from the gdb | |
140 | # source code that triggered this bug in GCC. | |
141 | AC_TRY_COMPILE( | |
142 | [struct scoped_restore_base {}; | |
143 | struct scoped_restore_tmpl : public scoped_restore_base { | |
144 | ~scoped_restore_tmpl() {} | |
145 | };], | |
146 | [const scoped_restore_base &b = scoped_restore_tmpl();], | |
147 | WARN_CFLAGS="${WARN_CFLAGS} $w",) | |
148 | else | |
149 | AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",) | |
150 | fi | |
b835bb52 MF |
151 | CFLAGS="$saved_CFLAGS" |
152 | CXXFLAGS="$saved_CXXFLAGS" | |
153 | esac | |
154 | done | |
155 | AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS}) | |
156 | fi | |
157 | AC_SUBST(WARN_CFLAGS) | |
158 | AC_SUBST(WERROR_CFLAGS) | |
159 | ||
cf6de44d | 160 | AC_LANG_POP([C++]) |
b835bb52 | 161 | ]) |