From 62b6137ff5b1c280ba99a0ba1b64b4a03cb3f779 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Sat, 7 Apr 2012 23:50:52 -0400 Subject: [PATCH] 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]. --- configure.ac | 16 ++++++++++++++++ scripts/wrap-compiler-for-flag-check | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 scripts/wrap-compiler-for-flag-check diff --git a/configure.ac b/configure.ac index 3c91f13..758edd9 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,18 @@ AC_ARG_ENABLE([compile-warnings], AC_SUBST([WARNING_CXXFLAGS]) AC_SUBST([PICKY_CXXFLAGS]) +# We want to check for compiler flag support, but there is no way to make +# clang's "argument unused" warning fatal. So we invoke the compiler through a +# wrapper script that greps for this message. + +saved_CC="$CC" +saved_CXX="$CXX" +saved_LD="$LD" +flag_wrap="$srcdir/scripts/wrap-compiler-for-flag-check" +CC="$flag_wrap $CC" +CXX="$flag_wrap $CXX" +LD="$flag_wrap $LD" + # We use the same hardening flags for C and C++. We must check that each flag # is supported by both compilers. AC_DEFUN([check_cc_cxx_flag], @@ -89,6 +101,10 @@ AS_IF([test x"$hardening" != x"no"], [ AC_SUBST([HARDEN_CFLAGS]) AC_SUBST([HARDEN_LDFLAGS]) +CC="$saved_CC" +CXX="$saved_CXX" +LD="$saved_LD" + AC_ARG_ENABLE([client], [AS_HELP_STRING([--enable-client], [Build the mosh-client program @<:@yes@:>@])], [build_client="$enableval"], diff --git a/scripts/wrap-compiler-for-flag-check b/scripts/wrap-compiler-for-flag-check new file mode 100755 index 0000000..579f577 --- /dev/null +++ b/scripts/wrap-compiler-for-flag-check @@ -0,0 +1,22 @@ +#!/bin/sh + +# There is no way to make clang's "argument unused" warning fatal. So when +# configure checks for supported flags, it runs $CC, $CXX, $LD via this +# wrapper. +# +# Ideally the search string would also include 'clang: ' but this output might +# depend on clang's argv[0]. + +if out=`"$@" 2>&1`; then + echo "$out" + if echo "$out" | grep 'warning: argument unused' >/dev/null; then + echo "$0: found clang warning" + exit 1 + else + exit 0 + fi +else + code=$? + echo "$out" + exit $code +fi