warning.m4 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. dnl Common configure.ac fragment
  2. dnl
  3. dnl Copyright (C) 2012-2022 Free Software Foundation, Inc.
  4. dnl
  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.
  9. dnl
  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.
  14. dnl
  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/>.
  18. dnl
  19. # AC_EGREP_CPP_FOR_BUILD(PATTERN, PROGRAM,
  20. # [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  21. # ------------------------------------------------------
  22. AC_DEFUN([AC_EGREP_CPP_FOR_BUILD],
  23. [AC_LANG_PREPROC_REQUIRE()dnl
  24. AC_REQUIRE([AC_PROG_EGREP])dnl
  25. AC_LANG_CONFTEST([AC_LANG_SOURCE([[$2]])])
  26. AS_IF([dnl eval is necessary to expand ac_cpp.
  27. dnl Ultrix and Pyramid sh refuse to redirect output of eval, so use subshell.
  28. (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&AS_MESSAGE_LOG_FD |
  29. dnl Quote $1 to prevent m4 from eating character classes
  30. $EGREP "[$1]" >/dev/null 2>&1],
  31. [$3],
  32. [$4])
  33. rm -f conftest*
  34. ])# AC_EGREP_CPP_FOR_BUILD
  35. AC_DEFUN([AM_BINUTILS_WARNINGS],[
  36. # Set the 'development' global.
  37. . $srcdir/../bfd/development.sh
  38. # Set acp_cpp_for_build variable
  39. ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
  40. # Default set of GCC warnings to enable.
  41. GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
  42. GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
  43. # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
  44. AC_EGREP_CPP([(^[0-3]$|^__GNUC__$)],[__GNUC__],,GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wshadow")
  45. # Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
  46. AC_EGREP_CPP([(^[0-4]$|^__GNUC__$)],[__GNUC__],,GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wstack-usage=262144")
  47. # Set WARN_WRITE_STRINGS if the compiler supports -Wwrite-strings.
  48. WARN_WRITE_STRINGS=""
  49. AC_EGREP_CPP([(^[0-3]$|^__GNUC__$)],[__GNUC__],,WARN_WRITE_STRINGS="-Wwrite-strings")
  50. # Verify CC_FOR_BUILD to be compatible with warning flags
  51. # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
  52. AC_EGREP_CPP_FOR_BUILD([(^[0-3]$|^__GNUC__$)],[__GNUC__],,GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow")
  53. # Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
  54. AC_EGREP_CPP_FOR_BUILD([(^[0-4]$|^__GNUC__$)],[__GNUC__],,GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144")
  55. AC_ARG_ENABLE(werror,
  56. [ --enable-werror treat compile warnings as errors],
  57. [case "${enableval}" in
  58. yes | y) ERROR_ON_WARNING="yes" ;;
  59. no | n) ERROR_ON_WARNING="no" ;;
  60. *) AC_MSG_ERROR(bad value ${enableval} for --enable-werror) ;;
  61. esac])
  62. # Disable -Wformat by default when using gcc on mingw
  63. case "${host}" in
  64. *-*-mingw32*)
  65. if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
  66. GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
  67. GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
  68. fi
  69. ;;
  70. *) ;;
  71. esac
  72. # Enable -Werror by default when using gcc. Turn it off for releases.
  73. if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" -a "$development" = true ; then
  74. ERROR_ON_WARNING=yes
  75. fi
  76. NO_WERROR=
  77. if test "${ERROR_ON_WARNING}" = yes ; then
  78. GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
  79. GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
  80. NO_WERROR="-Wno-error"
  81. fi
  82. if test "${GCC}" = yes ; then
  83. WARN_CFLAGS="${GCC_WARN_CFLAGS}"
  84. WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
  85. fi
  86. AC_ARG_ENABLE(build-warnings,
  87. [ --enable-build-warnings enable build-time compiler warnings],
  88. [case "${enableval}" in
  89. yes) WARN_CFLAGS="${GCC_WARN_CFLAGS}"
  90. WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
  91. no) if test "${GCC}" = yes ; then
  92. WARN_CFLAGS="-w"
  93. WARN_CFLAGS_FOR_BUILD="-w"
  94. fi;;
  95. ,*) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  96. WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
  97. WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
  98. *,) t=`echo "${enableval}" | sed -e "s/,/ /g"`
  99. WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
  100. WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
  101. *) WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
  102. WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
  103. esac])
  104. if test x"$silent" != x"yes" && test x"$WARN_CFLAGS" != x""; then
  105. echo "Setting warning flags = $WARN_CFLAGS" 6>&1
  106. fi
  107. AC_SUBST(WARN_CFLAGS)
  108. AC_SUBST(WARN_CFLAGS_FOR_BUILD)
  109. AC_SUBST(NO_WERROR)
  110. AC_SUBST(WARN_WRITE_STRINGS)
  111. ])