From patchwork Tue Feb 25 18:27:49 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 25303 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AE70220543 for ; Tue, 25 Feb 2014 18:27:59 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id i4sf2966733oah.7 for ; Tue, 25 Feb 2014 10:27:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=ULZug5doab8VPk8S1AIL4kZMYvdWz36HwJDbB65oLHs=; b=hvM5Vbmx4q6wgmS3QdsKifsr3I9pn/IcygZFEyoJPrBlEqxBJ8S3IZ6jBvPAgG78lW zb1PxJV3/HeYKkOD97/BEkwB+1RGQI1yumK6wAidVwoAWVF6NRmadRmz57+n9fVxoAp4 tr8UhDy+PV3lHL+vDrky2JIrWSx5pEfDByZ2OhjXHtydCyjO17VFIGeRj8aqbGhWGJ5H a0SkP58gn220pZk1touQF2CpDuZLxcCZZJbl73aC66WQ1vBRxsxCqJw6p8CncObcQfuQ FEWnrJHPaP56LGmny5jyvTNDsr/4FjS/jBd/cNGkJKFKoM8jSxcxgyswLN7XkD2psKRL mIoQ== X-Gm-Message-State: ALoCoQlWMSIvNQxAVlUKs0Nz0uT4jel9bu6nQx0UDPjib/Eq4SXDtj6aDTmNQUwfu9lOTsayZpdl X-Received: by 10.43.92.73 with SMTP id bp9mr512078icc.26.1393352879113; Tue, 25 Feb 2014 10:27:59 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.106.165 with SMTP id e34ls2654784qgf.29.gmail; Tue, 25 Feb 2014 10:27:58 -0800 (PST) X-Received: by 10.58.54.15 with SMTP id f15mr2106258vep.5.1393352878887; Tue, 25 Feb 2014 10:27:58 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id p9si7004250vdv.135.2014.02.25.10.27.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 10:27:58 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id c14so922636vea.0 for ; Tue, 25 Feb 2014 10:27:58 -0800 (PST) X-Received: by 10.220.159.4 with SMTP id h4mr2160163vcx.1.1393352878760; Tue, 25 Feb 2014 10:27:58 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp158997vcz; Tue, 25 Feb 2014 10:27:58 -0800 (PST) X-Received: by 10.194.104.39 with SMTP id gb7mr3506027wjb.69.1393352877700; Tue, 25 Feb 2014 10:27:57 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id a3si667384wie.22.2014.02.25.10.27.57 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 25 Feb 2014 10:27:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WIMjN-0005nS-6k; Tue, 25 Feb 2014 18:27:49 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexey Kardashevskiy , Thomas Huth , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [PATCH v2] configure: Make C++ test work with --enable-werror Date: Tue, 25 Feb 2014 18:27:49 +0000 Message-Id: <1393352869-22257-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , gcc's C++ compiler complains about being passed some -W options which make sense for C but not for C++. This means we mustn't try a C++ compile with QEMU_CFLAGS, but only with a filtered version that removes the offending options. This filtering was already being done for uses of C++ in the build itself, but was omitted for the "does C++ work?" configure test. This only showed up when doing builds which explicitly enabled -Werror with --enable-werror, because the "do the compilers work" tests were mistakenly placed above the "default werror based on whether compiling from git" code. Another error in this category is that clang warns if you ask it to compile C++ code from a file named "foo.c". Further, because we were running do_cc in a subshell in the condition part of an "if", the error_exit inside do_compiler wouldn't terminate configure and we would plunge on regardless. Fix this complex of errors: 1. Move the default-werror code up so that there are no invocations of compile_object and friends between it and the point where we set $werror explicitly based on the --enable-werror command line option. 2. Provide a mechanism for filtering QEMU_CFLAGS to create QEMU_CXXFLAGS, and use it for the test we run here. 3. Provide a do_cxx function to run a test with the C++ compiler rather than doing cute tricks with subshells and do_cc. 4. Use a new temporary file TMPCXX for the C++ program fragment. Signed-off-by: Peter Maydell Tested-by: Andreas Färber --- Changes v1->v2: item 4, use TMPCXX for the C++ source so that clang doesn't warn (and trigger build failure if -Werror) configure | 75 ++++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/configure b/configure index 00f9070..06c6204 100755 --- a/configure +++ b/configure @@ -14,13 +14,14 @@ fi TMPC="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c" TMPB="qemu-conf-${RANDOM}-$$-${RANDOM}" TMPO="${TMPDIR1}/${TMPB}.o" +TMPCXX="${TMPDIR1}/${TMPB}.cxx" TMPL="${TMPDIR1}/${TMPB}.lo" TMPA="${TMPDIR1}/lib${TMPB}.la" TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.exe" # NB: do not call "exit" in the trap handler; this is buggy with some shells; # see <1285349658-3122-1-git-send-email-loic.minier@linaro.org> -trap "rm -f $TMPC $TMPO $TMPE" EXIT INT QUIT TERM +trap "rm -f $TMPC $TMPO $TMPCXX $TMPE" EXIT INT QUIT TERM rm -f config.log # Print a helpful header at the top of config.log @@ -54,10 +55,13 @@ error_exit() { exit 1 } -do_cc() { - # Run the compiler, capturing its output to the log. - echo $cc "$@" >> config.log - $cc "$@" >> config.log 2>&1 || return $? +do_compiler() { + # Run the compiler, capturing its output to the log. First argument + # is compiler binary to execute. + local compiler="$1" + shift + echo $compiler "$@" >> config.log + $compiler "$@" >> config.log 2>&1 || return $? # Test passed. If this is an --enable-werror build, rerun # the test with -Werror and bail out if it fails. This # makes warning-generating-errors in configure test code @@ -71,14 +75,39 @@ do_cc() { return 0 ;; esac - echo $cc -Werror "$@" >> config.log - $cc -Werror "$@" >> config.log 2>&1 && return $? + echo $compiler -Werror "$@" >> config.log + $compiler -Werror "$@" >> config.log 2>&1 && return $? error_exit "configure test passed without -Werror but failed with -Werror." \ "This is probably a bug in the configure script. The failing command" \ "will be at the bottom of config.log." \ "You can run configure with --disable-werror to bypass this check." } +do_cc() { + do_compiler "$cc" "$@" +} + +do_cxx() { + do_compiler "$cxx" "$@" +} + +update_cxxflags() { + # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those + # options which some versions of GCC's C++ compiler complain about + # because they only make sense for C programs. + QEMU_CXXFLAGS= + for arg in $QEMU_CFLAGS; do + case $arg in + -Wstrict-prototypes|-Wmissing-prototypes|-Wnested-externs|\ + -Wold-style-declaration|-Wold-style-definition|-Wredundant-decls) + ;; + *) + QEMU_CXXFLAGS=${QEMU_CXXFLAGS:+$QEMU_CXXFLAGS }$arg + ;; + esac + done +} + compile_object() { do_cc $QEMU_CFLAGS -c -o $TMPO $TMPC } @@ -1320,6 +1349,19 @@ if test "$ARCH" = "unknown"; then fi fi +# Consult white-list to determine whether to enable werror +# by default. Only enable by default for git builds +z_version=`cut -f3 -d. $source_path/VERSION` + +if test -z "$werror" ; then + if test -d "$source_path/.git" -a \ + "$linux" = "yes" ; then + werror="yes" + else + werror="no" + fi +fi + # check that the C compiler works. cat > $TMPC < $TMPC < $TMPCXX <