1 dnl This Source Code Form is subject to the terms of the Mozilla Public
2 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
3 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 AC_DEFUN([MOZ_TOOL_VARIABLES],
13 cat <<EOF > conftest.c
15 #if defined(__clang__)
16 COMPILER clang-cl _MSC_VER
18 COMPILER msvc _MSC_VER
20 #elif defined(__clang__)
21 COMPILER clang __clang_major__.__clang_minor__.__clang_patchlevel__
22 #elif defined(__GNUC__)
23 COMPILER gcc __GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__
24 #elif defined(__INTEL_COMPILER)
25 COMPILER icc __INTEL_COMPILER
28 read dummy compiler CC_VERSION <<EOF
29 $($CC -E $CPPFLAGS $CFLAGS conftest.c 2>/dev/null | grep COMPILER)
31 read dummy cxxcompiler CXX_VERSION <<EOF
32 $($CXX -E $CPPFLAGS $CXXFLAGS conftest.c 2>/dev/null | grep COMPILER)
34 if test "$compiler" != "$cxxcompiler"; then
35 AC_MSG_ERROR([Your C and C++ compilers are different. You need to use the same compiler.])
37 CC_VERSION=`echo "$CC_VERSION" | sed 's/ //g'`
38 CXX_VERSION=`echo "$CXX_VERSION" | sed 's/ //g'`
39 if test "$compiler" = "gcc"; then
43 GCC_VERSION_FULL="$CXX_VERSION"
44 GCC_VERSION=`echo "$GCC_VERSION_FULL" | $PERL -pe '(split(/\./))[0]>=4&&s/(^\d*\.\d*).*/<<$>>1/;'`
46 GCC_MAJOR_VERSION=`echo ${GCC_VERSION} | $AWK -F\. '{ print <<$>>1 }'`
47 GCC_MINOR_VERSION=`echo ${GCC_VERSION} | $AWK -F\. '{ print <<$>>2 }'`
51 if test "`echo | $AS -o conftest.out -v 2>&1 | grep -c GNU`" != "0"; then
55 if test "`echo | $LD -v 2>&1 | grep -c GNU`" != "0"; then
60 if test "$compiler" = "icc"; then
68 if test "$compiler" = "clang"; then
74 if test "$compiler" = "clang-cl"; then
78 if test "$GNU_CC"; then
79 if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then
88 AC_DEFUN([MOZ_CROSS_COMPILER],
90 echo "cross compiling from $host to $target"
93 _SAVE_CFLAGS="$CFLAGS"
94 _SAVE_LDFLAGS="$LDFLAGS"
96 AC_MSG_CHECKING([for host c compiler])
97 AC_CHECK_PROGS(HOST_CC, cc gcc clang cl, "")
98 if test -z "$HOST_CC"; then
99 AC_MSG_ERROR([no acceptable c compiler found in \$PATH])
101 AC_MSG_RESULT([$HOST_CC])
102 AC_MSG_CHECKING([for host c++ compiler])
103 AC_CHECK_PROGS(HOST_CXX, c++ g++ clang++ cl, "")
104 if test -z "$HOST_CXX"; then
105 AC_MSG_ERROR([no acceptable c++ compiler found in \$PATH])
107 AC_MSG_RESULT([$HOST_CXX])
109 if test -z "$HOST_CFLAGS"; then
110 HOST_CFLAGS="$CFLAGS"
112 if test -z "$HOST_CXXFLAGS"; then
113 HOST_CXXFLAGS="$CXXFLAGS"
115 if test -z "$HOST_LDFLAGS"; then
116 HOST_LDFLAGS="$LDFLAGS"
118 if test -z "$HOST_AR_FLAGS"; then
119 HOST_AR_FLAGS="$AR_FLAGS"
121 AC_CHECK_PROGS(HOST_RANLIB, $HOST_RANLIB ranlib, ranlib, :)
122 AC_CHECK_PROGS(HOST_AR, $HOST_AR ar, ar, :)
124 CFLAGS="$HOST_CFLAGS"
125 LDFLAGS="$HOST_LDFLAGS"
127 AC_MSG_CHECKING([whether the host c compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works])
128 AC_TRY_COMPILE([], [return(0);],
129 [ac_cv_prog_hostcc_works=1 AC_MSG_RESULT([yes])],
130 AC_MSG_ERROR([installation or configuration problem: host compiler $HOST_CC cannot create executables.]) )
133 CFLAGS="$HOST_CXXFLAGS"
134 AC_MSG_CHECKING([whether the host c++ compiler ($HOST_CXX $HOST_CXXFLAGS $HOST_LDFLAGS) works])
135 AC_TRY_COMPILE([], [return(0);],
136 [ac_cv_prog_hostcxx_works=1 AC_MSG_RESULT([yes])],
137 AC_MSG_ERROR([installation or configuration problem: host compiler $HOST_CXX cannot create executables.]) )
141 LDFLAGS=$_SAVE_LDFLAGS
143 AC_CHECK_PROGS(CC, "${target_alias}-gcc" "${target}-gcc", :)
146 AC_CHECK_PROGS(CXX, "${target_alias}-g++" "${target}-g++", :)
150 AC_CHECK_PROGS(RANLIB, "${target_alias}-ranlib" "${target}-ranlib", :)
151 AC_CHECK_PROGS(AR, "${target_alias}-ar" "${target}-ar", :)
152 MOZ_PATH_PROGS(AS, "${target_alias}-as" "${target}-as", :)
153 AC_CHECK_PROGS(LD, "${target_alias}-ld" "${target}-ld", :)
154 AC_CHECK_PROGS(STRIP, "${target_alias}-strip" "${target}-strip", :)
155 AC_CHECK_PROGS(WINDRES, "${target_alias}-windres" "${target}-windres", :)
156 AC_DEFINE(CROSS_COMPILE)
159 dnl If we cross compile for ppc on Mac OS X x86, cross_compiling will
160 dnl dnl have erroneously been set to "no", because the x86 build host is
161 dnl dnl able to run ppc code in a translated environment, making a cross
162 dnl dnl compiler appear native. So we override that here.
166 AC_DEFUN([MOZ_CXX11],
168 dnl Check whether gcc's c++0x mode works
169 dnl Updates to the test below should be duplicated further below for the
170 dnl cross-compiling case.
172 if test "$GNU_CXX"; then
173 CXXFLAGS="$CXXFLAGS -std=gnu++0x"
174 _ADDED_CXXFLAGS="-std=gnu++0x"
176 AC_CACHE_CHECK(for gcc c++0x headers bug without rtti,
177 ac_cv_cxx0x_headers_bug,
178 [AC_TRY_COMPILE([#include <memory>], [],
179 ac_cv_cxx0x_headers_bug="no",
180 ac_cv_cxx0x_headers_bug="yes")])
182 if test "$CLANG_CXX" -a "$ac_cv_cxx0x_headers_bug" = "yes"; then
183 CXXFLAGS="$CXXFLAGS -I$_topsrcdir/build/unix/headers"
184 _ADDED_CXXFLAGS="$_ADDED_CXXFLAGS -I$_topsrcdir/build/unix/headers"
185 AC_CACHE_CHECK(whether workaround for gcc c++0x headers conflict with clang works,
186 ac_cv_cxx0x_clang_workaround,
187 [AC_TRY_COMPILE([#include <memory>], [],
188 ac_cv_cxx0x_clang_workaround="yes",
189 ac_cv_cxx0x_clang_workaround="no")])
191 if test "ac_cv_cxx0x_clang_workaround" = "no"; then
192 AC_MSG_ERROR([Your toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
194 elif test "$ac_cv_cxx0x_headers_bug" = "yes"; then
195 AC_MSG_ERROR([Your toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
198 if test -n "$CROSS_COMPILE"; then
199 dnl When cross compile, we have no variable telling us what the host compiler is. Figure it out.
200 cat > conftest.C <<EOF
201 #if defined(__clang__)
203 #elif defined(__GNUC__)
207 host_compiler=`$HOST_CXX -E conftest.C | egrep '(CLANG|GCC)'`
209 if test -n "$host_compiler"; then
210 HOST_CXXFLAGS="$HOST_CXXFLAGS -std=gnu++0x"
212 _SAVE_CXXFLAGS="$CXXFLAGS"
213 _SAVE_CPPFLAGS="$CPPFLAGS"
215 CXXFLAGS="$HOST_CXXFLAGS"
216 CPPFLAGS="$HOST_CPPFLAGS"
218 AC_CACHE_CHECK(for host gcc c++0x headers bug without rtti,
219 ac_cv_host_cxx0x_headers_bug,
220 [AC_TRY_COMPILE([#include <memory>], [],
221 ac_cv_host_cxx0x_headers_bug="no",
222 ac_cv_host_cxx0x_headers_bug="yes")])
224 if test "$host_compiler" = CLANG -a "$ac_cv_host_cxx0x_headers_bug" = "yes"; then
225 CXXFLAGS="$CXXFLAGS -I$_topsrcdir/build/unix/headers"
226 AC_CACHE_CHECK(whether workaround for host gcc c++0x headers conflict with host clang works,
227 ac_cv_host_cxx0x_clang_workaround,
228 [AC_TRY_COMPILE([#include <memory>], [],
229 ac_cv_host_cxx0x_clang_workaround="yes",
230 ac_cv_host_cxx0x_clang_workaround="no")])
232 if test "ac_cv_host_cxx0x_clang_workaround" = "no"; then
233 AC_MSG_ERROR([Your host toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
235 HOST_CXXFLAGS="$CXXFLAGS"
236 elif test "$ac_cv_host_cxx0x_headers_bug" = "yes"; then
237 AC_MSG_ERROR([Your host toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
239 CXXFLAGS="$_SAVE_CXXFLAGS"
240 CPPFLAGS="$_SAVE_CPPFLAGS"
243 elif test "$GNU_CXX"; then
244 HOST_CXXFLAGS="$HOST_CXXFLAGS $_ADDED_CXXFLAGS"