sim_ac_option_warnings.m4 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. dnl Copyright (C) 1997-2022 Free Software Foundation, Inc.
  2. dnl
  3. dnl This program is free software; you can redistribute it and/or modify
  4. dnl it under the terms of the GNU General Public License as published by
  5. dnl the Free Software Foundation; either version 3 of the License, or
  6. dnl (at your option) any later version.
  7. dnl
  8. dnl This program is distributed in the hope that it will be useful,
  9. dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. dnl GNU General Public License for more details.
  12. dnl
  13. dnl You should have received a copy of the GNU General Public License
  14. dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. dnl
  16. dnl --enable-build-warnings is for developers of the simulator.
  17. dnl it enables extra GCC specific warnings.
  18. AC_DEFUN([SIM_AC_OPTION_WARNINGS],
  19. [
  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. dnl Enable -Werror by default when using gcc
  28. if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
  29. ERROR_ON_WARNING=yes
  30. fi
  31. WERROR_CFLAGS=""
  32. if test "${ERROR_ON_WARNING}" = yes ; then
  33. WERROR_CFLAGS="-Werror"
  34. fi
  35. dnl The options we'll try to enable.
  36. dnl NB: Kept somewhat in sync with gdbsupport/warnings.m4.
  37. build_warnings="-Wall -Wdeclaration-after-statement -Wpointer-arith
  38. -Wno-unused -Wunused-value -Wunused-function
  39. -Wno-switch -Wno-char-subscripts
  40. -Wempty-body -Wunused-but-set-parameter
  41. -Wno-error=maybe-uninitialized
  42. -Wmissing-declarations
  43. -Wmissing-prototypes
  44. -Wdeclaration-after-statement -Wmissing-parameter-type
  45. -Wpointer-sign
  46. -Wold-style-declaration -Wold-style-definition
  47. "
  48. # Enable -Wno-format by default when using gcc on mingw since many
  49. # GCC versions complain about %I64.
  50. case "${host}" in
  51. *-*-mingw32*) build_warnings="$build_warnings -Wno-format" ;;
  52. *) build_warnings="$build_warnings -Wformat-nonliteral" ;;
  53. esac
  54. AC_ARG_ENABLE(build-warnings,
  55. AS_HELP_STRING([--enable-build-warnings], [enable build-time compiler warnings if gcc is used]),
  56. [case "${enableval}" in
  57. yes) ;;
  58. no) build_warnings="-w";;
  59. ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  60. build_warnings="${build_warnings} ${t}";;
  61. *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  62. build_warnings="${t} ${build_warnings}";;
  63. *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
  64. esac
  65. if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
  66. echo "Setting compiler warning flags = $build_warnings" 6>&1
  67. fi])dnl
  68. AC_ARG_ENABLE(sim-build-warnings,
  69. AS_HELP_STRING([--enable-sim-build-warnings], [enable SIM specific build-time compiler warnings if gcc is used]),
  70. [case "${enableval}" in
  71. yes) ;;
  72. no) build_warnings="-w";;
  73. ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  74. build_warnings="${build_warnings} ${t}";;
  75. *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  76. build_warnings="${t} ${build_warnings}";;
  77. *) build_warnings=`echo "${enableval}" | sed -e "s/,/ /g"`;;
  78. esac
  79. if test x"$silent" != x"yes" && test x"$build_warnings" != x""; then
  80. echo "Setting GDB specific compiler warning flags = $build_warnings" 6>&1
  81. fi])dnl
  82. WARN_CFLAGS=""
  83. if test "x${build_warnings}" != x -a "x$GCC" = xyes
  84. then
  85. AC_MSG_CHECKING(compiler warning flags)
  86. # Separate out the -Werror flag as some files just cannot be
  87. # compiled with it enabled.
  88. for w in ${build_warnings}; do
  89. case $w in
  90. -Werr*) WERROR_CFLAGS=-Werror ;;
  91. *) # Check that GCC accepts it
  92. saved_CFLAGS="$CFLAGS"
  93. CFLAGS="$CFLAGS -Werror $w"
  94. AC_TRY_COMPILE([],[],WARN_CFLAGS="${WARN_CFLAGS} $w",)
  95. CFLAGS="$saved_CFLAGS"
  96. esac
  97. done
  98. AC_MSG_RESULT(${WARN_CFLAGS} ${WERROR_CFLAGS})
  99. fi
  100. ])
  101. AC_SUBST(WARN_CFLAGS)
  102. AC_SUBST(WERROR_CFLAGS)