Bumping manifests a=b2g-bump
[gecko.git] / build / autoconf / toolchain.m4
blobdf8651ebf45b0446161ad6a5efdf560b2cdf5683
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_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
58 INTEL_CC=
59 INTEL_CXX=
60 if test "$compiler" = "icc"; then
61    INTEL_CC=1
62    INTEL_CXX=1
65 CLANG_CC=
66 CLANG_CXX=
67 CLANG_CL=
68 if test "$compiler" = "clang"; then
69     GNU_CC=1
70     GNU_CXX=1
71     CLANG_CC=1
72     CLANG_CXX=1
74 if test "$compiler" = "clang-cl"; then
75     CLANG_CL=1
78 if test "$GNU_CC"; then
79     if `$CC -print-prog-name=ld` -v 2>&1 | grep -c GNU >/dev/null; then
80         GCC_USE_GNU_LD=1
81     fi
84 AC_SUBST(CLANG_CXX)
85 AC_SUBST(CLANG_CL)
88 AC_DEFUN([MOZ_CROSS_COMPILER],
90 echo "cross compiling from $host to $target"
92 _SAVE_CC="$CC"
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, :)
123 CC="$HOST_CC"
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.]) )
132 CC="$HOST_CXX"
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.]) )
139 CC=$_SAVE_CC
140 CFLAGS=$_SAVE_CFLAGS
141 LDFLAGS=$_SAVE_LDFLAGS
143 AC_CHECK_PROGS(CC, "${target_alias}-gcc" "${target}-gcc", :)
144 unset ac_cv_prog_CC
145 AC_PROG_CC
146 AC_CHECK_PROGS(CXX, "${target_alias}-g++" "${target}-g++", :)
147 unset ac_cv_prog_CXX
148 AC_PROG_CXX
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)
157 CROSS_COMPILE=1
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.
163 cross_compiling=yes
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.
171 AC_LANG_CPLUSPLUS
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])
193         fi
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])
196     fi
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__)
202 CLANG
203 #elif defined(__GNUC__)
205 #endif
207     host_compiler=`$HOST_CXX -E conftest.C | egrep '(CLANG|GCC)'`
208     rm conftest.C
209     if test -n "$host_compiler"; then
210         HOST_CXXFLAGS="$HOST_CXXFLAGS -std=gnu++0x"
212         _SAVE_CXXFLAGS="$CXXFLAGS"
213         _SAVE_CPPFLAGS="$CPPFLAGS"
214         _SAVE_CXX="$CXX"
215         CXXFLAGS="$HOST_CXXFLAGS"
216         CPPFLAGS="$HOST_CPPFLAGS"
217         CXX="$HOST_CXX"
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])
234             fi
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])
238         fi
239         CXXFLAGS="$_SAVE_CXXFLAGS"
240         CPPFLAGS="$_SAVE_CPPFLAGS"
241         CXX="$_SAVE_CXX"
242     fi
243 elif test "$GNU_CXX"; then
244     HOST_CXXFLAGS="$HOST_CXXFLAGS $_ADDED_CXXFLAGS"
246 AC_LANG_C