From: Francesco Chemolli Date: Thu, 18 Apr 2013 05:28:16 +0000 (-0600) Subject: Bug 3674: Improve compiler detection, better support warnings-as-errors on clang X-Git-Tag: SQUID_3_3_4~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17eeaed6997e2e74c89aa8577b0637f3865fd9eb;p=thirdparty%2Fsquid.git Bug 3674: Improve compiler detection, better support warnings-as-errors on clang --- diff --git a/acinclude/compiler-flags.m4 b/acinclude/compiler-flags.m4 index 3f4bdc8953..345c2dea05 100644 --- a/acinclude/compiler-flags.m4 +++ b/acinclude/compiler-flags.m4 @@ -81,15 +81,12 @@ AC_DEFUN([SQUID_CC_REQUIRE_ARGUMENT],[ # - sunstudio # - none (undetected) # -AC_DEFUN([SQUID_CC_GUESS_VARIANT], [ +AC_DEFUN([SQUID_CC_GUESS_VARIANT], [ AC_CACHE_CHECK([what kind of compiler we're using],[squid_cv_compiler], [ AC_REQUIRE([AC_PROG_CC]) - if test "$GCC" = "yes" ; then - squid_cv_compiler="gcc" - fi dnl repeat the next block for each compiler, changing the - dnl preprocessor definition type so that it depends on platform-specific + dnl preprocessor definition so that it depends on platform-specific dnl predefined macros dnl SunPro CC if test -z "$squid_cv_compiler" ; then @@ -109,12 +106,39 @@ AC_DEFUN([SQUID_CC_GUESS_VARIANT], [ #endif ]])],[squid_cv_compiler="icc"],[]) fi + dnl clang + if test -z "$squid_cv_compiler" ; then + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#if !defined(__clang__) +#error "not clang" +#endif + ]])],[squid_cv_compiler="clang"],[]) + fi + dnl microsoft visual c++ + if test -z "$squid_cv_compiler" ; then + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#if !defined(_MSC_VER) +#error "not Microsoft VC++" +#endif + ]])],[squid_cv_compiler="msvc"],[]) + fi + dnl gcc. MUST BE LAST as many other compilers also define it for compatibility + if test -z "$squid_cv_compiler" ; then + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[ +#if !defined(__GNUC__) +#error "not gcc" +#endif + ]])],[squid_cv_compiler="gcc"],[]) + fi dnl end of block to be repeated if test -z "$squid_cv_compiler" ; then squid_cv_compiler="none" fi - ]) - ]) + ]) dnl AC_CACHE_CHECK + ]) dnl AC_DEFUN # define the flag to use to have the compiler treat warnings as errors # requirs SQUID_CC_GUESS_VARIANT @@ -145,6 +169,13 @@ AC_DEFUN([SQUID_CC_GUESS_OPTIONS], [ squid_cv_cc_option_optimize="-fast" squid_cv_cc_arg_pipe="" ;; + clang) + squid_cv_cxx_option_werror="-Werror -Wno-error=parentheses-equality" + squid_cv_cc_option_werror="$squid_cv_cxx_option_werror" + squid_cv_cc_option_wall="-Wall" + squid_cv_cc_option_optimize="-O2" + squid_cv_cc_arg_pipe="" + ;; icc) squid_cv_cxx_option_werror="-Werror" squid_cv_cc_option_werror="$squid_cv_cxx_option_werror" diff --git a/configure.ac b/configure.ac index cc0f5ee1d1..043207dcdf 100644 --- a/configure.ac +++ b/configure.ac @@ -259,7 +259,7 @@ case $withval in ]) AC_SUBST(DEFAULT_SWAP_DIR) -if test "x$GCC" = "xyes"; then +if test "$squid_cv_compiler" = "gcc"; then GCCVER=`$CC -v 2>&1 | awk '$2 == "version" {print $3}'` GCCVER2=`echo $GCCVER | awk '{print $1 * 100}'` case "$host" in @@ -276,7 +276,7 @@ fi dnl Set Default CFLAGS if test "x$PRESET_CFLAGS" = "x"; then - if test "x$GCC" = "xyes"; then + if test "$squid_cv_compiler" = "gcc"; then case "$host" in *-sun-sunos*) # sunos has too many warnings for this to be useful @@ -310,7 +310,7 @@ if test "x$PRESET_CFLAGS" = "x"; then fi dnl set squid required flags -if test "x$GCC" = "xyes"; then +if test "$squid_cv_compiler" = "gcc"; then case "$squid_host_os" in mingw) dnl Guido Serassio (serassio@squid-cache.org) 20070811