Code

correctly test compiler for -Werror=...
authorkeescook <keescook@users.sourceforge.net>
Wed, 30 Apr 2008 06:09:51 +0000 (06:09 +0000)
committerkeescook <keescook@users.sourceforge.net>
Wed, 30 Apr 2008 06:09:51 +0000 (06:09 +0000)
configure.ac

index 313d349a8b28e002e5c28ae7f11af4f5050a0826..b28048dd1ef792843f44fa7ef51bc13a80c660cb 100644 (file)
@@ -33,17 +33,36 @@ AC_HEADER_STDC
 dnl These next few lines are needed only while libcroco is in our source tree.
 AC_PROG_CC
 AM_PROG_CC_C_O
-AC_MSG_NOTICE([Testing -Wno-pointer-sign])
 if test "$GCC" = "yes"; then
   # Enable some warnings from gcc.
 
   AC_LANG_PUSH(C)
   # -Wno-pointer-sign is probably new in gcc 4.0; certainly it isn't accepted
   # by gcc 2.95.
+  AC_MSG_CHECKING([support for -Wno-pointer-sign])
   ink_svd_CFLAGS="$CFLAGS"
   CFLAGS="-Wno-pointer-sign $CFLAGS"
-  AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), AC_MSG_NOTICE([ compiler supports -Wno-pointer-sign]), CFLAGS="$ink_svd_CFLAGS")
-  CFLAGS="-Wall -Wformat -Werror=format-security -W -D_FORTIFY_SOURCE=2 $CFLAGS"
+  AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), [gcc_opt_ok=yes], [gcc_opt_ok=no])
+  AC_MSG_RESULT([$gcc_opt_ok])
+  if test "x$gcc_opt_ok" != "xyes"; then
+    CFLAGS="$ink_svd_CFLAGS"
+  fi
+
+  # This seems safe so far...
+  CFLAGS="-Wall -Wformat -Wformat-security $CFLAGS"
+
+  # Test for -Werror=... (introduced some time post-4.0)
+  AC_MSG_CHECKING([support for -Werror=format-security])
+  ink_svd_CFLAGS="$CFLAGS"
+  CFLAGS="-Werror=format-security $CFLAGS"
+  AC_COMPILE_IFELSE(AC_LANG_PROGRAM([]), [gcc_opt_ok=yes], [gcc_opt_ok=no])
+  AC_MSG_RESULT([$gcc_opt_ok])
+  if test "x$gcc_opt_ok" != "xyes"; then
+    CFLAGS="$ink_svd_CFLAGS"
+  fi
+
+  # Fortify source requires -O2 or higher...
+  CFLAGS="-W -D_FORTIFY_SOURCE=2 $CFLAGS"
   AC_LANG_POP
 fi