Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Mon, 06 Apr 2015 15:45:37 UTC Commit: 17b9d8318ca9ca8893e7cacbbdf50b227156714d https://github.com/geany/geany-plugins/commit/17b9d8318ca9ca8893e7cacbbdf50b...
Log Message: ----------- autotools: Improve check for compiler flags
Try and avoid compiler forgiveness about unknown flags to really know whether the compiler understands the flag or just doesn't care much.
This avoids adding flags the compiler might warn about later on, polluting the output. In practice, CLang does this with gcc-like warning flags: it does not treat the ones it doesn't understand as erroneous flags, yet emits warnings about them by default. This leads to the actual build being riddled with warnings about unknown flags, hiding relevant warnings.
To better detect such forgiving compiler behavior, try and find the flag the compiler has for treating warnings as errors, and use it when checking for additional flags. This assumes that if such a flag is used the compiler will either error out when passed an unknown flag, or just shut up completely -- either being OK with us.
Modified Paths: -------------- build/cflags.m4
Modified: build/cflags.m4 39 lines changed, 31 insertions(+), 8 deletions(-) =================================================================== @@ -1,20 +1,43 @@ -dnl GP_CHECK_CFLAG(FLAG, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) -dnl Checks whether the C compiler understands FLAG -AC_DEFUN([GP_CHECK_CFLAG], +dnl _GP_CHECK_CFLAG(FLAG, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +dnl Checks whether the C compiler works when passed FLAG +dnl This might not mean it actually understand the flag, in case it is +dnl forgiving about unknown flags. +AC_DEFUN([_GP_CHECK_CFLAG], [ gp_check_cflag_CFLAGS="$CFLAGS" CFLAGS="$1" - AC_MSG_CHECKING([whether the C compiler understands $CFLAGS]) AC_LANG_PUSH(C) AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main(void) {return 0;}])], - [AC_MSG_RESULT([yes]) - $2], - [AC_MSG_RESULT([no]) - $3]) + [$2], [$3]) AC_LANG_POP(C) CFLAGS="$gp_check_cflag_CFLAGS" ])
+dnl _GP_CHECK_CFLAG_WERROR +dnl Checks for the flag the compiler has to treat warnings as errors +dnl Sets $_GP_CFLAG_WERROR +AC_DEFUN([_GP_CHECK_CFLAG_WERROR], +[ + _GP_CFLAG_WERROR= + AC_MSG_CHECKING([for the C compiler flag to treat warnings as errors]) + _GP_CHECK_CFLAG([-Werror], [_GP_CFLAG_WERROR="-Werror"]) + AC_MSG_RESULT([${_GP_CFLAG_WERROR:-none}]) +]) + +dnl GP_CHECK_CFLAG(FLAG, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +dnl Checks whether the C compiler understands FLAG +AC_DEFUN([GP_CHECK_CFLAG], +[ + AC_REQUIRE([_GP_CHECK_CFLAG_WERROR]) + + AC_MSG_CHECKING([whether the C compiler understands $1]) + _GP_CHECK_CFLAG([$1 $_GP_CFLAG_WERROR], + [AC_MSG_RESULT([yes]) + $2], + [AC_MSG_RESULT([no]) + $3]) +]) + dnl GP_CHECK_CFLAGS dnl Checks for default Geany-Plugins CFLAGS and defines GP_CFLAGS AC_DEFUN([GP_CHECK_CFLAGS],
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).