Skip to content
This repository
Browse code

Grep for clang warnings when testing compiler flag support

There is no way to make clang's "argument unused" warning fatal.

Ideally the search string would also include 'clang: ' but this output might
depend on clang's argv[0].
  • Loading branch information...
commit 62b6137ff5b1c280ba99a0ba1b64b4a03cb3f779 1 parent b5ab0d0
Keegan McAllister kmcallister authored committed

Showing 2 changed files with 38 additions and 0 deletions. Show diff stats Hide diff stats

  1. +16 0 configure.ac
  2. +22 0 scripts/wrap-compiler-for-flag-check
16 configure.ac
@@ -44,6 +44,18 @@ AC_ARG_ENABLE([compile-warnings],
44 44 AC_SUBST([WARNING_CXXFLAGS])
45 45 AC_SUBST([PICKY_CXXFLAGS])
46 46
  47 +# We want to check for compiler flag support, but there is no way to make
  48 +# clang's "argument unused" warning fatal. So we invoke the compiler through a
  49 +# wrapper script that greps for this message.
  50 +
  51 +saved_CC="$CC"
  52 +saved_CXX="$CXX"
  53 +saved_LD="$LD"
  54 +flag_wrap="$srcdir/scripts/wrap-compiler-for-flag-check"
  55 +CC="$flag_wrap $CC"
  56 +CXX="$flag_wrap $CXX"
  57 +LD="$flag_wrap $LD"
  58 +
47 59 # We use the same hardening flags for C and C++. We must check that each flag
48 60 # is supported by both compilers.
49 61 AC_DEFUN([check_cc_cxx_flag],
@@ -89,6 +101,10 @@ AS_IF([test x"$hardening" != x"no"], [
89 101 AC_SUBST([HARDEN_CFLAGS])
90 102 AC_SUBST([HARDEN_LDFLAGS])
91 103
  104 +CC="$saved_CC"
  105 +CXX="$saved_CXX"
  106 +LD="$saved_LD"
  107 +
92 108 AC_ARG_ENABLE([client],
93 109 [AS_HELP_STRING([--enable-client], [Build the mosh-client program @<:@yes@:>@])],
94 110 [build_client="$enableval"],
22 scripts/wrap-compiler-for-flag-check
... ... @@ -0,0 +1,22 @@
  1 +#!/bin/sh
  2 +
  3 +# There is no way to make clang's "argument unused" warning fatal. So when
  4 +# configure checks for supported flags, it runs $CC, $CXX, $LD via this
  5 +# wrapper.
  6 +#
  7 +# Ideally the search string would also include 'clang: ' but this output might
  8 +# depend on clang's argv[0].
  9 +
  10 +if out=`"$@" 2>&1`; then
  11 + echo "$out"
  12 + if echo "$out" | grep 'warning: argument unused' >/dev/null; then
  13 + echo "$0: found clang warning"
  14 + exit 1
  15 + else
  16 + exit 0
  17 + fi
  18 +else
  19 + code=$?
  20 + echo "$out"
  21 + exit $code
  22 +fi

0 comments on commit 62b6137

Please sign in to comment.
Something went wrong with that request. Please try again.