18dffb485Schristosdnl Autoconf configure script for GDB, the GNU debugger. 2*5ba1f45fSchristosdnl Copyright (C) 1995-2024 Free Software Foundation, Inc. 38dffb485Schristosdnl 48dffb485Schristosdnl This file is part of GDB. 58dffb485Schristosdnl 68dffb485Schristosdnl This program is free software; you can redistribute it and/or modify 78dffb485Schristosdnl it under the terms of the GNU General Public License as published by 88dffb485Schristosdnl the Free Software Foundation; either version 3 of the License, or 98dffb485Schristosdnl (at your option) any later version. 108dffb485Schristosdnl 118dffb485Schristosdnl This program is distributed in the hope that it will be useful, 128dffb485Schristosdnl but WITHOUT ANY WARRANTY; without even the implied warranty of 138dffb485Schristosdnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 148dffb485Schristosdnl GNU General Public License for more details. 158dffb485Schristosdnl 168dffb485Schristosdnl You should have received a copy of the GNU General Public License 178dffb485Schristosdnl along with this program. If not, see <http://www.gnu.org/licenses/>. 188dffb485Schristos 198dffb485SchristosAC_DEFUN([AM_GDB_WARNINGS],[ 208dffb485SchristosAC_ARG_ENABLE(werror, 218dffb485Schristos AS_HELP_STRING([--enable-werror], [treat compile warnings as errors]), 228dffb485Schristos [case "${enableval}" in 238dffb485Schristos yes | y) ERROR_ON_WARNING="yes" ;; 248dffb485Schristos no | n) ERROR_ON_WARNING="no" ;; 258dffb485Schristos *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;; 268dffb485Schristos esac]) 278dffb485Schristos 288dffb485Schristos# Enable -Werror by default when using gcc. Turn it off for releases. 298dffb485Schristosif test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" && $development; then 308dffb485Schristos ERROR_ON_WARNING=yes 318dffb485Schristosfi 328dffb485Schristos 338dffb485SchristosWERROR_CFLAGS="" 348dffb485Schristosif test "${ERROR_ON_WARNING}" = yes ; then 358dffb485Schristos WERROR_CFLAGS="-Werror" 368dffb485Schristosfi 378dffb485Schristos 388dffb485Schristos# The options we'll try to enable. 398dffb485Schristosbuild_warnings="-Wall -Wpointer-arith \ 408dffb485Schristos-Wno-unused -Wunused-value -Wunused-variable -Wunused-function \ 418dffb485Schristos-Wno-switch -Wno-char-subscripts \ 428dffb485Schristos-Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable \ 438dffb485Schristos-Wno-sign-compare -Wno-error=maybe-uninitialized \ 448dffb485Schristos-Wno-mismatched-tags \ 458dffb485Schristos-Wno-error=deprecated-register \ 468dffb485Schristos-Wsuggest-override \ 47*5ba1f45fSchristos-Wimplicit-fallthrough=5 \ 488dffb485Schristos-Wduplicated-cond \ 498dffb485Schristos-Wshadow=local \ 508dffb485Schristos-Wdeprecated-copy \ 518dffb485Schristos-Wdeprecated-copy-dtor \ 528dffb485Schristos-Wredundant-move \ 538dffb485Schristos-Wmissing-declarations \ 548dffb485Schristos-Wstrict-null-sentinel \ 55*5ba1f45fSchristos-Wno-vla-cxx-extension \ 568dffb485Schristos" 578dffb485Schristos 584b169a6bSchristos# The -Wmissing-prototypes flag will be accepted by GCC, but results 594b169a6bSchristos# in a warning being printed about the flag not being valid for C++, 604b169a6bSchristos# this is something to do with using ccache, and argument ordering. 614b169a6bSchristosif test "$GDB_COMPILER_TYPE" != gcc; then 624b169a6bSchristos build_warnings="$build_warnings -Wmissing-prototypes" 634b169a6bSchristosfi 644b169a6bSchristos 658dffb485Schristoscase "${host}" in 668dffb485Schristos *-*-mingw32*) 678dffb485Schristos # Enable -Wno-format by default when using gcc on mingw since many 688dffb485Schristos # GCC versions complain about %I64. 698dffb485Schristos build_warnings="$build_warnings -Wno-format" ;; 708dffb485Schristos *-*-solaris*) 718dffb485Schristos # Solaris 11.4 <python2.7/ceval.h> uses #pragma no_inline that GCC 728dffb485Schristos # doesn't understand. 738dffb485Schristos build_warnings="$build_warnings -Wno-unknown-pragmas" 748dffb485Schristos # Solaris 11 <unistd.h> marks vfork deprecated. 758dffb485Schristos build_warnings="$build_warnings -Wno-deprecated-declarations" ;; 768dffb485Schristos *) 778dffb485Schristos # Note that gcc requires -Wformat for -Wformat-nonliteral to work, 788dffb485Schristos # but there's a special case for this below. 798dffb485Schristos build_warnings="$build_warnings -Wformat-nonliteral" ;; 808dffb485Schristosesac 818dffb485Schristos 828dffb485SchristosAC_ARG_ENABLE(build-warnings, 838dffb485SchristosAS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]), 848dffb485Schristos[case "${enableval}" in 858dffb485Schristos yes) ;; 868dffb485Schristos no) build_warnings="-w";; 878dffb485Schristos ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"` 888dffb485Schristos build_warnings="${build_warnings} ${t}";; 898dffb485Schristos *,) t=`echo "${enableval}" | sed -e "s/,/ /g"` 908dffb485Schristos build_warnings="${t} ${build_warnings}";; 918dffb485Schristos *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;; 928dffb485Schristosesac 938dffb485Schristosif test x"$silent" != x"yes" && test x"$build_warnings" != x""; then 948dffb485Schristos echo "Setting compiler warning flags = $build_warnings" 6>&1 958dffb485Schristosfi])dnl 968dffb485SchristosAC_ARG_ENABLE(gdb-build-warnings, 978dffb485SchristosAS_HELP_STRING([--enable-gdb-build-warnings], [enable GDB specific build-time compiler warnings if gcc is used]), 988dffb485Schristos[case "${enableval}" in 998dffb485Schristos yes) ;; 1008dffb485Schristos no) build_warnings="-w";; 1018dffb485Schristos ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"` 1028dffb485Schristos build_warnings="${build_warnings} ${t}";; 1038dffb485Schristos *,) t=`echo "${enableval}" | sed -e "s/,/ /g"` 1048dffb485Schristos build_warnings="${t} ${build_warnings}";; 1058dffb485Schristos *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;; 1068dffb485Schristosesac 1078dffb485Schristosif test x"$silent" != x"yes" && test x"$build_warnings" != x""; then 1088dffb485Schristos echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1 1098dffb485Schristosfi])dnl 1108dffb485Schristos 1118dffb485Schristos# The set of warnings supported by a C++ compiler is not the same as 1128dffb485Schristos# of the C compiler. 1138dffb485SchristosAC_LANG_PUSH([C++]) 1148dffb485Schristos 1158dffb485SchristosWARN_CFLAGS="" 1168dffb485Schristosif test "x${build_warnings}" != x -a "x$GCC" = xyes 1178dffb485Schristosthen 1188dffb485Schristos AC_MSG_CHECKING(compiler warning flags) 1198dffb485Schristos # Separate out the -Werror flag as some files just cannot be 1208dffb485Schristos # compiled with it enabled. 1218dffb485Schristos for w in ${build_warnings}; do 1228dffb485Schristos # GCC does not complain about -Wno-unknown-warning. Invert 1238dffb485Schristos # and test -Wunknown-warning instead. 1248dffb485Schristos case $w in 1258dffb485Schristos -Wno-*) 1268dffb485Schristos wtest=`echo $w | sed 's/-Wno-/-W/g'` ;; 1278dffb485Schristos -Wformat-nonliteral) 1288dffb485Schristos # gcc requires -Wformat before -Wformat-nonliteral 1298dffb485Schristos # will work, so stick them together. 1308dffb485Schristos w="-Wformat $w" 1318dffb485Schristos wtest="$w" 1328dffb485Schristos ;; 1338dffb485Schristos *) 1348dffb485Schristos wtest=$w ;; 1358dffb485Schristos esac 1368dffb485Schristos 1378dffb485Schristos case $w in 1388dffb485Schristos -Werr*) WERROR_CFLAGS=-Werror ;; 1398dffb485Schristos *) 1408dffb485Schristos # Check whether GCC accepts it. 1418dffb485Schristos saved_CFLAGS="$CFLAGS" 1428dffb485Schristos CFLAGS="$CFLAGS -Werror $wtest" 1438dffb485Schristos saved_CXXFLAGS="$CXXFLAGS" 1448dffb485Schristos CXXFLAGS="$CXXFLAGS -Werror $wtest" 1458dffb485Schristos if test "x$w" = "x-Wunused-variable"; then 1468dffb485Schristos # Check for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38958, 1478dffb485Schristos # fixed in GCC 4.9. This test is derived from the gdb 1488dffb485Schristos # source code that triggered this bug in GCC. 1494b169a6bSchristos AC_COMPILE_IFELSE( 1504b169a6bSchristos [AC_LANG_PROGRAM( 1518dffb485Schristos [struct scoped_restore_base {}; 1528dffb485Schristos struct scoped_restore_tmpl : public scoped_restore_base { 1538dffb485Schristos ~scoped_restore_tmpl() {} 1548dffb485Schristos };], 1554b169a6bSchristos [const scoped_restore_base &b = scoped_restore_tmpl();] 1564b169a6bSchristos )], 1574b169a6bSchristos [WARN_CFLAGS="${WARN_CFLAGS} $w"], 1584b169a6bSchristos [] 1594b169a6bSchristos ) 1608dffb485Schristos else 1614b169a6bSchristos AC_COMPILE_IFELSE( 1624b169a6bSchristos [AC_LANG_PROGRAM([], [])], 1634b169a6bSchristos [WARN_CFLAGS="${WARN_CFLAGS} $w"], 1644b169a6bSchristos [] 1654b169a6bSchristos ) 1668dffb485Schristos fi 1678dffb485Schristos CFLAGS="$saved_CFLAGS" 1688dffb485Schristos CXXFLAGS="$saved_CXXFLAGS" 1698dffb485Schristos esac 1708dffb485Schristos done 1718dffb485Schristos AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS}) 1728dffb485Schristosfi 1738dffb485SchristosAC_SUBST(WARN_CFLAGS) 1748dffb485SchristosAC_SUBST(WERROR_CFLAGS) 1758dffb485Schristos 1768dffb485SchristosAC_LANG_POP([C++]) 1778dffb485Schristos]) 178