Fix crash in "run" on macOS when gdb is not signed
[external/binutils.git] / gdb / warning.m4
1 dnl Autoconf configure script for GDB, the GNU debugger.
2 dnl Copyright (C) 1995-2018 Free Software Foundation, Inc.
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
38 # The options we'll try to enable.
39 build_warnings="-Wall -Wpointer-arith \
40 -Wno-unused -Wunused-value -Wunused-function \
41 -Wno-switch -Wno-char-subscripts \
42 -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \
43 -Wno-sign-compare -Wno-narrowing -Wno-error=maybe-uninitialized \
44 -Wno-mismatched-tags \
45 -Wno-error=deprecated-register \
46 -Wsuggest-override \
47 -Wimplicit-fallthrough=3 \
48 -Wduplicated-cond"
49
50 case "${host}" in
51   *-*-mingw32*)
52     # Enable -Wno-format by default when using gcc on mingw since many
53     # GCC versions complain about %I64.
54     build_warnings="$build_warnings -Wno-format" ;;
55   *-*-solaris*)
56     # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC
57     # doesn't understand.
58     build_warnings="$build_warnings -Wno-unknown-pragmas"
59     # Solaris 11 <unistd.h> marks vfork deprecated.
60     build_warnings="$build_warnings -Wno-deprecated-declarations" ;;
61   *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
62 esac
63
64 AC_ARG_ENABLE(build-warnings,
65 AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
66 [case "${enableval}" in
67   yes)  ;;
68   no)   build_warnings="-w";;
69   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
70         build_warnings="${build_warnings} ${t}";;
71   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
72         build_warnings="${t} ${build_warnings}";;
73   *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
74 esac
75 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
76   echo "Setting compiler warning flags = $build_warnings" 6>&1
77 fi])dnl
78 AC_ARG_ENABLE(gdb-build-warnings,
79 AS_HELP_STRING([--enable-gdb-build-warnings], [enable GDB specific build-time compiler warnings if gcc is used]),
80 [case "${enableval}" in
81   yes)  ;;
82   no)   build_warnings="-w";;
83   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
84         build_warnings="${build_warnings} ${t}";;
85   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
86         build_warnings="${t} ${build_warnings}";;
87   *)    build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
88 esac
89 if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
90   echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
91 fi])dnl
92
93 # The set of warnings supported by a C++ compiler is not the same as
94 # of the C compiler.
95 AC_LANG_PUSH([C++])
96
97 WARN_CFLAGS=""
98 if test "x${build_warnings}" != x -a "x$GCC" = xyes
99 then
100     AC_MSG_CHECKING(compiler warning flags)
101     # Separate out the -Werror flag as some files just cannot be
102     # compiled with it enabled.
103     for w in ${build_warnings}; do
104         # GCC does not complain about -Wno-unknown-warning.  Invert
105         # and test -Wunknown-warning instead.
106         case $w in
107         -Wno-*)
108                 wtest=`echo $w | sed 's/-Wno-/-W/g'` ;;
109         *)
110                 wtest=$w ;;
111         esac
112
113         case $w in
114         -Werr*) WERROR_CFLAGS=-Werror ;;
115         *)
116             # Check whether GCC accepts it.
117             saved_CFLAGS="$CFLAGS"
118             CFLAGS="$CFLAGS -Werror $wtest"
119             saved_CXXFLAGS="$CXXFLAGS"
120             CXXFLAGS="$CXXFLAGS -Werror $wtest"
121             AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
122             CFLAGS="$saved_CFLAGS"
123             CXXFLAGS="$saved_CXXFLAGS"
124         esac
125     done
126     AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
127 fi
128 AC_SUBST(WARN_CFLAGS)
129 AC_SUBST(WERROR_CFLAGS)
130
131 AC_LANG_POP([C++])
132 ])