From: Ken Raeburn Date: Fri, 22 Aug 2008 15:56:32 +0000 (+0000) Subject: New macro for testing whether the compiler supports a given X-Git-Tag: krb5-1.7-alpha1~464 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a601b792b81eda6a9d3e4158e147a2e9524c13c7;p=krb5.git New macro for testing whether the compiler supports a given command-line flag or not, and adding it to CFLAGS only if supported. Use it for GCC flag -Wno-format-zero-length, which we were testing for before, and for some additional flags: -Woverflow -Wstrict-overflow -Wmissing-format-attribute -Werror=declaration-after-statement -Wdeclaration-after-statement -Werror=variadic-macros -Wvariadic-macros. (The last few are because we've had some code contributions that assumed full C99 support, and our baseline is currently C89+, so if possible we want certain newer constructs flagged as errors.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20685 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/aclocal.m4 b/src/aclocal.m4 index d788f0a5e..eba19d51f 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -564,6 +564,22 @@ krb5_ac_cflags_set=${CFLAGS+set} krb5_ac_cxxflags_set=${CXXFLAGS+set} ]) dnl +AC_DEFUN(TRY_CC_FLAG,[dnl + cachevar=`echo "krb5_cv_cc_flag_$1" | sed s/[[^a-zA-Z0-9_]]/_/g` + AC_CACHE_CHECK([if C compiler supports $1], [$cachevar], + [# first try without, then with + AC_TRY_COMPILE([], 1;, + [old_cflags="$CFLAGS" + CFLAGS="$CFLAGS $1" + AC_TRY_COMPILE([], 1;, eval $cachevar=yes, eval $cachevar=no) + CFLAGS="$old_cflags"], + [AC_MSG_ERROR(compiling simple test program with $CFLAGS failed)])]) + if eval test '"${'$cachevar'}"' = yes; then + CFLAGS="$CFLAGS $1" + fi + eval flag_supported='${'$cachevar'}' +])dnl +dnl AC_DEFUN(WITH_CC,[dnl AC_REQUIRE([KRB5_AC_CHECK_FOR_CFLAGS])dnl AC_REQUIRE([AC_PROG_CC])dnl @@ -589,7 +605,6 @@ withval=no) if test "$withval" = yes; then AC_DEFINE(CONFIG_SMALL,1,[Define to reduce code size even if it means more cpu usage]) fi -# maybe add -Waggregate-return, or can we assume that actually works by now? # -Wno-long-long, if needed, for k5-platform.h without inttypes.h etc. extra_gcc_warn_opts="-Wall -Wcast-qual -Wcast-align -Wconversion -Wshadow" # -Wmissing-prototypes @@ -624,20 +639,33 @@ if test "$GCC" = yes ; then fi fi # Currently, G++ does not support -Wno-format-zero-length. - # So only add it to CFLAGS. - AC_CACHE_CHECK([if GCC supports -Wno-format-zero-length], - krb5_cv_gcc_Wno_format_zero_length, - [# first try without, then with - AC_TRY_COMPILE([], 1;, - [old_cflags="$CFLAGS" - CFLAGS="$CFLAGS -Wno-format-zero-length" - AC_TRY_COMPILE([], 1;, krb5_cv_gcc_Wno_format_zero_length=yes, - krb5_cv_gcc_Wno_format_zero_length=no) - CFLAGS="$old_cflags"], - [AC_MSG_ERROR(compiling simple test program with $CFLAGS failed)])]) - if test "$krb5_cv_gcc_Wno_format_zero_length" = yes; then - CFLAGS="$CFLAGS -Wno-format-zero-length" - fi + TRY_CC_FLAG(-Wno-format-zero-length) + # Other flags here may not be supported on some versions of + # gcc that people want to use. + for flag in overflow strict-overflow missing-format-attribute ; do + TRY_CC_FLAG(-W$flag) + done + # old-style-definition? generates many, many warnings + # + # Warnings that we'd like to turn into errors on versions of gcc + # that support promoting only specific warnings to errors, but + # we'll take as warnings on older compilers. (If such a warning + # is added after the -Werror=foo feature, you can just put + # error=foo in the above list, and skip the test for the + # warning-only form.) At least in some versions, -Werror= doesn't + # seem to make the conditions actual errors, but still issues + # warnings; I guess we'll take what we can get. + # + # We're currently targeting C89+, not C99, so disallow some + # constructs. + for flag in declaration-after-statement variadic-macros ; do + TRY_CC_FLAG(-Werror=$flag) + if test "$flag_supported" = no; then + TRY_CC_FLAG(-W$flag) + fi + done + # missing-prototypes? maybe someday + # fi if test "`uname -s`" = Darwin ; then # Someday this should be a feature test.