From f5d8c0befc61497b3d3572ae51e779b396589660 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 5 Mar 2010 22:53:30 +0000 Subject: Daniel Johnson provided fixes for building with the clang compiler --- CHANGES | 3 ++ RELEASE-NOTES | 1 + ares/CHANGES | 3 ++ ares/m4/cares-compilers.m4 | 78 +++++++++++++++++++++++++++++++++++++++++++++- configure.ac | 5 ++- m4/curl-compilers.m4 | 72 +++++++++++++++++++++++++++++++++++++++++- 6 files changed, 159 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 8147d00fd..a3ceb533c 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,9 @@ Changelog +Daniel Stenberg (5 Mar 2010) +- Daniel Johnson provided fixes for building curl with the clang compiler. + Yang Tse (5 Mar 2010) - Constantine Sapuntzakis detected and fixed a double free in builds done with threaded resolver enabled (Windows default configuration) that would diff --git a/RELEASE-NOTES b/RELEASE-NOTES index d59cba5ae..5321f86f3 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -29,6 +29,7 @@ This release includes the following bugfixes: o sub-second timeouts improvements o configure fixes for GSSAPI o threaded resolver double free when closing curl handle + o configure fixes for building with the clang compiler This release includes the following known bugs: diff --git a/ares/CHANGES b/ares/CHANGES index bb9d9385e..ae8a57a8b 100644 --- a/ares/CHANGES +++ b/ares/CHANGES @@ -1,5 +1,8 @@ Changelog for the c-ares project +* March 5, 2010 (Daniel Stenberg) +- Daniel Johnson provided fixes for building with the clang compiler. + * March 5, 2010 (Yang Tse) - Added IPv6 name servers support. Implementation has been based on code, comments and feedback provided November and December of 2008 by Daniel diff --git a/ares/m4/cares-compilers.m4 b/ares/m4/cares-compilers.m4 index aef46f172..7e1bb11e7 100644 --- a/ares/m4/cares-compilers.m4 +++ b/ares/m4/cares-compilers.m4 @@ -40,6 +40,7 @@ AC_DEFUN([CARES_CHECK_COMPILER], [ CARES_CHECK_COMPILER_HPUX_C CARES_CHECK_COMPILER_IBM_C CARES_CHECK_COMPILER_INTEL_C + CARES_CHECK_COMPILER_CLANG CARES_CHECK_COMPILER_GNU_C CARES_CHECK_COMPILER_LCC CARES_CHECK_COMPILER_SGI_MIPSPRO_C @@ -66,6 +67,40 @@ _EOF ]) +dnl CARES_CHECK_COMPILER_CLANG +dnl ------------------------------------------------- +dnl Verify if compiler being used is clang. + +AC_DEFUN([CARES_CHECK_COMPILER_CLANG], [ + AC_BEFORE([$0],[CARES_CHECK_COMPILER_GNU_C])dnl + AC_MSG_CHECKING([if compiler is clang]) + CURL_CHECK_DEF([__clang__], [], [silent]) + if test "$curl_cv_have_def___clang__" = "yes"; then + AC_MSG_RESULT([yes]) + compiler_id="CLANG" + clangver=`$CC -dumpversion` + clangvhi=`echo $clangver | cut -d . -f1` + clangvlo=`echo $clangver | cut -d . -f2` + compiler_num=`(expr $clangvhi "*" 100 + $clangvlo) 2>/dev/null` + flags_dbg_all="-g -g0 -g1 -g2 -g3" + flags_dbg_all="$flags_dbg_all -ggdb" + flags_dbg_all="$flags_dbg_all -gstabs" + flags_dbg_all="$flags_dbg_all -gstabs+" + flags_dbg_all="$flags_dbg_all -gcoff" + flags_dbg_all="$flags_dbg_all -gxcoff" + flags_dbg_all="$flags_dbg_all -gdwarf-2" + flags_dbg_all="$flags_dbg_all -gvms" + flags_dbg_yes="-g" + flags_dbg_off="-g0" + flags_opt_all="-O -O0 -O1 -O2 -Os -O3 -O4" + flags_opt_yes="-Os" + flags_opt_off="-O0" + else + AC_MSG_RESULT([no]) + fi +]) + + dnl CARES_CHECK_COMPILER_DEC_C dnl ------------------------------------------------- dnl Verify if compiler being used is DEC C. @@ -96,6 +131,7 @@ dnl Verify if compiler being used is GNU C. AC_DEFUN([CARES_CHECK_COMPILER_GNU_C], [ AC_REQUIRE([CARES_CHECK_COMPILER_INTEL_C])dnl + AC_REQUIRE([CARES_CHECK_COMPILER_CLANG])dnl AC_MSG_CHECKING([if compiler is GNU C]) CURL_CHECK_DEF([__GNUC__], [], [silent]) if test "$curl_cv_have_def___GNUC__" = "yes" && @@ -495,7 +531,8 @@ AC_DEFUN([CARES_SET_COMPILER_BASIC_OPTS], [ # if test "$compiler_id" != "unknown"; then # - if test "$compiler_id" = "GNU_C"; then + if test "$compiler_id" = "GNU_C" || + test "$compiler_id" = "CLANG"; then CARES_CONVERT_INCLUDE_TO_ISYSTEM fi # @@ -506,6 +543,14 @@ AC_DEFUN([CARES_SET_COMPILER_BASIC_OPTS], [ # case "$compiler_id" in # + CLANG) + # + dnl Disable warnings for unused arguments, otherwise clang will + dnl warn about compile-time arguments used during link-time, like + dnl -O and -g and -pedantic. + tmp_CFLAGS="$tmp_CFLAGS -Qunused-arguments" + ;; + # DEC_C) # dnl Select strict ANSI C compiler mode @@ -786,6 +831,31 @@ AC_DEFUN([CARES_SET_COMPILER_WARNING_OPTS], [ # case "$compiler_id" in # + CLANG) + # + if test "$want_warnings" = "yes"; then + dnl All versions of clang support the same warnings as at least + dnl gcc 4.2.1. + tmp_CFLAGS="$tmp_CFLAGS -pedantic" + tmp_CFLAGS="$tmp_CFLAGS -Wall -Wextra" + tmp_CFLAGS="$tmp_CFLAGS -Wpointer-arith -Wwrite-strings" + tmp_CFLAGS="$tmp_CFLAGS -Wunused -Wshadow" + tmp_CFLAGS="$tmp_CFLAGS -Winline -Wnested-externs" + tmp_CFLAGS="$tmp_CFLAGS -Wmissing-declarations" + tmp_CFLAGS="$tmp_CFLAGS -Wmissing-prototypes" + tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long" + tmp_CFLAGS="$tmp_CFLAGS -Wfloat-equal" + tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar -Wsign-compare" + tmp_CFLAGS="$tmp_CFLAGS -Wundef" + tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral" + tmp_CFLAGS="$tmp_CFLAGS -Wendif-labels -Wstrict-prototypes" + tmp_CFLAGS="$tmp_CFLAGS -Wdeclaration-after-statement" + tmp_CFLAGS="$tmp_CFLAGS -Wcast-align" + tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers" + tmp_CFLAGS="$tmp_CFLAGS -Wshorten-64-to-32" + fi + ;; + # DEC_C) # if test "$want_warnings" = "yes"; then @@ -1326,6 +1396,12 @@ AC_DEFUN([CARES_CHECK_COMPILER_SYMBOL_HIDING], [ tmp_CFLAGS="" tmp_EXTERN="" case "$compiler_id" in + CLANG) + dnl All versions of clang support -fvisibility= + tmp_EXTERN="__attribute__ ((visibility (\"default\")))" + tmp_CFLAGS="-fvisibility=hidden" + supports_symbol_hiding="yes" + ;; GNU_C) dnl Only gcc 3.4 or later if test "$compiler_num" -ge "304"; then diff --git a/configure.ac b/configure.ac index 2320dce4d..727e389b6 100644 --- a/configure.ac +++ b/configure.ac @@ -2380,7 +2380,10 @@ AC_HELP_STRING([--disable-hidden-symbols],[Leave all symbols with default visibi *) AC_MSG_CHECKING([whether $CC supports it]) if test "$GCC" = yes ; then - if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then + if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null || + dnl clang always supports -fvisibility= but it doesn't show up + dnl under --help. + test "$compiler_id" = "CLANG"; then AC_MSG_RESULT(yes) AC_DEFINE(CURL_HIDDEN_SYMBOLS, 1, [to enable hidden symbols]) AC_DEFINE(CURL_EXTERN_SYMBOL, [__attribute__ ((visibility ("default")))], [to make a symbol visible]) diff --git a/m4/curl-compilers.m4 b/m4/curl-compilers.m4 index 21ccc65e7..c88917a69 100644 --- a/m4/curl-compilers.m4 +++ b/m4/curl-compilers.m4 @@ -45,6 +45,7 @@ AC_DEFUN([CURL_CHECK_COMPILER], [ CURL_CHECK_COMPILER_HPUX_C CURL_CHECK_COMPILER_IBM_C CURL_CHECK_COMPILER_INTEL_C + CURL_CHECK_COMPILER_CLANG CURL_CHECK_COMPILER_GNU_C CURL_CHECK_COMPILER_LCC CURL_CHECK_COMPILER_SGI_MIPSPRO_C @@ -71,6 +72,40 @@ _EOF ]) +dnl CURL_CHECK_COMPILER_CLANG +dnl ------------------------------------------------- +dnl Verify if compiler being used is clang. + +AC_DEFUN([CURL_CHECK_COMPILER_CLANG], [ + AC_BEFORE([$0],[CURL_CHECK_COMPILER_GNU_C])dnl + AC_MSG_CHECKING([if compiler is clang]) + CURL_CHECK_DEF([__clang__], [], [silent]) + if test "$curl_cv_have_def___clang__" = "yes"; then + AC_MSG_RESULT([yes]) + compiler_id="CLANG" + clangver=`$CC -dumpversion` + clangvhi=`echo $clangver | cut -d . -f1` + clangvlo=`echo $clangver | cut -d . -f2` + compiler_num=`(expr $clangvhi "*" 100 + $clangvlo) 2>/dev/null` + flags_dbg_all="-g -g0 -g1 -g2 -g3" + flags_dbg_all="$flags_dbg_all -ggdb" + flags_dbg_all="$flags_dbg_all -gstabs" + flags_dbg_all="$flags_dbg_all -gstabs+" + flags_dbg_all="$flags_dbg_all -gcoff" + flags_dbg_all="$flags_dbg_all -gxcoff" + flags_dbg_all="$flags_dbg_all -gdwarf-2" + flags_dbg_all="$flags_dbg_all -gvms" + flags_dbg_yes="-g" + flags_dbg_off="-g0" + flags_opt_all="-O -O0 -O1 -O2 -Os -O3 -O4" + flags_opt_yes="-Os" + flags_opt_off="-O0" + else + AC_MSG_RESULT([no]) + fi +]) + + dnl CURL_CHECK_COMPILER_DEC_C dnl ------------------------------------------------- dnl Verify if compiler being used is DEC C. @@ -101,6 +136,7 @@ dnl Verify if compiler being used is GNU C. AC_DEFUN([CURL_CHECK_COMPILER_GNU_C], [ AC_REQUIRE([CURL_CHECK_COMPILER_INTEL_C])dnl + AC_REQUIRE([CURL_CHECK_COMPILER_CLANG])dnl AC_MSG_CHECKING([if compiler is GNU C]) CURL_CHECK_DEF([__GNUC__], [], [silent]) if test "$curl_cv_have_def___GNUC__" = "yes" && @@ -500,7 +536,8 @@ AC_DEFUN([CURL_SET_COMPILER_BASIC_OPTS], [ # if test "$compiler_id" != "unknown"; then # - if test "$compiler_id" = "GNU_C"; then + if test "$compiler_id" = "GNU_C" || + test "$compiler_id" = "CLANG"; then CURL_CONVERT_INCLUDE_TO_ISYSTEM fi # @@ -511,6 +548,14 @@ AC_DEFUN([CURL_SET_COMPILER_BASIC_OPTS], [ # case "$compiler_id" in # + CLANG) + # + dnl Disable warnings for unused arguments, otherwise clang will + dnl warn about compile-time arguments used during link-time, like + dnl -O and -g and -pedantic. + tmp_CFLAGS="$tmp_CFLAGS -Qunused-arguments" + ;; + # DEC_C) # dnl Select strict ANSI C compiler mode @@ -791,6 +836,31 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [ # case "$compiler_id" in # + CLANG) + # + if test "$want_warnings" = "yes"; then + dnl All versions of clang support the same warnings as at least + dnl gcc 4.2.1. + tmp_CFLAGS="$tmp_CFLAGS -pedantic" + tmp_CFLAGS="$tmp_CFLAGS -Wall -Wextra" + tmp_CFLAGS="$tmp_CFLAGS -Wpointer-arith -Wwrite-strings" + tmp_CFLAGS="$tmp_CFLAGS -Wunused -Wshadow" + tmp_CFLAGS="$tmp_CFLAGS -Winline -Wnested-externs" + tmp_CFLAGS="$tmp_CFLAGS -Wmissing-declarations" + tmp_CFLAGS="$tmp_CFLAGS -Wmissing-prototypes" + tmp_CFLAGS="$tmp_CFLAGS -Wno-long-long" + tmp_CFLAGS="$tmp_CFLAGS -Wfloat-equal" + tmp_CFLAGS="$tmp_CFLAGS -Wno-multichar -Wsign-compare" + tmp_CFLAGS="$tmp_CFLAGS -Wundef" + tmp_CFLAGS="$tmp_CFLAGS -Wno-format-nonliteral" + tmp_CFLAGS="$tmp_CFLAGS -Wendif-labels -Wstrict-prototypes" + tmp_CFLAGS="$tmp_CFLAGS -Wdeclaration-after-statement" + tmp_CFLAGS="$tmp_CFLAGS -Wcast-align" + tmp_CFLAGS="$tmp_CFLAGS -Wno-system-headers" + tmp_CFLAGS="$tmp_CFLAGS -Wshorten-64-to-32" + fi + ;; + # DEC_C) # if test "$want_warnings" = "yes"; then -- cgit v1.2.3