Bumping manifests a=b2g-bump
[gecko.git] / build / autoconf / toolchain.m4
blobf6ffa109b4e8f715a4b5b9d34391a3439edcbba4
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],
7 GNU_AS=
8 GNU_LD=
9 GNU_CC=
10 GNU_CXX=
11 CC_VERSION='N/A'
12 CXX_VERSION='N/A'
13 cat <<EOF > conftest.c
14 #if defined(_MSC_VER)
15 #if defined(__clang__)
16 COMPILER clang-cl _MSC_VER
17 #else
18 COMPILER msvc _MSC_FULL_VER
19 #endif
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
26 #endif
27 EOF
28 read dummy compiler CC_VERSION <<EOF
29 $($CC -E $CPPFLAGS $CFLAGS conftest.c 2>/dev/null | grep COMPILER)
30 EOF
31 read dummy cxxcompiler CXX_VERSION <<EOF
32 $($CXX -E $CPPFLAGS $CXXFLAGS conftest.c 2>/dev/null | grep COMPILER)
33 EOF
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
40     GNU_CC=1
41     GNU_CXX=1
42     changequote(<<,>>)
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 }'`
48     changequote([,])
51 if test "`echo | $AS -o conftest.out -v 2>&1 | grep -c GNU`" != "0"; then
52     GNU_AS=1
54 rm -f conftest.out
55 if test "`echo | $LD -v 2>&1 | grep -c GNU`" != "0"; then
56     GNU_LD=1
59 if test "$compiler" = "msvc"; then
60      MSVC_VERSION_FULL="$CXX_VERSION"
61      CC_VERSION=`echo ${CC_VERSION} | cut -c 1-4`
62      CXX_VERSION=`echo ${CXX_VERSION} | cut -c 1-4`
65 INTEL_CC=
66 INTEL_CXX=
67 if test "$compiler" = "icc"; then
68    INTEL_CC=1
69    INTEL_CXX=1
72 CLANG_CC=
73 CLANG_CXX=
74 CLANG_CL=
75 if test "$compiler" = "clang"; then
76     GNU_CC=1
77     GNU_CXX=1
78     CLANG_CC=1
79     CLANG_CXX=1
81 if test "$compiler" = "clang-cl"; then
82     CLANG_CL=1
83     # We force clang-cl to emulate Visual C++ 2013 in configure.in, but that
84     # is based on the CLANG_CL variable defined here, so make sure that we're
85     # getting the right version here manually.
86     CC_VERSION=1800
87     CXX_VERSION=1800
88     MSVC_VERSION_FULL=180030723
89     # Build on clang-cl with MSVC 2013 Update 3 with fallback emulation.
90     CFLAGS="$CFLAGS -fms-compatibility-version=18.00.30723 -fallback"
91     CXXFLAGS="$CXXFLAGS -fms-compatibility-version=18.00.30723 -fallback"
94 if test "$GNU_CC"; then
95     if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then
96         GCC_USE_GNU_LD=1
97     fi
100 AC_SUBST(CLANG_CXX)
101 AC_SUBST(CLANG_CL)
103 if test -n "$GNU_CC" -a -z "$CLANG_CC" ; then
104     if test "$GCC_MAJOR_VERSION" -eq 4 -a "$GCC_MINOR_VERSION" -lt 6 ||
105        test "$GCC_MAJOR_VERSION" -lt 4; then
106         AC_MSG_ERROR([Only GCC 4.6 or newer supported])
107     fi
111 AC_DEFUN([MOZ_CROSS_COMPILER],
113 echo "cross compiling from $host to $target"
115 _SAVE_CC="$CC"
116 _SAVE_CFLAGS="$CFLAGS"
117 _SAVE_LDFLAGS="$LDFLAGS"
119 AC_MSG_CHECKING([for host c compiler])
120 AC_CHECK_PROGS(HOST_CC, cc gcc clang cl, "")
121 if test -z "$HOST_CC"; then
122     AC_MSG_ERROR([no acceptable c compiler found in \$PATH])
124 AC_MSG_RESULT([$HOST_CC])
125 AC_MSG_CHECKING([for host c++ compiler])
126 AC_CHECK_PROGS(HOST_CXX, c++ g++ clang++ cl, "")
127 if test -z "$HOST_CXX"; then
128     AC_MSG_ERROR([no acceptable c++ compiler found in \$PATH])
130 AC_MSG_RESULT([$HOST_CXX])
132 if test -z "$HOST_CFLAGS"; then
133     HOST_CFLAGS="$CFLAGS"
135 if test -z "$HOST_CXXFLAGS"; then
136     HOST_CXXFLAGS="$CXXFLAGS"
138 if test -z "$HOST_LDFLAGS"; then
139     HOST_LDFLAGS="$LDFLAGS"
141 if test -z "$HOST_AR_FLAGS"; then
142     HOST_AR_FLAGS="$AR_FLAGS"
144 AC_CHECK_PROGS(HOST_RANLIB, $HOST_RANLIB ranlib, ranlib, :)
145 AC_CHECK_PROGS(HOST_AR, $HOST_AR ar, ar, :)
146 CC="$HOST_CC"
147 CFLAGS="$HOST_CFLAGS"
148 LDFLAGS="$HOST_LDFLAGS"
150 AC_MSG_CHECKING([whether the host c compiler ($HOST_CC $HOST_CFLAGS $HOST_LDFLAGS) works])
151 AC_TRY_COMPILE([], [return(0);],
152     [ac_cv_prog_hostcc_works=1 AC_MSG_RESULT([yes])],
153     AC_MSG_ERROR([installation or configuration problem: host compiler $HOST_CC cannot create executables.]) )
155 CC="$HOST_CXX"
156 CFLAGS="$HOST_CXXFLAGS"
157 AC_MSG_CHECKING([whether the host c++ compiler ($HOST_CXX $HOST_CXXFLAGS $HOST_LDFLAGS) works])
158 AC_TRY_COMPILE([], [return(0);],
159     [ac_cv_prog_hostcxx_works=1 AC_MSG_RESULT([yes])],
160     AC_MSG_ERROR([installation or configuration problem: host compiler $HOST_CXX cannot create executables.]) )
162 CC=$_SAVE_CC
163 CFLAGS=$_SAVE_CFLAGS
164 LDFLAGS=$_SAVE_LDFLAGS
166 AC_CHECK_PROGS(CC, "${target_alias}-gcc" "${target}-gcc", :)
167 unset ac_cv_prog_CC
168 AC_PROG_CC
169 AC_CHECK_PROGS(CXX, "${target_alias}-g++" "${target}-g++", :)
170 unset ac_cv_prog_CXX
171 AC_PROG_CXX
173 AC_CHECK_PROGS(RANLIB, "${target_alias}-ranlib" "${target}-ranlib", :)
174 AC_CHECK_PROGS(AR, "${target_alias}-ar" "${target}-ar", :)
175 MOZ_PATH_PROGS(AS, "${target_alias}-as" "${target}-as", :)
176 AC_CHECK_PROGS(LD, "${target_alias}-ld" "${target}-ld", :)
177 AC_CHECK_PROGS(STRIP, "${target_alias}-strip" "${target}-strip", :)
178 AC_CHECK_PROGS(WINDRES, "${target_alias}-windres" "${target}-windres", :)
179 AC_CHECK_PROGS(OTOOL, "${target_alias}-otool" "${target}-otool", :)
180 AC_DEFINE(CROSS_COMPILE)
181 CROSS_COMPILE=1
183 dnl If we cross compile for ppc on Mac OS X x86, cross_compiling will
184 dnl dnl have erroneously been set to "no", because the x86 build host is
185 dnl dnl able to run ppc code in a translated environment, making a cross
186 dnl dnl compiler appear native.  So we override that here.
187 cross_compiling=yes
190 AC_DEFUN([MOZ_CXX11],
192 dnl Check whether gcc's c++0x mode works
193 dnl Updates to the test below should be duplicated further below for the
194 dnl cross-compiling case.
195 AC_LANG_CPLUSPLUS
196 if test "$GNU_CXX"; then
197     CXXFLAGS="$CXXFLAGS -std=gnu++0x"
198     _ADDED_CXXFLAGS="-std=gnu++0x"
200     AC_CACHE_CHECK(for gcc c++0x headers bug without rtti,
201         ac_cv_cxx0x_headers_bug,
202         [AC_TRY_COMPILE([#include <memory>], [],
203                         ac_cv_cxx0x_headers_bug="no",
204                         ac_cv_cxx0x_headers_bug="yes")])
206     if test "$CLANG_CXX" -a "$ac_cv_cxx0x_headers_bug" = "yes"; then
207         CXXFLAGS="$CXXFLAGS -I$_topsrcdir/build/unix/headers"
208         _ADDED_CXXFLAGS="$_ADDED_CXXFLAGS -I$_topsrcdir/build/unix/headers"
209         AC_CACHE_CHECK(whether workaround for gcc c++0x headers conflict with clang works,
210             ac_cv_cxx0x_clang_workaround,
211             [AC_TRY_COMPILE([#include <memory>], [],
212                             ac_cv_cxx0x_clang_workaround="yes",
213                             ac_cv_cxx0x_clang_workaround="no")])
215         if test "ac_cv_cxx0x_clang_workaround" = "no"; then
216             AC_MSG_ERROR([Your toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
217         fi
218     elif test "$ac_cv_cxx0x_headers_bug" = "yes"; then
219         AC_MSG_ERROR([Your toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
220     fi
222 if test -n "$CROSS_COMPILE"; then
223     dnl When cross compile, we have no variable telling us what the host compiler is. Figure it out.
224     cat > conftest.C <<EOF
225 #if defined(__clang__)
226 CLANG
227 #elif defined(__GNUC__)
229 #endif
231     host_compiler=`$HOST_CXX -E conftest.C | egrep '(CLANG|GCC)'`
232     rm conftest.C
233     if test -n "$host_compiler"; then
234         HOST_CXXFLAGS="$HOST_CXXFLAGS -std=gnu++0x"
236         _SAVE_CXXFLAGS="$CXXFLAGS"
237         _SAVE_CPPFLAGS="$CPPFLAGS"
238         _SAVE_CXX="$CXX"
239         CXXFLAGS="$HOST_CXXFLAGS"
240         CPPFLAGS="$HOST_CPPFLAGS"
241         CXX="$HOST_CXX"
242         AC_CACHE_CHECK(for host gcc c++0x headers bug without rtti,
243             ac_cv_host_cxx0x_headers_bug,
244             [AC_TRY_COMPILE([#include <memory>], [],
245                             ac_cv_host_cxx0x_headers_bug="no",
246                             ac_cv_host_cxx0x_headers_bug="yes")])
248         if test "$host_compiler" = CLANG -a "$ac_cv_host_cxx0x_headers_bug" = "yes"; then
249             CXXFLAGS="$CXXFLAGS -I$_topsrcdir/build/unix/headers"
250             AC_CACHE_CHECK(whether workaround for host gcc c++0x headers conflict with host clang works,
251                 ac_cv_host_cxx0x_clang_workaround,
252                 [AC_TRY_COMPILE([#include <memory>], [],
253                                 ac_cv_host_cxx0x_clang_workaround="yes",
254                                 ac_cv_host_cxx0x_clang_workaround="no")])
256             if test "ac_cv_host_cxx0x_clang_workaround" = "no"; then
257                 AC_MSG_ERROR([Your host toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
258             fi
259             HOST_CXXFLAGS="$CXXFLAGS"
260         elif test "$ac_cv_host_cxx0x_headers_bug" = "yes"; then
261             AC_MSG_ERROR([Your host toolchain does not support C++0x/C++11 mode properly. Please upgrade your toolchain])
262         fi
263         CXXFLAGS="$_SAVE_CXXFLAGS"
264         CPPFLAGS="$_SAVE_CPPFLAGS"
265         CXX="$_SAVE_CXX"
266     fi
267 elif test "$GNU_CXX"; then
268     HOST_CXXFLAGS="$HOST_CXXFLAGS $_ADDED_CXXFLAGS"
270 AC_LANG_C