Patrick Williams | ddad1a1 | 2017-02-23 20:36:32 -0600 | [diff] [blame^] | 1 | From 4cfb728804157e8f3c69e11ba4df449d8f76388f Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Thu, 20 Oct 2016 04:42:26 +0000 |
| 4 | Subject: [PATCH] Detect clang |
| 5 | |
| 6 | Check for clang compiler since we need to disable |
| 7 | unused-function warning for clang, at same time |
| 8 | pass werror when checking for compiler options if |
| 9 | werror is enabled so spurious options do not get |
| 10 | enabled. Only the ones that are supported by given |
| 11 | compiler are accepted. |
| 12 | |
| 13 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 14 | Upstream-Status: Pending |
| 15 | --- |
| 16 | m4/compiler-warnings.m4 | 29 +++++++++++++++++++++++++---- |
| 17 | 1 file changed, 25 insertions(+), 4 deletions(-) |
| 18 | |
| 19 | diff --git a/m4/compiler-warnings.m4 b/m4/compiler-warnings.m4 |
| 20 | index de4a8b0..e4ba718 100644 |
| 21 | --- a/m4/compiler-warnings.m4 |
| 22 | +++ b/m4/compiler-warnings.m4 |
| 23 | @@ -2,10 +2,30 @@ AC_DEFUN([LIBQMI_COMPILER_WARNINGS], |
| 24 | [AC_ARG_ENABLE(more-warnings, |
| 25 | AS_HELP_STRING([--enable-more-warnings], [Possible values: no/yes/error]), |
| 26 | set_more_warnings="$enableval",set_more_warnings=error) |
| 27 | + |
| 28 | +# Clang throws a lot of warnings when it does not understand a flag. Disable |
| 29 | +# this warning for now so other warnings are visible. |
| 30 | +AC_MSG_CHECKING([if compiling with clang]) |
| 31 | +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ |
| 32 | +#ifndef __clang__ |
| 33 | + not clang |
| 34 | +#endif |
| 35 | + ]])], |
| 36 | + [CLANG=yes], |
| 37 | + [CLANG=no] |
| 38 | +) |
| 39 | +AC_MSG_RESULT([$CLANG]) |
| 40 | +AS_IF([test "x$CLANG" = "xyes"], [CLANG_FLAGS=-Wno-error=unused-function]) |
| 41 | +CFLAGS="$CFLAGS $CLANG_FLAGS" |
| 42 | +LDFLAGS="$LDFLAGS $CLANG_FLAGS" |
| 43 | + |
| 44 | AC_MSG_CHECKING(for more warnings) |
| 45 | if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then |
| 46 | AC_MSG_RESULT(yes) |
| 47 | CFLAGS="-Wall -std=gnu89 $CFLAGS" |
| 48 | + if test "x$set_more_warnings" = xerror; then |
| 49 | + WERROR="-Werror" |
| 50 | + fi |
| 51 | |
| 52 | for option in -Wmissing-declarations -Wmissing-prototypes \ |
| 53 | -Wdeclaration-after-statement -Wstrict-prototypes \ |
| 54 | @@ -17,22 +37,23 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then |
| 55 | -Wmissing-include-dirs -Waggregate-return \ |
| 56 | -Wformat-security; do |
| 57 | SAVE_CFLAGS="$CFLAGS" |
| 58 | - CFLAGS="$CFLAGS $option" |
| 59 | + CFLAGS="$CFLAGS $option $WERROR" |
| 60 | AC_MSG_CHECKING([whether gcc understands $option]) |
| 61 | AC_TRY_COMPILE([], [], |
| 62 | has_option=yes, |
| 63 | has_option=no,) |
| 64 | if test $has_option = no; then |
| 65 | CFLAGS="$SAVE_CFLAGS" |
| 66 | + else |
| 67 | + CFLAGS="$SAVE_CFLAGS $option" |
| 68 | fi |
| 69 | AC_MSG_RESULT($has_option) |
| 70 | unset has_option |
| 71 | unset SAVE_CFLAGS |
| 72 | done |
| 73 | + CFLAGS="$CFLAGS $WERROR" |
| 74 | unset option |
| 75 | - if test "x$set_more_warnings" = xerror; then |
| 76 | - CFLAGS="$CFLAGS -Werror" |
| 77 | - fi |
| 78 | + unset WERROR |
| 79 | else |
| 80 | AC_MSG_RESULT(no) |
| 81 | fi |
| 82 | -- |
| 83 | 1.9.1 |
| 84 | |