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
dnl Add compiler specific options
7
AC_DEFUN([MOZ_DEFAULT_COMPILER],
9
dnl Default to MSVC for win32 and gcc-4.2 for darwin
10
dnl ==============================================================
11
if test -z "$CROSS_COMPILE"; then
14
if test -z "$CC"; then CC=cl; fi
15
if test -z "$CXX"; then CXX=cl; fi
16
if test -z "$CPP"; then CPP="cl -E -nologo"; fi
17
if test -z "$CXXCPP"; then CXXCPP="cl -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi
18
if test -z "$LD"; then LD=link; fi
19
if test -z "$AS"; then
20
case "${target_cpu}" in
29
if test -z "$MIDL"; then MIDL=midl; fi
31
# need override this flag since we don't use $(LDFLAGS) for this.
32
if test -z "$HOST_LDFLAGS" ; then
37
# we prefer gcc-4.2 over gcc on older darwin, so
38
# use that specific version if it's available.
39
# On newer versions of darwin, gcc is llvm-gcc while gcc-4.2 is the plain
40
# one, so we also try that first. If that fails, we fall back to clang
41
# as llvm-gcc is an unsupported dead end.
42
MOZ_PATH_PROGS(CC, $CC gcc-4.2 clang gcc)
43
MOZ_PATH_PROGS(CXX, $CXX g++-4.2 clang++ g++)
44
IS_LLVM_GCC=$($CC -v 2>&1 | grep llvm-gcc)
45
if test -n "$IS_LLVM_GCC"
47
echo llvm-gcc is known to be broken, please use gcc-4.2 or clang.
55
dnl ============================================================================
57
dnl We don't use it in the code, but it can be usefull for debugging, so give
58
dnl the user the option of enabling it.
59
dnl ============================================================================
62
MOZ_ARG_ENABLE_BOOL(cpp-rtti,
63
[ --enable-cpp-rtti Enable C++ RTTI ],
67
if test -z "$_MOZ_USE_RTTI"; then
68
if test "$GNU_CC"; then
69
CXXFLAGS="$CXXFLAGS -fno-rtti"
73
CXXFLAGS="$CXXFLAGS -GR-"
79
dnl A high level macro for selecting compiler options.
80
AC_DEFUN([MOZ_COMPILER_OPTS],
83
if test "$CLANG_CXX"; then
84
## We disable return-type-c-linkage because jsval is defined as a C++ type but is
85
## returned by C functions. This is possible because we use knowledge about the ABI
86
## to typedef it to a C type with the same layout when the headers are included
89
## mismatched-tags is disabled (bug 780474) mostly because it's useless.
90
## Worse, it's not supported by gcc, so it will cause tryserver bustage
91
## without any easy way for non-Clang users to check for it.
92
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-mismatched-tags"
95
if test "$GNU_CC"; then
96
CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
97
CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections -fno-exceptions"
100
dnl ========================================================
101
dnl = Identical Code Folding
102
dnl ========================================================
104
MOZ_ARG_DISABLE_BOOL(icf,
105
[ --disable-icf Disable Identical Code Folding],
109
if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF"; then
110
AC_CACHE_CHECK([whether the linker supports Identical Code Folding],
112
[echo 'int foo() {return 42;}' \
113
'int bar() {return 42;}' \
114
'int main() {return foo() - bar();}' > conftest.${ac_ext}
115
# If the linker supports ICF, foo and bar symbols will have
117
if AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS -Wl,--icf=safe -ffunction-sections conftest.${ac_ext} $LIBS 1>&2]) &&
118
test -s conftest${ac_exeext} &&
119
objdump -t conftest${ac_exeext} | awk changequote(<<, >>)'{a[<<$>>6] = <<$>>1} END {if (a["foo"] && (a["foo"] != a["bar"])) { exit 1 }}'changequote([, ]); then
125
if test "$LD_SUPPORTS_ICF" = yes; then
126
_SAVE_LDFLAGS="$LDFLAGS -Wl,--icf=safe"
127
LDFLAGS="$LDFLAGS -Wl,--icf=safe -Wl,--print-icf-sections"
129
[LD_PRINT_ICF_SECTIONS=-Wl,--print-icf-sections],
130
[LD_PRINT_ICF_SECTIONS=])
131
AC_SUBST([LD_PRINT_ICF_SECTIONS])
132
LDFLAGS="$_SAVE_LDFLAGS"
136
dnl ========================================================
137
dnl = Automatically remove dead symbols
138
dnl ========================================================
140
if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -n "$MOZ_DEBUG_FLAGS"; then
142
AC_CACHE_CHECK([whether removing dead symbols breaks debugging],
143
GC_SECTIONS_BREAKS_DEBUG_RANGES,
144
[echo 'int foo() {return 42;}' \
145
'int bar() {return 1;}' \
146
'int main() {return foo();}' > conftest.${ac_ext}
147
if AC_TRY_COMMAND([${CC-cc} -o conftest.${ac_objext} $CFLAGS $MOZ_DEBUG_FLAGS -c conftest.${ac_ext} 1>&2]) &&
148
AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS $MOZ_DEBUG_FLAGS -Wl,--gc-sections conftest.${ac_objext} $LIBS 1>&2]) &&
149
test -s conftest${ac_exeext} -a -s conftest.${ac_objext}; then
150
if test "`$PYTHON "$_topsrcdir"/build/autoconf/check_debug_ranges.py conftest.${ac_objext} conftest.${ac_ext}`" = \
151
"`$PYTHON "$_topsrcdir"/build/autoconf/check_debug_ranges.py conftest${ac_exeext} conftest.${ac_ext}`"; then
152
GC_SECTIONS_BREAKS_DEBUG_RANGES=no
154
GC_SECTIONS_BREAKS_DEBUG_RANGES=yes
157
dnl We really don't expect to get here, but just in case
158
GC_SECTIONS_BREAKS_DEBUG_RANGES="no, but it's broken in some other way"
161
if test "$GC_SECTIONS_BREAKS_DEBUG_RANGES" = no; then
162
DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections"
168
dnl GCC and clang will fail if given an unknown warning option like -Wfoobar.
169
dnl But later versions won't fail if given an unknown negated warning option
170
dnl like -Wno-foobar. So when we are check for support of negated warning
171
dnl options, we actually test the positive form, but add the negated form to
172
dnl the flags variable.
174
AC_DEFUN([MOZ_C_SUPPORTS_WARNING],
176
AC_CACHE_CHECK(whether the C compiler supports $1$2, $3,
180
_SAVE_CFLAGS="$CFLAGS"
181
CFLAGS="$CFLAGS -Werror -W$2"
186
CFLAGS="$_SAVE_CFLAGS"
189
if test "${$3}" = "yes"; then
190
_WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} $1$2"
194
AC_DEFUN([MOZ_CXX_SUPPORTS_WARNING],
196
AC_CACHE_CHECK(whether the C++ compiler supports $1$2, $3,
200
_SAVE_CXXFLAGS="$CXXFLAGS"
201
CXXFLAGS="$CXXFLAGS -Werror -W$2"
206
CXXFLAGS="$_SAVE_CXXFLAGS"
209
if test "${$3}" = "yes"; then
210
_WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} $1$2"