[libvirt] [PATCH] Improve compiler flag checking

# HG changeset patch # User john.levon@sun.com # Date 1229399267 28800 # Node ID 1f7707a3d49b20397011897cdc04c347322ad0c5 # Parent a6c317b5fe1b4081ccb40ba90af7d31298cf6b44 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@sun.com> 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) ]) diff --git a/m4/compiler-flags.m4 b/m4/compiler-flags.m4 --- a/m4/compiler-flags.m4 +++ b/m4/compiler-flags.m4 @@ -23,12 +23,14 @@ AC_DEFUN([gl_COMPILER_FLAGS], AC_DEFUN([gl_COMPILER_FLAGS], [AC_MSG_CHECKING(whether compiler accepts $1) 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" + echo 'int x;' >conftest.c + $CC $CFLAGS $1 -c conftest.c 2>conftest.err + ret=$? + if test $ret != 0 -o -s conftest.err; then + AC_MSG_RESULT(no) + else + AC_MSG_RESULT(yes) + COMPILER_FLAGS="$COMPILER_FLAGS $1" + fi + rm -f conftest* ])

On Tue, Dec 16, 2008 at 06:48:56PM -0800, john.levon@sun.com wrote:
# HG changeset patch # User john.levon@sun.com # Date 1229399267 28800 # Node ID 1f7707a3d49b20397011897cdc04c347322ad0c5 # Parent a6c317b5fe1b4081ccb40ba90af7d31298cf6b44 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.
This isn't quite correct. We do explicitly need to do a AC_TRY_LINK test, because on Debian there are flags which are accepted by the compiler OK, but will then fail to link. So we should keep the AC_TRY_LINK check, and upon success of that, then also do your additional new check for zero- length stderr output. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (2)
-
Daniel P. Berrange
-
john.levon@sun.com