ri-gcc-warnings.m4 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. dnl ri_GCC_WARNINGS()
  2. dnl
  3. dnl Adjust the CPPFLAGS, CFLAGS and CXXFLAGS for various GCC versions
  4. AC_DEFUN([ri_GCC_WARNINGS],
  5. [AC_ARG_ENABLE([gcc-warnings],
  6. [AC_HELP_STRING([--enable-gcc-warnings[[[[=error]]]]],
  7. [enable additional gcc warning flags])])
  8. if test x"$GCC" = x"yes"; then
  9. if test x"$enable_gcc_warnings" = x"yes" -o x"$enable_gcc_warnings" = x"error"; then
  10. ri_gcc_main=`echo __GNUC__ | $CPP -E - | grep -v ^\#`
  11. ri_gcc_minor=`echo __GNUC_MINOR__ | $CPP -E - | grep -v ^\#`
  12. ri_cppflags=""
  13. ri_cflags=""
  14. ri_cxxflags=""
  15. ri_bothflags=""
  16. ri_gcc_v2_95="false"
  17. test $ri_gcc_main -gt 2 && ri_gcc_v2_95="true"
  18. test $ri_gcc_main -eq 2 && test $ri_gcc_minor -ge 95 && ri_gcc_v2_95="true"
  19. ri_gcc_v3_2="false"
  20. test $ri_gcc_main -gt 3 && ri_gcc_v3_2="true"
  21. test $ri_gcc_main -eq 3 && test $ri_gcc_minor -ge 2 && ri_gcc_v3_2="true"
  22. ri_gcc_v3_3="false"
  23. test $ri_gcc_main -gt 3 && ri_gcc_v3_3="true"
  24. test $ri_gcc_main -eq 3 && test $ri_gcc_minor -ge 3 && ri_gcc_v3_3="true"
  25. ri_gcc_v3_4="false"
  26. test $ri_gcc_main -gt 3 && ri_gcc_v3_4="true"
  27. test $ri_gcc_main -eq 3 && test $ri_gcc_minor -ge 4 && ri_gcc_v3_4="true"
  28. if $ri_gcc_v3_4; then
  29. ri_bothflags="-Wextra -Wall -pedantic"
  30. else
  31. ri_bothflags="-W -Wall -pedantic"
  32. fi
  33. if $ri_gcc_v2_95; then
  34. # the following options are taken from the gcc-2.95 info page
  35. ri_bothflags="$ri_bothflags -Wcast-align"
  36. ri_bothflags="$ri_bothflags -Wcast-qual"
  37. ri_bothflags="$ri_bothflags -Wmissing-prototypes"
  38. ri_bothflags="$ri_bothflags -Wmultichar"
  39. ri_bothflags="$ri_bothflags -Wpointer-arith"
  40. ri_bothflags="$ri_bothflags -Wredundant-decls"
  41. ri_bothflags="$ri_bothflags -Wshadow"
  42. ri_bothflags="$ri_bothflags -Wsign-compare"
  43. ri_bothflags="$ri_bothflags -Wundef"
  44. ri_bothflags="$ri_bothflags -Wwrite-strings"
  45. ri_cflags="$ri_cflags -Waggregate-return"
  46. ri_cflags="$ri_cflags -Wbad-function-cast"
  47. ri_cflags="$ri_cflags -Wmissing-declarations"
  48. ri_cflags="$ri_cflags -Wnested-externs"
  49. ri_cflags="$ri_cflags -Wstrict-prototypes"
  50. ri_cflags="$ri_cflags -Wmissing-declarations"
  51. fi
  52. if $ri_gcc_v3_2; then
  53. # the following options are taken from the gcc-3.2.1 info page
  54. ri_cflags="$ri_cflags -Wdiv-by-zero"
  55. ri_bothflags="$ri_bothflags -Wfloat-equal"
  56. fi
  57. if $ri_gcc_v3_3; then
  58. # the following options are taken from the gcc-3.3.2 info page
  59. ri_cppflags="$ri_cppflags -Wendif-labels"
  60. ri_bothflags="$ri_bothflags -Wdisabled-optimization"
  61. fi
  62. if test x"$enable_gcc_warnings" = x"error"; then
  63. ri_bothflags="$ri_bothflags -Werror"
  64. fi
  65. CPPFLAGS="$CPPFLAGS $ri_cppflags"
  66. CFLAGS="$ri_bothflags $ri_cflags $CFLAGS"
  67. CXXFLAGS="$ri_bothflags $ri_cxxflags $CXXFLAGS"
  68. fi
  69. fi
  70. ])