You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.8 KiB

  1. # gnome-compiler-flags.m4
  2. #
  3. # serial 4
  4. #
  5. dnl GNOME_COMPILE_WARNINGS
  6. dnl Turn on many useful compiler warnings and substitute the result into
  7. dnl WARN_CFLAGS
  8. dnl For now, only works on GCC
  9. dnl Pass the default value of the --enable-compile-warnings configure option as
  10. dnl the first argument to the macro, defaulting to 'yes'.
  11. dnl Additional warning/error flags can be passed as an optional second argument.
  12. dnl
  13. dnl For example: GNOME_COMPILE_WARNINGS([maximum],[-Werror=some-flag -Wfoobar])
  14. AU_DEFUN([GNOME_COMPILE_WARNINGS],[
  15. dnl ******************************
  16. dnl More compiler warnings
  17. dnl ******************************
  18. AC_ARG_ENABLE(compile-warnings,
  19. AS_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
  20. [Turn on compiler warnings]),,
  21. [enable_compile_warnings="m4_default([$1],[yes])"])
  22. if test "x$GCC" != xyes; then
  23. enable_compile_warnings=no
  24. fi
  25. warning_flags=
  26. realsave_CFLAGS="$CFLAGS"
  27. dnl These are warning flags that aren't marked as fatal. Can be
  28. dnl overridden on a per-project basis with -Wno-foo.
  29. base_warn_flags=" \
  30. -Wall \
  31. -Wstrict-prototypes \
  32. -Wnested-externs \
  33. "
  34. dnl These compiler flags typically indicate very broken or suspicious
  35. dnl code. Some of them such as implicit-function-declaration are
  36. dnl just not default because gcc compiles a lot of legacy code.
  37. dnl We choose to make this set into explicit errors.
  38. base_error_flags=" \
  39. -Werror=missing-prototypes \
  40. -Werror=implicit-function-declaration \
  41. -Werror=pointer-arith \
  42. -Werror=init-self \
  43. -Werror=format-security \
  44. -Werror=format=2 \
  45. -Werror=missing-include-dirs \
  46. -Werror=return-type \
  47. "
  48. dnl Additional warning or error flags provided by the module author to
  49. dnl allow stricter standards to be imposed on a per-module basis.
  50. dnl The author can pass -W or -Werror flags here as they see fit.
  51. additional_flags="m4_default([$2],[])"
  52. case "$enable_compile_warnings" in
  53. no)
  54. warning_flags="-w"
  55. ;;
  56. minimum)
  57. warning_flags="-Wall"
  58. ;;
  59. yes|maximum|error)
  60. warning_flags="$base_warn_flags $base_error_flags $additional_flags"
  61. ;;
  62. *)
  63. AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
  64. ;;
  65. esac
  66. if test "$enable_compile_warnings" = "error" ; then
  67. warning_flags="$warning_flags -Werror"
  68. fi
  69. dnl Check whether GCC supports the warning options
  70. for option in $warning_flags; do
  71. save_CFLAGS="$CFLAGS"
  72. CFLAGS="$CFLAGS $option"
  73. AC_MSG_CHECKING([whether gcc understands $option])
  74. AC_TRY_COMPILE([], [],
  75. has_option=yes,
  76. has_option=no,)
  77. CFLAGS="$save_CFLAGS"
  78. AC_MSG_RESULT([$has_option])
  79. if test $has_option = yes; then
  80. tested_warning_flags="$tested_warning_flags $option"
  81. fi
  82. unset has_option
  83. unset save_CFLAGS
  84. done
  85. unset option
  86. CFLAGS="$realsave_CFLAGS"
  87. AC_MSG_CHECKING(what warning flags to pass to the C compiler)
  88. AC_MSG_RESULT($tested_warning_flags)
  89. AC_ARG_ENABLE(iso-c,
  90. AS_HELP_STRING([--enable-iso-c],
  91. [Try to warn if code is not ISO C ]),,
  92. [enable_iso_c=no])
  93. AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
  94. complCFLAGS=
  95. if test "x$enable_iso_c" != "xno"; then
  96. if test "x$GCC" = "xyes"; then
  97. case " $CFLAGS " in
  98. *[\ \ ]-ansi[\ \ ]*) ;;
  99. *) complCFLAGS="$complCFLAGS -ansi" ;;
  100. esac
  101. case " $CFLAGS " in
  102. *[\ \ ]-pedantic[\ \ ]*) ;;
  103. *) complCFLAGS="$complCFLAGS -pedantic" ;;
  104. esac
  105. fi
  106. fi
  107. AC_MSG_RESULT($complCFLAGS)
  108. WARN_CFLAGS="$tested_warning_flags $complCFLAGS"
  109. AC_SUBST(WARN_CFLAGS)
  110. ],
  111. [[$0: This macro is deprecated. You should use AX_COMPILER_FLAGS instead and
  112. eliminate use of --enable-iso-c.
  113. See: http://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html#ax_compiler_flags]])
  114. dnl For C++, do basically the same thing.
  115. AU_DEFUN([GNOME_CXX_WARNINGS],[
  116. AC_ARG_ENABLE(cxx-warnings,
  117. AS_HELP_STRING([--enable-cxx-warnings=@<:@no/minimum/yes@:>@]
  118. [Turn on compiler warnings.]),,
  119. [enable_cxx_warnings="m4_default([$1],[minimum])"])
  120. AC_MSG_CHECKING(what warning flags to pass to the C++ compiler)
  121. warnCXXFLAGS=
  122. if test "x$GXX" != xyes; then
  123. enable_cxx_warnings=no
  124. fi
  125. if test "x$enable_cxx_warnings" != "xno"; then
  126. if test "x$GXX" = "xyes"; then
  127. case " $CXXFLAGS " in
  128. *[\ \ ]-Wall[\ \ ]*) ;;
  129. *) warnCXXFLAGS="-Wall -Wno-unused" ;;
  130. esac
  131. ## -W is not all that useful. And it cannot be controlled
  132. ## with individual -Wno-xxx flags, unlike -Wall
  133. if test "x$enable_cxx_warnings" = "xyes"; then
  134. warnCXXFLAGS="$warnCXXFLAGS -Wshadow -Woverloaded-virtual"
  135. fi
  136. fi
  137. fi
  138. AC_MSG_RESULT($warnCXXFLAGS)
  139. AC_ARG_ENABLE(iso-cxx,
  140. AS_HELP_STRING([--enable-iso-cxx],
  141. [Try to warn if code is not ISO C++ ]),,
  142. [enable_iso_cxx=no])
  143. AC_MSG_CHECKING(what language compliance flags to pass to the C++ compiler)
  144. complCXXFLAGS=
  145. if test "x$enable_iso_cxx" != "xno"; then
  146. if test "x$GXX" = "xyes"; then
  147. case " $CXXFLAGS " in
  148. *[\ \ ]-ansi[\ \ ]*) ;;
  149. *) complCXXFLAGS="$complCXXFLAGS -ansi" ;;
  150. esac
  151. case " $CXXFLAGS " in
  152. *[\ \ ]-pedantic[\ \ ]*) ;;
  153. *) complCXXFLAGS="$complCXXFLAGS -pedantic" ;;
  154. esac
  155. fi
  156. fi
  157. AC_MSG_RESULT($complCXXFLAGS)
  158. WARN_CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS"
  159. AC_SUBST(WARN_CXXFLAGS)
  160. ],
  161. [[$0: This macro is deprecated. You should use AX_COMPILER_FLAGS instead and
  162. eliminate use of --enable-iso-cxx.
  163. See: http://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html#ax_compiler_flags]])