[libvirt] [PATCH] Improve compiler flag checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



# HG changeset patch
# User john.levon@xxxxxxx
# Date 1229789393 28800
# Node ID a158bbc6df6fb8b15af875d08e73cfd3ca75f907
# Parent  34706075e6c801cd9532490c11b20b64dfcf464b
Improve compiler flag checking

Some compilers (including GCC) don't set the return value consistently
if an erroneous option is passed on the command line. Account for that.

Signed-off-by: John Levon <john.levon@xxxxxxx>

diff --git a/acinclude.m4 b/acinclude.m4
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -45,21 +45,9 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
 	;;
     esac
 
-    compiler_flags=
+    COMPILER_FLAGS=
     for option in $try_compiler_flags; do
-	SAVE_CFLAGS="$CFLAGS"
-	CFLAGS="$CFLAGS $option"
-	AC_MSG_CHECKING([whether gcc understands $option])
-	AC_TRY_LINK([], [],
-		has_option=yes,
-		has_option=no,)
-	CFLAGS="$SAVE_CFLAGS"
-	AC_MSG_RESULT($has_option)
-	if test $has_option = yes; then
-	  compiler_flags="$compiler_flags $option"
-	fi
-	unset has_option
-	unset SAVE_CFLAGS
+        gl_COMPILER_FLAGS($option)
     done
     unset option
     unset try_compiler_flags
@@ -85,7 +73,7 @@ AC_DEFUN([LIBVIRT_COMPILE_WARNINGS],[
     fi
     AC_MSG_RESULT($complCFLAGS)
 
-    WARN_CFLAGS="$compiler_flags $complCFLAGS"
+    WARN_CFLAGS="$COMPILER_FLAGS $complCFLAGS"
     AC_SUBST(WARN_CFLAGS)
 
     dnl Needed to keep compile quiet on python 2.4
diff --git a/m4/compiler-flags.m4 b/m4/compiler-flags.m4
--- a/m4/compiler-flags.m4
+++ b/m4/compiler-flags.m4
@@ -25,10 +25,16 @@ AC_DEFUN([gl_COMPILER_FLAGS],
    AC_SUBST(COMPILER_FLAGS)
    ac_save_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS $1"
-   AC_TRY_COMPILE(,
-    [int x;],
-    COMPILER_FLAGS="$COMPILER_FLAGS $1"
-    AC_MSG_RESULT(yes),
-    AC_MSG_RESULT(no))
-  CFLAGS="$ac_save_CFLAGS"
+   AC_TRY_LINK([], [], has_option=yes, has_option=no,)
+   echo 'int x;' >conftest.c
+   $CC $CFLAGS -c conftest.c 2>conftest.err
+   ret=$?
+   if test $ret != 0 -o -s conftest.err -o $has_option = "no"; then
+       AC_MSG_RESULT(no)
+   else
+       AC_MSG_RESULT(yes)
+       COMPILER_FLAGS="$COMPILER_FLAGS $1"
+   fi
+   CFLAGS="$ac_save_CFLAGS"
+   rm -f conftest*
  ])

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]