]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/warning.m4
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / bfd / warning.m4
CommitLineData
1110793a 1dnl Common configure.ac fragment
5bf135a7 2dnl
fd67aa11 3dnl Copyright (C) 2012-2024 Free Software Foundation, Inc.
5bf135a7
NC
4dnl
5dnl This file is free software; you can redistribute it and/or modify
6dnl it under the terms of the GNU General Public License as published by
7dnl the Free Software Foundation; either version 3 of the License, or
8dnl (at your option) any later version.
1b786873 9dnl
5bf135a7
NC
10dnl This program is distributed in the hope that it will be useful,
11dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13dnl GNU General Public License for more details.
1b786873 14dnl
5bf135a7
NC
15dnl You should have received a copy of the GNU General Public License
16dnl along with this program; see the file COPYING3. If not see
17dnl <http://www.gnu.org/licenses/>.
18dnl
9e9b66a9 19
c5da1932
VZ
20# AC_EGREP_CPP_FOR_BUILD(PATTERN, PROGRAM,
21# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
22# ------------------------------------------------------
23AC_DEFUN([AC_EGREP_CPP_FOR_BUILD],
24[AC_LANG_PREPROC_REQUIRE()dnl
25AC_REQUIRE([AC_PROG_EGREP])dnl
26AC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])])
27AS_IF([dnl eval is necessary to expand ac_cpp.
28dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
29(eval "$ac_cpp_for_build conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
30dnl Quote $1 to prevent m4 from eating character classes
31 $EGREP "[$1]" >/dev/null 2>&1],
32 [$3],
33 [$4])
34rm -f conftest*
35])# AC_EGREP_CPP_FOR_BUILD
36
37
9e9b66a9 38AC_DEFUN([AM_BINUTILS_WARNINGS],[
270c9937
JB
39# Set the 'development' global.
40. $srcdir/../bfd/development.sh
41
c5da1932
VZ
42# Set acp_cpp_for_build variable
43ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
44
9780e045 45# Default set of GCC warnings to enable.
d1a98e0c 46GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
c5da1932 47GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
9780e045
NC
48
49# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
3107326d 50AC_EGREP_CPP([(^[0-3]$|^__GNUC__$)],[__GNUC__],,GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wshadow")
9e9b66a9 51
9780e045 52# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
491cf317
TO
53AC_EGREP_CPP([(^[0-4]$|^__GNUC__$)],[__GNUC__],,dnl
54[AC_EGREP_CPP([^__clang__$],[__clang__],[GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wstack-usage=262144"],)])
9780e045 55
6757cf57
TS
56# Set WARN_WRITE_STRINGS if the compiler supports -Wwrite-strings.
57WARN_WRITE_STRINGS=""
3107326d 58AC_EGREP_CPP([(^[0-3]$|^__GNUC__$)],[__GNUC__],,WARN_WRITE_STRINGS="-Wwrite-strings")
9780e045 59
96fe4562 60# Verify CC_FOR_BUILD to be compatible with warning flags
c5da1932
VZ
61
62# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
3107326d 63AC_EGREP_CPP_FOR_BUILD([(^[0-3]$|^__GNUC__$)],[__GNUC__],,GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow")
c5da1932
VZ
64
65# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
491cf317
TO
66AC_EGREP_CPP_FOR_BUILD([(^[0-4]$|^__GNUC__$)],[__GNUC__],,dnl
67[AC_EGREP_CPP_FOR_BUILD([^__clang__$],[__clang__],[GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"],)])
c5da1932 68
9e9b66a9 69AC_ARG_ENABLE(werror,
241a6c40 70 [ --enable-werror treat compile warnings as errors],
9e9b66a9
AM
71 [case "${enableval}" in
72 yes | y) ERROR_ON_WARNING="yes" ;;
73 no | n) ERROR_ON_WARNING="no" ;;
74 *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
75 esac])
76
d1a98e0c 77# Disable -Wformat by default when using gcc on mingw
bb8541b9
L
78case "${host}" in
79 *-*-mingw32*)
80 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
81 GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
c5da1932 82 GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
bb8541b9
L
83 fi
84 ;;
85 *) ;;
86esac
87
270c9937
JB
88# Enable -Werror by default when using gcc. Turn it off for releases.
89if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" -a "$development" = true ; then
9e9b66a9
AM
90 ERROR_ON_WARNING=yes
91fi
92
93NO_WERROR=
94if test "${ERROR_ON_WARNING}" = yes ; then
9780e045 95 GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
c5da1932 96 GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
9e9b66a9
AM
97 NO_WERROR="-Wno-error"
98fi
1b786873 99
49c96104
SE
100if test "${GCC}" = yes ; then
101 WARN_CFLAGS="${GCC_WARN_CFLAGS}"
c5da1932 102 WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
49c96104
SE
103fi
104
9e9b66a9 105AC_ARG_ENABLE(build-warnings,
241a6c40 106[ --enable-build-warnings enable build-time compiler warnings],
9e9b66a9 107[case "${enableval}" in
c5da1932
VZ
108 yes) WARN_CFLAGS="${GCC_WARN_CFLAGS}"
109 WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
49c96104
SE
110 no) if test "${GCC}" = yes ; then
111 WARN_CFLAGS="-w"
c5da1932 112 WARN_CFLAGS_FOR_BUILD="-w"
49c96104 113 fi;;
9e9b66a9 114 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
c5da1932
VZ
115 WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
116 WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
9e9b66a9 117 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
c5da1932
VZ
118 WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
119 WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
120 *) WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
121 WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
9e9b66a9
AM
122esac])
123
124if test x"$silent" != x"yes" && test x"$WARN_CFLAGS" != x""; then
125 echo "Setting warning flags = $WARN_CFLAGS" 6>&1
126fi
127
128AC_SUBST(WARN_CFLAGS)
c5da1932 129AC_SUBST(WARN_CFLAGS_FOR_BUILD)
9e9b66a9 130AC_SUBST(NO_WERROR)
6757cf57 131 AC_SUBST(WARN_WRITE_STRINGS)
9e9b66a9 132])