1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/autoconf/toolchain.m4 Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,227 @@ 1.4 +dnl This Source Code Form is subject to the terms of the Mozilla Public 1.5 +dnl License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 +dnl file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + 1.8 +AC_DEFUN([MOZ_TOOL_VARIABLES], 1.9 +[ 1.10 +GNU_AS= 1.11 +GNU_LD= 1.12 +GNU_CC= 1.13 +GNU_CXX= 1.14 +CC_VERSION='N/A' 1.15 +CXX_VERSION='N/A' 1.16 +if test "$GCC" = "yes"; then 1.17 + GNU_CC=1 1.18 + CC_VERSION=`$CC -v 2>&1 | grep 'gcc version'` 1.19 +fi 1.20 +if test "$GXX" = "yes"; then 1.21 + GNU_CXX=1 1.22 + CXX_VERSION=`$CXX -v 2>&1 | grep 'gcc version'` 1.23 + changequote(<<,>>) 1.24 + GCC_VERSION_FULL=`echo "$CXX_VERSION" | $PERL -pe 's/^.*gcc version ([^ ]*).*/<<$>>1/'` 1.25 + GCC_VERSION=`echo "$GCC_VERSION_FULL" | $PERL -pe '(split(/\./))[0]>=4&&s/(^\d*\.\d*).*/<<$>>1/;'` 1.26 + 1.27 + GCC_MAJOR_VERSION=`echo ${GCC_VERSION} | $AWK -F\. '{ print <<$>>1 }'` 1.28 + GCC_MINOR_VERSION=`echo ${GCC_VERSION} | $AWK -F\. '{ print <<$>>2 }'` 1.29 + changequote([,]) 1.30 +fi 1.31 + 1.32 +if test "`echo | $AS -o conftest.out -v 2>&1 | grep -c GNU`" != "0"; then 1.33 + GNU_AS=1 1.34 +fi 1.35 +rm -f conftest.out 1.36 +if test "`echo | $LD -v 2>&1 | grep -c GNU`" != "0"; then 1.37 + GNU_LD=1 1.38 +fi 1.39 +if test "$GNU_CC"; then 1.40 + if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then 1.41 + GCC_USE_GNU_LD=1 1.42 + fi 1.43 +fi 1.44 + 1.45 +INTEL_CC= 1.46 +INTEL_CXX= 1.47 +if test "$GCC" = yes; then 1.48 + if test "`$CC -help 2>&1 | grep -c 'Intel(R) C++ Compiler'`" != "0"; then 1.49 + INTEL_CC=1 1.50 + fi 1.51 +fi 1.52 + 1.53 +if test "$GXX" = yes; then 1.54 + if test "`$CXX -help 2>&1 | grep -c 'Intel(R) C++ Compiler'`" != "0"; then 1.55 + INTEL_CXX=1 1.56 + fi 1.57 +fi 1.58 + 1.59 +CLANG_CC= 1.60 +CLANG_CXX= 1.61 +if test "`$CC -v 2>&1 | egrep -c '(clang version|Apple.*clang)'`" != "0"; then 1.62 + CLANG_CC=1 1.63 +fi 1.64 + 1.65 +if test "`$CXX -v 2>&1 | egrep -c '(clang version|Apple.*clang)'`" != "0"; then 1.66 + CLANG_CXX=1 1.67 +fi 1.68 +AC_SUBST(CLANG_CXX) 1.69 +]) 1.70 + 1.71 +AC_DEFUN([MOZ_CROSS_COMPILER], 1.72 +[ 1.73 +echo "cross compiling from $host to $target" 1.74 + 1.75 +_SAVE_CC="$CC" 1.76 +_SAVE_CFLAGS="$CFLAGS" 1.77 +_SAVE_LDFLAGS="$LDFLAGS" 1.78 + 1.79 +AC_MSG_CHECKING([for host c compiler]) 1.80 +AC_CHECK_PROGS(HOST_CC, cc gcc clang cl, "") 1.81 +if test -z "$HOST_CC"; then 1.82 + AC_MSG_ERROR([no acceptable c compiler found in \$PATH]) 1.83 +fi 1.84 +AC_MSG_RESULT([$HOST_CC]) 1.85 +AC_MSG_CHECKING([for host c++ compiler]) 1.86 +AC_CHECK_PROGS(HOST_CXX, c++ g++ clang++ cl, "") 1.87 +if test -z "$HOST_CXX"; then 1.88 + AC_MSG_ERROR([no acceptable c++ compiler found in \$PATH]) 1.89 +fi 1.90 +AC_MSG_RESULT([$HOST_CXX]) 1.91 + 1.92 +if test -z "$HOST_CFLAGS"; then 1.93 + HOST_CFLAGS="$CFLAGS" 1.94 +fi 1.95 +if test -z "$HOST_CXXFLAGS"; then 1.96 + HOST_CXXFLAGS="$CXXFLAGS" 1.97 +fi 1.98 +if test -z "$HOST_LDFLAGS"; then 1.99 + HOST_LDFLAGS="$LDFLAGS" 1.100 +fi 1.101 +if test -z "$HOST_AR_FLAGS"; then 1.102 + HOST_AR_FLAGS="$AR_FLAGS" 1.103 +fi 1.104 +AC_CHECK_PROGS(HOST_RANLIB, $HOST_RANLIB ranlib, ranlib, :) 1.105 +AC_CHECK_PROGS(HOST_AR, $HOST_AR ar, ar, :) 1.106 +CC="$HOST_CC" 1.107 +CFLAGS="$HOST_CFLAGS" 1.108 +LDFLAGS="$HOST_LDFLAGS" 1.109 + 1.110 +AC_MSG_CHECKING([whether the host c compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works]) 1.111 +AC_TRY_COMPILE([], [return(0);], 1.112 + [ac_cv_prog_hostcc_works=1 AC_MSG_RESULT([yes])], 1.113 + AC_MSG_ERROR([installation or configuration problem: host compiler $HOST_CC cannot create executables.]) ) 1.114 + 1.115 +CC="$HOST_CXX" 1.116 +CFLAGS="$HOST_CXXFLAGS" 1.117 +AC_MSG_CHECKING([whether the host c++ compiler ($HOST_CXX $HOST_CXXFLAGS $HOST_LDFLAGS) works]) 1.118 +AC_TRY_COMPILE([], [return(0);], 1.119 + [ac_cv_prog_hostcxx_works=1 AC_MSG_RESULT([yes])], 1.120 + AC_MSG_ERROR([installation or configuration problem: host compiler $HOST_CXX cannot create executables.]) ) 1.121 + 1.122 +CC=$_SAVE_CC 1.123 +CFLAGS=$_SAVE_CFLAGS 1.124 +LDFLAGS=$_SAVE_LDFLAGS 1.125 + 1.126 +AC_CHECK_PROGS(CC, "${target_alias}-gcc" "${target}-gcc", :) 1.127 +unset ac_cv_prog_CC 1.128 +AC_PROG_CC 1.129 +AC_CHECK_PROGS(CXX, "${target_alias}-g++" "${target}-g++", :) 1.130 +unset ac_cv_prog_CXX 1.131 +AC_PROG_CXX 1.132 + 1.133 +AC_CHECK_PROGS(RANLIB, "${target_alias}-ranlib" "${target}-ranlib", :) 1.134 +AC_CHECK_PROGS(AR, "${target_alias}-ar" "${target}-ar", :) 1.135 +MOZ_PATH_PROGS(AS, "${target_alias}-as" "${target}-as", :) 1.136 +AC_CHECK_PROGS(LD, "${target_alias}-ld" "${target}-ld", :) 1.137 +AC_CHECK_PROGS(STRIP, "${target_alias}-strip" "${target}-strip", :) 1.138 +AC_CHECK_PROGS(WINDRES, "${target_alias}-windres" "${target}-windres", :) 1.139 +AC_DEFINE(CROSS_COMPILE) 1.140 +CROSS_COMPILE=1 1.141 + 1.142 +dnl If we cross compile for ppc on Mac OS X x86, cross_compiling will 1.143 +dnl dnl have erroneously been set to "no", because the x86 build host is 1.144 +dnl dnl able to run ppc code in a translated environment, making a cross 1.145 +dnl dnl compiler appear native. So we override that here. 1.146 +cross_compiling=yes 1.147 +]) 1.148 + 1.149 +AC_DEFUN([MOZ_CXX11], 1.150 +[ 1.151 +dnl Check whether gcc's c++0x mode works 1.152 +dnl Updates to the test below should be duplicated further below for the 1.153 +dnl cross-compiling case. 1.154 +AC_LANG_CPLUSPLUS 1.155 +if test "$GNU_CXX"; then 1.156 + CXXFLAGS="$CXXFLAGS -std=gnu++0x" 1.157 + _ADDED_CXXFLAGS="-std=gnu++0x" 1.158 + 1.159 + AC_CACHE_CHECK(for gcc c++0x headers bug without rtti, 1.160 + ac_cv_cxx0x_headers_bug, 1.161 + [AC_TRY_COMPILE([#include <memory>], [], 1.162 + ac_cv_cxx0x_headers_bug="no", 1.163 + ac_cv_cxx0x_headers_bug="yes")]) 1.164 + 1.165 + if test "$CLANG_CXX" -a "$ac_cv_cxx0x_headers_bug" = "yes"; then 1.166 + CXXFLAGS="$CXXFLAGS -I$_topsrcdir/build/unix/headers" 1.167 + _ADDED_CXXFLAGS="$_ADDED_CXXFLAGS -I$_topsrcdir/build/unix/headers" 1.168 + AC_CACHE_CHECK(whether workaround for gcc c++0x headers conflict with clang works, 1.169 + ac_cv_cxx0x_clang_workaround, 1.170 + [AC_TRY_COMPILE([#include <memory>], [], 1.171 + ac_cv_cxx0x_clang_workaround="yes", 1.172 + ac_cv_cxx0x_clang_workaround="no")]) 1.173 + 1.174 + if test "ac_cv_cxx0x_clang_workaround" = "no"; then 1.175 + AC_MSG_ERROR([Your toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain]) 1.176 + fi 1.177 + elif test "$ac_cv_cxx0x_headers_bug" = "yes"; then 1.178 + AC_MSG_ERROR([Your toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain]) 1.179 + fi 1.180 +fi 1.181 +if test -n "$CROSS_COMPILE"; then 1.182 + dnl When cross compile, we have no variable telling us what the host compiler is. Figure it out. 1.183 + cat > conftest.C <<EOF 1.184 +#if defined(__clang__) 1.185 +CLANG 1.186 +#elif defined(__GNUC__) 1.187 +GCC 1.188 +#endif 1.189 +EOF 1.190 + host_compiler=`$HOST_CXX -E conftest.C | egrep '(CLANG|GCC)'` 1.191 + rm conftest.C 1.192 + if test -n "$host_compiler"; then 1.193 + HOST_CXXFLAGS="$HOST_CXXFLAGS -std=gnu++0x" 1.194 + 1.195 + _SAVE_CXXFLAGS="$CXXFLAGS" 1.196 + _SAVE_CPPFLAGS="$CPPFLAGS" 1.197 + _SAVE_CXX="$CXX" 1.198 + CXXFLAGS="$HOST_CXXFLAGS" 1.199 + CPPFLAGS="$HOST_CPPFLAGS" 1.200 + CXX="$HOST_CXX" 1.201 + AC_CACHE_CHECK(for host gcc c++0x headers bug without rtti, 1.202 + ac_cv_host_cxx0x_headers_bug, 1.203 + [AC_TRY_COMPILE([#include <memory>], [], 1.204 + ac_cv_host_cxx0x_headers_bug="no", 1.205 + ac_cv_host_cxx0x_headers_bug="yes")]) 1.206 + 1.207 + if test "$host_compiler" = CLANG -a "$ac_cv_host_cxx0x_headers_bug" = "yes"; then 1.208 + CXXFLAGS="$CXXFLAGS -I$_topsrcdir/build/unix/headers" 1.209 + AC_CACHE_CHECK(whether workaround for host gcc c++0x headers conflict with host clang works, 1.210 + ac_cv_host_cxx0x_clang_workaround, 1.211 + [AC_TRY_COMPILE([#include <memory>], [], 1.212 + ac_cv_host_cxx0x_clang_workaround="yes", 1.213 + ac_cv_host_cxx0x_clang_workaround="no")]) 1.214 + 1.215 + if test "ac_cv_host_cxx0x_clang_workaround" = "no"; then 1.216 + AC_MSG_ERROR([Your host toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain]) 1.217 + fi 1.218 + HOST_CXXFLAGS="$CXXFLAGS" 1.219 + elif test "$ac_cv_host_cxx0x_headers_bug" = "yes"; then 1.220 + AC_MSG_ERROR([Your host toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain]) 1.221 + fi 1.222 + CXXFLAGS="$_SAVE_CXXFLAGS" 1.223 + CPPFLAGS="$_SAVE_CPPFLAGS" 1.224 + CXX="$_SAVE_CXX" 1.225 + fi 1.226 +elif test "$GNU_CXX"; then 1.227 + HOST_CXXFLAGS="$HOST_CXXFLAGS $_ADDED_CXXFLAGS" 1.228 +fi 1.229 +AC_LANG_C 1.230 +])