The attached patch makes several changes to how we discover compilers and set flags on *nix:
* Search for clang as well as the default gcc/cc, and prefer clang(++) over gcc/g++. * Set standards-compliance mode (C90/C++11) even without maintainer-mode. * Add -pipe to C(XX)FLAGS if the compiler supports it. This speeds up compilation a bit in my tests. I tested this on Mac OS (with clang) and Linux (without clang) but don't know how it affects bindings. Please review. -- Brane {{{ * build/ac-macros/compiler.m4: New file. (SVN_PROG_CC, SVN_CFLAGS_ADD_IFELSE, SVN_PROG_CXX, SVN_CXXFLAGS_ADD_IFELSE): New. * aclocal.m4: Include build/ac-macros/compiler.m4. * configure.ac: - Use SVN_PROG_CC instead of AC_PROG_CC - Use SVN_PROG_CXX instead of AC_PROG_CXX - Use SVN_CFLAGS_ADD_IFELSE and SVN_CXXFLAGS_ADD_IFELSE to add mainter-mode flags - Do not remove -ansi for clang, since it's not set any more. }}} -- Branko Čibej Director of Subversion | WANdisco | www.wandisco.com
Index: aclocal.m4 =================================================================== --- aclocal.m4 (revision 1421399) +++ aclocal.m4 (working copy) @@ -36,6 +36,7 @@ sinclude(build/ac-macros/aprutil.m4) sinclude(build/ac-macros/apr_memcache.m4) sinclude(build/ac-macros/berkeley-db.m4) +sinclude(build/ac-macros/compiler.m4) sinclude(build/ac-macros/ctypesgen.m4) sinclude(build/ac-macros/gssapi.m4) sinclude(build/ac-macros/java.m4) Index: configure.ac =================================================================== --- configure.ac (revision 1421399) +++ configure.ac (working copy) @@ -48,12 +48,10 @@ # ==== Check for programs ==================================================== -# Look for a C compiler (before anything can set CFLAGS) -AC_PROG_CC +# Look for a C and C++ compiler (before anything can set CFLAGS or CXXFLAGS) +SVN_PROG_CC +SVN_PROG_CXX -# Look for a C++ compiler -AC_PROG_CXX - # Look for a C pre-processor AC_PROG_CPP @@ -990,62 +988,31 @@ AC_MSG_NOTICE([maintainer-mode: adding GCC warning flags]) dnl Enable some extra warnings. Put these before the user's flags dnl so the user can specify flags that override these. - CFLAGS="-Wpointer-arith -Wwrite-strings -Wshadow -ansi -Wall -Wformat=2 -Wunused -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wno-multichar -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Wno-long-long $CFLAGS" - CXXFLAGS="-Wpointer-arith -Wwrite-strings -Wshadow -ansi -Wall $CXXFLAGS" + dnl Add each of the following flags only if the C compiler accepts it. + SVN_CFLAGS_ADD_IFELSE([-Werror=declaration-after-statement]) + SVN_CFLAGS_ADD_IFELSE([-Wextra-tokens]) + SVN_CFLAGS_ADD_IFELSE([-Wnewline-eof]) + SVN_CFLAGS_ADD_IFELSE([-Wshorten-64-to-32]) + SVN_CFLAGS_ADD_IFELSE([-Wold-style-definition]) + SVN_CFLAGS_ADD_IFELSE([-Wno-format-nonliteral]) + SVN_CFLAGS_ADD_IFELSE([-Wno-system-headers]) + + dnl Add each of the following flags only if the C++ compiler accepts it. + SVN_CXXFLAGS_ADD_IFELSE([-Wextra-tokens]) + SVN_CXXFLAGS_ADD_IFELSE([-Wshorten-64-to-32]) + SVN_CXXFLAGS_ADD_IFELSE([-Wno-system-headers]) + + dnl Finally, prepend a standard set of extra warnings that + dnl even very old compilers understand + CFLAGS="-Wpointer-arith -Wwrite-strings -Wshadow -Wall -Wformat=2 -Wunused -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wno-multichar -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Wno-long-long $CFLAGS" + CXXFLAGS="-Wpointer-arith -Wwrite-strings -Wshadow -Wall $CXXFLAGS" + dnl some additional flags that can be handy for an occasional review, dnl but throw too many warnings in svn code, of too little importance, dnl to keep these enabled. Remove the "dnl" to do a run with these dnl switches enabled. dnl CFLAGS="-Wswitch-enum -Wswitch-default $CFLAGS" - - dnl Add each of the following flags only if the C compiler accepts it. - - CFLAGS_KEEP="$CFLAGS" - AC_LANG_PUSH([C]) - - CFLAGS="-Werror=declaration-after-statement $CFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CFLAGS_KEEP="$CFLAGS"]) - - CFLAGS="-Wextra-tokens $CFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CFLAGS_KEEP="$CFLAGS"]) - - CFLAGS="-Wnewline-eof $CFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CFLAGS_KEEP="$CFLAGS"]) - - CFLAGS="-Wshorten-64-to-32 $CFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CFLAGS_KEEP="$CFLAGS"]) - - CFLAGS="-Wold-style-definition $CFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CFLAGS_KEEP="$CFLAGS"]) - - CFLAGS="-Wno-system-headers $CFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CFLAGS_KEEP="$CFLAGS"]) - - dnl Put this flag behind -Wall: - - CFLAGS="$CFLAGS_KEEP -Wno-format-nonliteral" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CFLAGS_KEEP="$CFLAGS"]) - - AC_LANG_POP([C]) - CFLAGS="$CFLAGS_KEEP" - - dnl Add each of the following flags only if the C++ compiler accepts it. - - CXXFLAGS_KEEP="$CXXFLAGS" - AC_LANG_PUSH([C++]) - - CXXFLAGS="-Wextra-tokens $CXXFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CXXFLAGS_KEEP="$CXXFLAGS"]) - - CXXFLAGS="-Wshorten-64-to-32 $CXXFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CXXFLAGS_KEEP="$CXXFLAGS"]) - - CXXFLAGS="-Wno-system-headers $CXXFLAGS_KEEP" - AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])], [CXXFLAGS_KEEP="$CXXFLAGS"]) - - AC_LANG_POP([C++]) - CXXFLAGS="$CXXFLAGS_KEEP" fi fi ]) @@ -1388,11 +1355,6 @@ CPPFLAGS=`echo "$CPPFLAGS" | $SED -e 's/-no-cpp-precomp //'` fi -# Clang also doesn't (yet) support the '-ansi' flag -if test "$CC" = "clang"; then - CFLAGS=`echo "$CFLAGS" | $SED -e 's/-ansi //'` -fi - dnl Since this is used only on Unix-y systems, define the path separator as '/' AC_DEFINE_UNQUOTED(SVN_PATH_LOCAL_SEPARATOR, '/', [Defined to be the path separator used on your local filesystem]) Index: build/ac-macros/compiler.m4 =================================================================== --- build/ac-macros/compiler.m4 (revision 0) +++ build/ac-macros/compiler.m4 (working copy) @@ -0,0 +1,112 @@ +dnl ============================================== -*- Autoconf -*- ==== +dnl Licensed to the Apache Software Foundation (ASF) under one +dnl or more contributor license agreements. See the NOTICE file +dnl distributed with this work for additional information +dnl regarding copyright ownership. The ASF licenses this file +dnl to you under the Apache License, Version 2.0 (the +dnl "License"); you may not use this file except in compliance +dnl with the License. You may obtain a copy of the License at +dnl +dnl http://www.apache.org/licenses/LICENSE-2.0 +dnl +dnl Unless required by applicable law or agreed to in writing, +dnl software distributed under the License is distributed on an +dnl "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +dnl KIND, either express or implied. See the License for the +dnl specific language governing permissions and limitations +dnl under the License. +dnl =================================================================== +dnl +dnl SVN_CFLAGS_ADD_IFELSE(option, success, failure) +dnl +dnl Check if the C compiler accepts $option. If it does, prepend it +dnl to CFLAGS and execute $success; otherwise execute $failure. +dnl +dnl SVN_CXXFLAGS_ADD_IFELSE(option, success, failure) +dnl +dnl Like SVN_CFLAGS_ADD_IFELSE, but for C++ and CXXFLAGS. +dnl +dnl SVN_PROG_CC: Customized replacement for AC_PROG_CC +dnl SVN_PROG_CXX: Customized replacement for AC_PROG_CXX +dnl + +AC_DEFUN([_SVN_XXFLAGS_ADD_IFELSE], +[ + _svn_xxflags__save="[$][$3]" + AC_LANG_PUSH([$1]) + AC_MSG_CHECKING([if [$][$2] accepts $4]) + [$3]="$4 [$][$3]" + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[]])],[ + AC_MSG_RESULT([yes]) + $5 + ],[ + AC_MSG_RESULT([no]) + [$3]="$_svn_xxflags__save" + $6 + ]) + AC_LANG_POP([$1]) +]) + +AC_DEFUN([SVN_CFLAGS_ADD_IFELSE], + [_SVN_XXFLAGS_ADD_IFELSE([C],[CC],[CFLAGS],[$1],[$2],[$3])]) + +AC_DEFUN([SVN_CXXFLAGS_ADD_IFELSE], + [_SVN_XXFLAGS_ADD_IFELSE([C++],[CXX],[CXXFLAGS],[$1],[$2],[$3])]) + + +AC_DEFUN([SVN_PROG_CC], +[ + dnl Try clang first, then the default list + if test -z "$CC"; then + AC_CHECK_TOOL([CC], [clang]) + fi + AC_PROG_CC + + dnl Slightly faster compilation with -pipe + SVN_CFLAGS_ADD_IFELSE([-pipe]) + + dnl Try to turn on C90 mode + dnl gcc and clang + SVN_CFLAGS_ADD_IFELSE([-std=c90],[],[ + SVN_CFLAGS_ADD_IFELSE([-std=c89],[],[ + SVN_CFLAGS_ADD_IFELSE([-ansi],[],[ + dnl Solaris + SVN_CFLAGS_ADD_IFELSE([-xc99=none]) + ]) + ]) + ]) +]) + + +AC_DEFUN([SVN_PROG_CXX], +[ + dnl Try clang++ first, then the default list + if test -z "$CXX"; then + AC_CHECK_TOOL([CXX], [clang++]) + fi + AC_PROG_CXX + + dnl Slightly faster compilation with -pipe + SVN_CXXFLAGS_ADD_IFELSE([-pipe]) + + dnl Try to turn on C++11 mode so that we can use + dnl std::shared_ptr<> and similar goodies + dnl g++ and clang++ + SVN_CXXFLAGS_ADD_IFELSE([-std=c++11],[],[ + SVN_CXXFLAGS_ADD_IFELSE([-std=c++0x]) + ]) + + dnl clang++ on Mac OS X can use an alternate C++ library that's + dnl closer to the C++11 standard than the default. + AC_LANG_PUSH([C++]) + AC_RUN_IFELSE([AC_LANG_PROGRAM([],[[ + #if __APPLE__ && __APPLE_CC__ + return 0; + #else + return 1; + #endif + ]])],[ + SVN_CXXFLAGS_ADD_IFELSE([-stdlib=libc++]) + ]) + AC_LANG_POP([C++]) +])