1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/autoconf/compiler-opts.m4 Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,381 @@ 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 +dnl Add compiler specific options 1.9 + 1.10 +AC_DEFUN([MOZ_DEFAULT_COMPILER], 1.11 +[ 1.12 +dnl set DEVELOPER_OPTIONS early; MOZ_DEFAULT_COMPILER is usually the first non-setup directive 1.13 + if test -z "$MOZILLA_OFFICIAL"; then 1.14 + DEVELOPER_OPTIONS=1 1.15 + fi 1.16 + MOZ_ARG_ENABLE_BOOL(release, 1.17 + [ --enable-release Build with more conservative, release engineering-oriented options. 1.18 + This may slow down builds.], 1.19 + DEVELOPER_OPTIONS=, 1.20 + DEVELOPER_OPTIONS=1) 1.21 + 1.22 + AC_SUBST(DEVELOPER_OPTIONS) 1.23 + 1.24 +dnl Default to MSVC for win32 and gcc-4.2 for darwin 1.25 +dnl ============================================================== 1.26 +if test -z "$CROSS_COMPILE"; then 1.27 +case "$target" in 1.28 +*-mingw*) 1.29 + if test -z "$CC"; then CC=cl; fi 1.30 + if test -z "$CXX"; then CXX=cl; fi 1.31 + if test -z "$CPP"; then CPP="cl -E -nologo"; fi 1.32 + if test -z "$CXXCPP"; then CXXCPP="cl -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi 1.33 + if test -z "$LD"; then LD=link; fi 1.34 + if test -z "$AS"; then 1.35 + case "${target_cpu}" in 1.36 + i*86) 1.37 + AS=ml; 1.38 + ;; 1.39 + x86_64) 1.40 + AS=ml64; 1.41 + ;; 1.42 + esac 1.43 + fi 1.44 + if test -z "$MIDL"; then MIDL=midl; fi 1.45 + 1.46 + # need override this flag since we don't use $(LDFLAGS) for this. 1.47 + if test -z "$HOST_LDFLAGS" ; then 1.48 + HOST_LDFLAGS=" " 1.49 + fi 1.50 + ;; 1.51 +*-darwin*) 1.52 + # GCC on darwin is based on gcc 4.2 and we don't support it anymore. 1.53 + if test -z "$CC"; then 1.54 + MOZ_PATH_PROGS(CC, clang) 1.55 + fi 1.56 + if test -z "$CXX"; then 1.57 + MOZ_PATH_PROGS(CXX, clang++) 1.58 + fi 1.59 + IS_GCC=$($CC -v 2>&1 | grep gcc) 1.60 + if test -n "$IS_GCC" 1.61 + then 1.62 + echo gcc is known to be broken on OS X, please use clang. 1.63 + echo see http://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites 1.64 + echo for more information. 1.65 + exit 1 1.66 + fi 1.67 + ;; 1.68 +esac 1.69 +fi 1.70 +]) 1.71 + 1.72 +dnl ============================================================================ 1.73 +dnl C++ rtti 1.74 +dnl We don't use it in the code, but it can be usefull for debugging, so give 1.75 +dnl the user the option of enabling it. 1.76 +dnl ============================================================================ 1.77 +AC_DEFUN([MOZ_RTTI], 1.78 +[ 1.79 +MOZ_ARG_ENABLE_BOOL(cpp-rtti, 1.80 +[ --enable-cpp-rtti Enable C++ RTTI ], 1.81 +[ _MOZ_USE_RTTI=1 ], 1.82 +[ _MOZ_USE_RTTI= ]) 1.83 + 1.84 +if test -z "$_MOZ_USE_RTTI"; then 1.85 + if test "$GNU_CC"; then 1.86 + CXXFLAGS="$CXXFLAGS -fno-rtti" 1.87 + else 1.88 + case "$target" in 1.89 + *-mingw*) 1.90 + CXXFLAGS="$CXXFLAGS -GR-" 1.91 + esac 1.92 + fi 1.93 +fi 1.94 +]) 1.95 + 1.96 +dnl ======================================================== 1.97 +dnl = 1.98 +dnl = Debugging Options 1.99 +dnl = 1.100 +dnl ======================================================== 1.101 +AC_DEFUN([MOZ_DEBUGGING_OPTS], 1.102 +[ 1.103 +dnl Debug info is ON by default. 1.104 +if test -z "$MOZ_DEBUG_FLAGS"; then 1.105 + if test -n "$_MSC_VER"; then 1.106 + MOZ_DEBUG_FLAGS="-Zi" 1.107 + else 1.108 + MOZ_DEBUG_FLAGS="-g" 1.109 + fi 1.110 +fi 1.111 + 1.112 +AC_SUBST(MOZ_DEBUG_FLAGS) 1.113 + 1.114 +MOZ_ARG_ENABLE_STRING(debug, 1.115 +[ --enable-debug[=DBG] Enable building with developer debug info 1.116 + (using compiler flags DBG)], 1.117 +[ if test "$enableval" != "no"; then 1.118 + MOZ_DEBUG=1 1.119 + if test -n "$enableval" -a "$enableval" != "yes"; then 1.120 + MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'` 1.121 + _MOZ_DEBUG_FLAGS_SET=1 1.122 + fi 1.123 + else 1.124 + MOZ_DEBUG= 1.125 + fi ], 1.126 + MOZ_DEBUG=) 1.127 + 1.128 +MOZ_DEBUG_ENABLE_DEFS="-DDEBUG -D_DEBUG -DTRACING" 1.129 +MOZ_ARG_WITH_STRING(debug-label, 1.130 +[ --with-debug-label=LABELS 1.131 + Define DEBUG_<value> for each comma-separated 1.132 + value given.], 1.133 +[ for option in `echo $withval | sed 's/,/ /g'`; do 1.134 + MOZ_DEBUG_ENABLE_DEFS="$MOZ_DEBUG_ENABLE_DEFS -DDEBUG_${option}" 1.135 +done]) 1.136 + 1.137 +MOZ_DEBUG_DISABLE_DEFS="-DNDEBUG -DTRIMMED" 1.138 + 1.139 +if test -n "$MOZ_DEBUG"; then 1.140 + AC_MSG_CHECKING([for valid debug flags]) 1.141 + _SAVE_CFLAGS=$CFLAGS 1.142 + CFLAGS="$CFLAGS $MOZ_DEBUG_FLAGS" 1.143 + AC_TRY_COMPILE([#include <stdio.h>], 1.144 + [printf("Hello World\n");], 1.145 + _results=yes, 1.146 + _results=no) 1.147 + AC_MSG_RESULT([$_results]) 1.148 + if test "$_results" = "no"; then 1.149 + AC_MSG_ERROR([These compiler flags are invalid: $MOZ_DEBUG_FLAGS]) 1.150 + fi 1.151 + CFLAGS=$_SAVE_CFLAGS 1.152 +fi 1.153 + 1.154 +dnl ======================================================== 1.155 +dnl = Enable generation of debug symbols 1.156 +dnl ======================================================== 1.157 +MOZ_ARG_ENABLE_STRING(debug-symbols, 1.158 +[ --enable-debug-symbols[=DBG] 1.159 + Enable debugging symbols (using compiler flags DBG)], 1.160 +[ if test "$enableval" != "no"; then 1.161 + MOZ_DEBUG_SYMBOLS=1 1.162 + if test -n "$enableval" -a "$enableval" != "yes"; then 1.163 + if test -z "$_MOZ_DEBUG_FLAGS_SET"; then 1.164 + MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'` 1.165 + else 1.166 + AC_MSG_ERROR([--enable-debug-symbols flags cannot be used with --enable-debug flags]) 1.167 + fi 1.168 + fi 1.169 + else 1.170 + MOZ_DEBUG_SYMBOLS= 1.171 + fi ], 1.172 + MOZ_DEBUG_SYMBOLS=1) 1.173 + 1.174 +if test -n "$MOZ_DEBUG" -o -n "$MOZ_DEBUG_SYMBOLS"; then 1.175 + AC_DEFINE(MOZ_DEBUG_SYMBOLS) 1.176 + export MOZ_DEBUG_SYMBOLS 1.177 +fi 1.178 + 1.179 +]) 1.180 + 1.181 +dnl A high level macro for selecting compiler options. 1.182 +AC_DEFUN([MOZ_COMPILER_OPTS], 1.183 +[ 1.184 + if test "${MOZ_PSEUDO_DERECURSE-unset}" = unset; then 1.185 + dnl Don't enable on pymake, because of bug 918652. Bug 912979 is an annoyance 1.186 + dnl with pymake, too. 1.187 + MOZ_PSEUDO_DERECURSE=no-pymake 1.188 + fi 1.189 + 1.190 + MOZ_DEBUGGING_OPTS 1.191 + MOZ_RTTI 1.192 +if test "$CLANG_CXX"; then 1.193 + ## We disable return-type-c-linkage because jsval is defined as a C++ type but is 1.194 + ## returned by C functions. This is possible because we use knowledge about the ABI 1.195 + ## to typedef it to a C type with the same layout when the headers are included 1.196 + ## from C. 1.197 + ## 1.198 + ## mismatched-tags is disabled (bug 780474) mostly because it's useless. 1.199 + ## Worse, it's not supported by gcc, so it will cause tryserver bustage 1.200 + ## without any easy way for non-Clang users to check for it. 1.201 + _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-mismatched-tags" 1.202 +fi 1.203 + 1.204 +AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) actually is a C++ compiler]) 1.205 +AC_LANG_SAVE 1.206 +AC_LANG_CPLUSPLUS 1.207 +_SAVE_LIBS=$LIBS 1.208 +LIBS= 1.209 +AC_TRY_LINK([#include <new>], [int *foo = new int;],, 1.210 + AC_MSG_RESULT([no]) 1.211 + AC_MSG_ERROR([$CXX $CXXFLAGS $LDFLAGS failed to compile and link a simple C++ source.])) 1.212 +LIBS=$_SAVE_LIBS 1.213 +AC_LANG_RESTORE 1.214 +AC_MSG_RESULT([yes]) 1.215 + 1.216 +if test -z "$GNU_CC"; then 1.217 + case "$target" in 1.218 + *-mingw*) 1.219 + ## Warning 4099 (equivalent of mismatched-tags) is disabled (bug 780474) 1.220 + ## for the same reasons as above. 1.221 + _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -wd4099" 1.222 + esac 1.223 +fi 1.224 + 1.225 +if test -n "$DEVELOPER_OPTIONS"; then 1.226 + MOZ_FORCE_GOLD=1 1.227 +fi 1.228 + 1.229 +MOZ_ARG_ENABLE_BOOL(gold, 1.230 +[ --enable-gold Enable GNU Gold Linker when it is not already the default], 1.231 + MOZ_FORCE_GOLD=1, 1.232 + MOZ_FORCE_GOLD= 1.233 + ) 1.234 + 1.235 +if test "$GNU_CC" -a -n "$MOZ_FORCE_GOLD"; then 1.236 + dnl if the default linker is BFD ld, check if gold is available and try to use it 1.237 + dnl for local builds only. 1.238 + if $CC -Wl,--version 2>&1 | grep -q "GNU ld"; then 1.239 + GOLD=$($CC -print-prog-name=ld.gold) 1.240 + case "$GOLD" in 1.241 + /*) 1.242 + ;; 1.243 + *) 1.244 + GOLD=$(which $GOLD) 1.245 + ;; 1.246 + esac 1.247 + if test -n "$GOLD"; then 1.248 + mkdir -p $_objdir/build/unix/gold 1.249 + rm -f $_objdir/build/unix/gold/ld 1.250 + ln -s "$GOLD" $_objdir/build/unix/gold/ld 1.251 + if $CC -B $_objdir/build/unix/gold -Wl,--version 2>&1 | grep -q "GNU gold"; then 1.252 + LDFLAGS="$LDFLAGS -B $_objdir/build/unix/gold" 1.253 + else 1.254 + rm -rf $_objdir/build/unix/gold 1.255 + fi 1.256 + fi 1.257 + fi 1.258 +fi 1.259 + 1.260 +if test "$GNU_CC"; then 1.261 + if test -z "$DEVELOPER_OPTIONS"; then 1.262 + CFLAGS="$CFLAGS -ffunction-sections -fdata-sections" 1.263 + CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections" 1.264 + fi 1.265 + CFLAGS="$CFLAGS -fno-math-errno" 1.266 + CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-math-errno" 1.267 +fi 1.268 + 1.269 +dnl ======================================================== 1.270 +dnl = Identical Code Folding 1.271 +dnl ======================================================== 1.272 + 1.273 +MOZ_ARG_DISABLE_BOOL(icf, 1.274 +[ --disable-icf Disable Identical Code Folding], 1.275 + MOZ_DISABLE_ICF=1, 1.276 + MOZ_DISABLE_ICF= ) 1.277 + 1.278 +if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF" -a -z "$DEVELOPER_OPTIONS"; then 1.279 + AC_CACHE_CHECK([whether the linker supports Identical Code Folding], 1.280 + LD_SUPPORTS_ICF, 1.281 + [echo 'int foo() {return 42;}' \ 1.282 + 'int bar() {return 42;}' \ 1.283 + 'int main() {return foo() - bar();}' > conftest.${ac_ext} 1.284 + # If the linker supports ICF, foo and bar symbols will have 1.285 + # the same address 1.286 + if AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS -Wl,--icf=safe -ffunction-sections conftest.${ac_ext} $LIBS 1>&2]) && 1.287 + test -s conftest${ac_exeext} && 1.288 + objdump -t conftest${ac_exeext} | awk changequote(<<, >>)'{a[<<$>>6] = <<$>>1} END {if (a["foo"] && (a["foo"] != a["bar"])) { exit 1 }}'changequote([, ]); then 1.289 + LD_SUPPORTS_ICF=yes 1.290 + else 1.291 + LD_SUPPORTS_ICF=no 1.292 + fi 1.293 + rm -rf conftest*]) 1.294 + if test "$LD_SUPPORTS_ICF" = yes; then 1.295 + _SAVE_LDFLAGS="$LDFLAGS -Wl,--icf=safe" 1.296 + LDFLAGS="$LDFLAGS -Wl,--icf=safe -Wl,--print-icf-sections" 1.297 + AC_TRY_LINK([], [], 1.298 + [LD_PRINT_ICF_SECTIONS=-Wl,--print-icf-sections], 1.299 + [LD_PRINT_ICF_SECTIONS=]) 1.300 + AC_SUBST([LD_PRINT_ICF_SECTIONS]) 1.301 + LDFLAGS="$_SAVE_LDFLAGS" 1.302 + fi 1.303 +fi 1.304 + 1.305 +dnl ======================================================== 1.306 +dnl = Automatically remove dead symbols 1.307 +dnl ======================================================== 1.308 + 1.309 +if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$DEVELOPER_OPTIONS"; then 1.310 + if test -n "$MOZ_DEBUG_FLAGS"; then 1.311 + dnl See bug 670659 1.312 + AC_CACHE_CHECK([whether removing dead symbols breaks debugging], 1.313 + GC_SECTIONS_BREAKS_DEBUG_RANGES, 1.314 + [echo 'int foo() {return 42;}' \ 1.315 + 'int bar() {return 1;}' \ 1.316 + 'int main() {return foo();}' > conftest.${ac_ext} 1.317 + if AC_TRY_COMMAND([${CC-cc} -o conftest.${ac_objext} $CFLAGS $MOZ_DEBUG_FLAGS -c conftest.${ac_ext} 1>&2]) && 1.318 + AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS $MOZ_DEBUG_FLAGS -Wl,--gc-sections conftest.${ac_objext} $LIBS 1>&2]) && 1.319 + test -s conftest${ac_exeext} -a -s conftest.${ac_objext}; then 1.320 + if test "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest.${ac_objext} conftest.${ac_ext}`" = \ 1.321 + "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest${ac_exeext} conftest.${ac_ext}`"; then 1.322 + GC_SECTIONS_BREAKS_DEBUG_RANGES=no 1.323 + else 1.324 + GC_SECTIONS_BREAKS_DEBUG_RANGES=yes 1.325 + fi 1.326 + else 1.327 + dnl We really don't expect to get here, but just in case 1.328 + GC_SECTIONS_BREAKS_DEBUG_RANGES="no, but it's broken in some other way" 1.329 + fi 1.330 + rm -rf conftest*]) 1.331 + if test "$GC_SECTIONS_BREAKS_DEBUG_RANGES" = no; then 1.332 + DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections" 1.333 + fi 1.334 + else 1.335 + DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections" 1.336 + fi 1.337 +fi 1.338 +]) 1.339 + 1.340 +dnl GCC and clang will fail if given an unknown warning option like -Wfoobar. 1.341 +dnl But later versions won't fail if given an unknown negated warning option 1.342 +dnl like -Wno-foobar. So when we are check for support of negated warning 1.343 +dnl options, we actually test the positive form, but add the negated form to 1.344 +dnl the flags variable. 1.345 + 1.346 +AC_DEFUN([MOZ_C_SUPPORTS_WARNING], 1.347 +[ 1.348 + AC_CACHE_CHECK(whether the C compiler supports $1$2, $3, 1.349 + [ 1.350 + AC_LANG_SAVE 1.351 + AC_LANG_C 1.352 + _SAVE_CFLAGS="$CFLAGS" 1.353 + CFLAGS="$CFLAGS -Werror -W$2" 1.354 + AC_TRY_COMPILE([], 1.355 + [return(0);], 1.356 + $3="yes", 1.357 + $3="no") 1.358 + CFLAGS="$_SAVE_CFLAGS" 1.359 + AC_LANG_RESTORE 1.360 + ]) 1.361 + if test "${$3}" = "yes"; then 1.362 + _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} $1$2" 1.363 + fi 1.364 +]) 1.365 + 1.366 +AC_DEFUN([MOZ_CXX_SUPPORTS_WARNING], 1.367 +[ 1.368 + AC_CACHE_CHECK(whether the C++ compiler supports $1$2, $3, 1.369 + [ 1.370 + AC_LANG_SAVE 1.371 + AC_LANG_CPLUSPLUS 1.372 + _SAVE_CXXFLAGS="$CXXFLAGS" 1.373 + CXXFLAGS="$CXXFLAGS -Werror -W$2" 1.374 + AC_TRY_COMPILE([], 1.375 + [return(0);], 1.376 + $3="yes", 1.377 + $3="no") 1.378 + CXXFLAGS="$_SAVE_CXXFLAGS" 1.379 + AC_LANG_RESTORE 1.380 + ]) 1.381 + if test "${$3}" = "yes"; then 1.382 + _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} $1$2" 1.383 + fi 1.384 +])