diff mbox

[v4,2/4] configure: factor out supported flag check

Message ID 1427221186-28404-3-git-send-email-jsnow@redhat.com
State New
Headers show

Commit Message

John Snow March 24, 2015, 6:19 p.m. UTC
Factor out the function that checks if a compiler
flag is supported or not.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 configure | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

Comments

Stefan Hajnoczi March 25, 2015, 1:16 p.m. UTC | #1
On Tue, Mar 24, 2015 at 02:19:44PM -0400, John Snow wrote:
> +cc_has_warning_flag() {
> +    write_c_skeleton;
> +
>      # Use the positive sense of the flag when testing for -Wno-wombat
>      # support (gcc will happily accept the -Wno- form of unknown
>      # warning options).
> -    optflag="$(echo $flag | sed -e 's/^-Wno-/-W/')"
> -    if compile_prog "-Werror $optflag" "" ; then
> -	QEMU_CFLAGS="$QEMU_CFLAGS $flag"
> +    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
> +    compile_prog "-Werror $optflag" ""
> +}
> +
> +for flag in $gcc_flags; do
> +    if cc_has_warning_flag $flag --keep-tmpc; then

Please drop the unused --keep-tmpc option here.

Stefan
diff mbox

Patch

diff --git a/configure b/configure
index 7a8637e..6f4bf4f 100755
--- a/configure
+++ b/configure
@@ -435,6 +435,12 @@  EOF
   compile_object
 }
 
+write_c_skeleton() {
+    cat > $TMPC <<EOF
+int main(void) { return 0; }
+EOF
+}
+
 if check_define __linux__ ; then
   targetos="Linux"
 elif check_define _WIN32 ; then
@@ -704,9 +710,7 @@  if test "$mingw32" = "yes" ; then
   # enable C99/POSIX format strings (needs mingw32-runtime 3.15 or later)
   QEMU_CFLAGS="-D__USE_MINGW_ANSI_STDIO=1 $QEMU_CFLAGS"
   LIBS="-lwinmm -lws2_32 -liphlpapi $LIBS"
-cat > $TMPC << EOF
-int main(void) { return 0; }
-EOF
+  write_c_skeleton;
   if compile_prog "" "-liberty" ; then
     LIBS="-liberty $LIBS"
   fi
@@ -1438,10 +1442,7 @@  if test -z "$werror" ; then
 fi
 
 # check that the C compiler works.
-cat > $TMPC <<EOF
-int main(void) { return 0; }
-EOF
-
+write_c_skeleton;
 if compile_object ; then
   : C compiler works ok
 else
@@ -1489,16 +1490,20 @@  gcc_flags="-Wno-string-plus-int $gcc_flags"
 # enable it for all configure tests. If a configure test failed due
 # to -Werror this would just silently disable some features,
 # so it's too error prone.
-cat > $TMPC << EOF
-int main(void) { return 0; }
-EOF
-for flag in $gcc_flags; do
+
+cc_has_warning_flag() {
+    write_c_skeleton;
+
     # Use the positive sense of the flag when testing for -Wno-wombat
     # support (gcc will happily accept the -Wno- form of unknown
     # warning options).
-    optflag="$(echo $flag | sed -e 's/^-Wno-/-W/')"
-    if compile_prog "-Werror $optflag" "" ; then
-	QEMU_CFLAGS="$QEMU_CFLAGS $flag"
+    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
+    compile_prog "-Werror $optflag" ""
+}
+
+for flag in $gcc_flags; do
+    if cc_has_warning_flag $flag --keep-tmpc; then
+        QEMU_CFLAGS="$QEMU_CFLAGS $flag"
     fi
 done