1 dnl Common configure.ac fragment
3 dnl Copyright (C) 2012-2018 Free Software Foundation, Inc.
5 dnl This file is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; either version 3 of the License, or
8 dnl (at your option) any later version.
10 dnl This program is distributed in the hope that it will be useful,
11 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 dnl GNU General Public License for more details.
15 dnl You should have received a copy of the GNU General Public License
16 dnl along with this program; see the file COPYING3. If not see
17 dnl <http://www.gnu.org/licenses/>.
20 # AC_EGREP_CPP_FOR_BUILD(PATTERN, PROGRAM,
21 # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
22 # ------------------------------------------------------
23 AC_DEFUN([AC_EGREP_CPP_FOR_BUILD],
24 [AC_LANG_PREPROC_REQUIRE()dnl
25 AC_REQUIRE([AC_PROG_EGREP])dnl
26 AC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])])
27 AS_IF([dnl eval is necessary to expand ac_cpp.
28 dnl 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 |
30 dnl Quote $1 to prevent m4 from eating character classes
31 $EGREP "[$1]" >/dev/null 2>&1],
35 ])# AC_EGREP_CPP_FOR_BUILD
38 AC_DEFUN([AM_BINUTILS_WARNINGS],[
39 # Set the 'development' global.
40 . $srcdir/../bfd/development.sh
42 # Set acp_cpp_for_build variable
43 ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
45 # Default set of GCC warnings to enable.
46 GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
47 GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
49 # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
50 AC_EGREP_CPP([^[0-3]$],[__GNUC__],,GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wshadow")
52 # Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
53 AC_EGREP_CPP([^[0-4]$],[__GNUC__],,GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wstack-usage=262144")
55 # Set WARN_WRITE_STRINGS if the compiler supports -Wwrite-strings.
57 AC_EGREP_CPP([^[0-3]$],[__GNUC__],,WARN_WRITE_STRINGS="-Wwrite-strings")
59 # Verify CC_FOR_BUILD to be compatible with warning flags
61 # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
62 AC_EGREP_CPP_FOR_BUILD([^[0-3]$],[__GNUC__],,GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow")
64 # Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
65 AC_EGREP_CPP_FOR_BUILD([^[0-4]$],[__GNUC__],,GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144")
68 [ --enable-werror treat compile warnings as errors],
69 [case "${enableval}" in
70 yes | y) ERROR_ON_WARNING="yes" ;;
71 no | n) ERROR_ON_WARNING="no" ;;
72 *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
75 # Disable -Wformat by default when using gcc on mingw
78 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
79 GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
80 GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
86 # Enable -Werror by default when using gcc. Turn it off for releases.
87 if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" -a "$development" = true ; then
92 if test "${ERROR_ON_WARNING}" = yes ; then
93 GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
94 GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
95 NO_WERROR="-Wno-error"
98 if test "${GCC}" = yes ; then
99 WARN_CFLAGS="${GCC_WARN_CFLAGS}"
100 WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
103 AC_ARG_ENABLE(build-warnings,
104 [ --enable-build-warnings enable build-time compiler warnings],
105 [case "${enableval}" in
106 yes) WARN_CFLAGS="${GCC_WARN_CFLAGS}"
107 WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
108 no) if test "${GCC}" = yes ; then
110 WARN_CFLAGS_FOR_BUILD="-w"
112 ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
113 WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
114 WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
115 *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
116 WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
117 WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
118 *) WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
119 WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
122 if test x"$silent" != x"yes" && test x"$WARN_CFLAGS" != x""; then
123 echo "Setting warning flags = $WARN_CFLAGS" 6>&1
126 AC_SUBST(WARN_CFLAGS)
127 AC_SUBST(WARN_CFLAGS_FOR_BUILD)
129 AC_SUBST(WARN_WRITE_STRINGS)