]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3674: Improve compiler detection, better support warnings-as-errors on clang
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 18 Apr 2013 05:28:16 +0000 (23:28 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 18 Apr 2013 05:28:16 +0000 (23:28 -0600)
acinclude/compiler-flags.m4
configure.ac

index 3f4bdc895352a339e6917fbe4291e5724b37d7bd..345c2dea05bf6fd24f867a78b839087e35129cea 100644 (file)
@@ -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" 
index cc0f5ee1d14c34404c715ac12735de0b5e2ca499..043207dcdf976b7eafa4c11cb00d9347d1b19542 100644 (file)
@@ -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