michael@0: dnl This Source Code Form is subject to the terms of the Mozilla Public michael@0: dnl License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: dnl file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: dnl Add compiler specific options michael@0: michael@0: AC_DEFUN([MOZ_DEFAULT_COMPILER], michael@0: [ michael@0: dnl set DEVELOPER_OPTIONS early; MOZ_DEFAULT_COMPILER is usually the first non-setup directive michael@0: if test -z "$MOZILLA_OFFICIAL"; then michael@0: DEVELOPER_OPTIONS=1 michael@0: fi michael@0: MOZ_ARG_ENABLE_BOOL(release, michael@0: [ --enable-release Build with more conservative, release engineering-oriented options. michael@0: This may slow down builds.], michael@0: DEVELOPER_OPTIONS=, michael@0: DEVELOPER_OPTIONS=1) michael@0: michael@0: AC_SUBST(DEVELOPER_OPTIONS) michael@0: michael@0: dnl Default to MSVC for win32 and gcc-4.2 for darwin michael@0: dnl ============================================================== michael@0: if test -z "$CROSS_COMPILE"; then michael@0: case "$target" in michael@0: *-mingw*) michael@0: if test -z "$CC"; then CC=cl; fi michael@0: if test -z "$CXX"; then CXX=cl; fi michael@0: if test -z "$CPP"; then CPP="cl -E -nologo"; fi michael@0: if test -z "$CXXCPP"; then CXXCPP="cl -TP -E -nologo"; ac_cv_prog_CXXCPP="$CXXCPP"; fi michael@0: if test -z "$LD"; then LD=link; fi michael@0: if test -z "$AS"; then michael@0: case "${target_cpu}" in michael@0: i*86) michael@0: AS=ml; michael@0: ;; michael@0: x86_64) michael@0: AS=ml64; michael@0: ;; michael@0: esac michael@0: fi michael@0: if test -z "$MIDL"; then MIDL=midl; fi michael@0: michael@0: # need override this flag since we don't use $(LDFLAGS) for this. michael@0: if test -z "$HOST_LDFLAGS" ; then michael@0: HOST_LDFLAGS=" " michael@0: fi michael@0: ;; michael@0: *-darwin*) michael@0: # GCC on darwin is based on gcc 4.2 and we don't support it anymore. michael@0: if test -z "$CC"; then michael@0: MOZ_PATH_PROGS(CC, clang) michael@0: fi michael@0: if test -z "$CXX"; then michael@0: MOZ_PATH_PROGS(CXX, clang++) michael@0: fi michael@0: IS_GCC=$($CC -v 2>&1 | grep gcc) michael@0: if test -n "$IS_GCC" michael@0: then michael@0: echo gcc is known to be broken on OS X, please use clang. michael@0: echo see http://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Mac_OS_X_Prerequisites michael@0: echo for more information. michael@0: exit 1 michael@0: fi michael@0: ;; michael@0: esac michael@0: fi michael@0: ]) michael@0: michael@0: dnl ============================================================================ michael@0: dnl C++ rtti michael@0: dnl We don't use it in the code, but it can be usefull for debugging, so give michael@0: dnl the user the option of enabling it. michael@0: dnl ============================================================================ michael@0: AC_DEFUN([MOZ_RTTI], michael@0: [ michael@0: MOZ_ARG_ENABLE_BOOL(cpp-rtti, michael@0: [ --enable-cpp-rtti Enable C++ RTTI ], michael@0: [ _MOZ_USE_RTTI=1 ], michael@0: [ _MOZ_USE_RTTI= ]) michael@0: michael@0: if test -z "$_MOZ_USE_RTTI"; then michael@0: if test "$GNU_CC"; then michael@0: CXXFLAGS="$CXXFLAGS -fno-rtti" michael@0: else michael@0: case "$target" in michael@0: *-mingw*) michael@0: CXXFLAGS="$CXXFLAGS -GR-" michael@0: esac michael@0: fi michael@0: fi michael@0: ]) michael@0: michael@0: dnl ======================================================== michael@0: dnl = michael@0: dnl = Debugging Options michael@0: dnl = michael@0: dnl ======================================================== michael@0: AC_DEFUN([MOZ_DEBUGGING_OPTS], michael@0: [ michael@0: dnl Debug info is ON by default. michael@0: if test -z "$MOZ_DEBUG_FLAGS"; then michael@0: if test -n "$_MSC_VER"; then michael@0: MOZ_DEBUG_FLAGS="-Zi" michael@0: else michael@0: MOZ_DEBUG_FLAGS="-g" michael@0: fi michael@0: fi michael@0: michael@0: AC_SUBST(MOZ_DEBUG_FLAGS) michael@0: michael@0: MOZ_ARG_ENABLE_STRING(debug, michael@0: [ --enable-debug[=DBG] Enable building with developer debug info michael@0: (using compiler flags DBG)], michael@0: [ if test "$enableval" != "no"; then michael@0: MOZ_DEBUG=1 michael@0: if test -n "$enableval" -a "$enableval" != "yes"; then michael@0: MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'` michael@0: _MOZ_DEBUG_FLAGS_SET=1 michael@0: fi michael@0: else michael@0: MOZ_DEBUG= michael@0: fi ], michael@0: MOZ_DEBUG=) michael@0: michael@0: MOZ_DEBUG_ENABLE_DEFS="-DDEBUG -D_DEBUG -DTRACING" michael@0: MOZ_ARG_WITH_STRING(debug-label, michael@0: [ --with-debug-label=LABELS michael@0: Define DEBUG_ for each comma-separated michael@0: value given.], michael@0: [ for option in `echo $withval | sed 's/,/ /g'`; do michael@0: MOZ_DEBUG_ENABLE_DEFS="$MOZ_DEBUG_ENABLE_DEFS -DDEBUG_${option}" michael@0: done]) michael@0: michael@0: MOZ_DEBUG_DISABLE_DEFS="-DNDEBUG -DTRIMMED" michael@0: michael@0: if test -n "$MOZ_DEBUG"; then michael@0: AC_MSG_CHECKING([for valid debug flags]) michael@0: _SAVE_CFLAGS=$CFLAGS michael@0: CFLAGS="$CFLAGS $MOZ_DEBUG_FLAGS" michael@0: AC_TRY_COMPILE([#include ], michael@0: [printf("Hello World\n");], michael@0: _results=yes, michael@0: _results=no) michael@0: AC_MSG_RESULT([$_results]) michael@0: if test "$_results" = "no"; then michael@0: AC_MSG_ERROR([These compiler flags are invalid: $MOZ_DEBUG_FLAGS]) michael@0: fi michael@0: CFLAGS=$_SAVE_CFLAGS michael@0: fi michael@0: michael@0: dnl ======================================================== michael@0: dnl = Enable generation of debug symbols michael@0: dnl ======================================================== michael@0: MOZ_ARG_ENABLE_STRING(debug-symbols, michael@0: [ --enable-debug-symbols[=DBG] michael@0: Enable debugging symbols (using compiler flags DBG)], michael@0: [ if test "$enableval" != "no"; then michael@0: MOZ_DEBUG_SYMBOLS=1 michael@0: if test -n "$enableval" -a "$enableval" != "yes"; then michael@0: if test -z "$_MOZ_DEBUG_FLAGS_SET"; then michael@0: MOZ_DEBUG_FLAGS=`echo $enableval | sed -e 's|\\\ | |g'` michael@0: else michael@0: AC_MSG_ERROR([--enable-debug-symbols flags cannot be used with --enable-debug flags]) michael@0: fi michael@0: fi michael@0: else michael@0: MOZ_DEBUG_SYMBOLS= michael@0: fi ], michael@0: MOZ_DEBUG_SYMBOLS=1) michael@0: michael@0: if test -n "$MOZ_DEBUG" -o -n "$MOZ_DEBUG_SYMBOLS"; then michael@0: AC_DEFINE(MOZ_DEBUG_SYMBOLS) michael@0: export MOZ_DEBUG_SYMBOLS michael@0: fi michael@0: michael@0: ]) michael@0: michael@0: dnl A high level macro for selecting compiler options. michael@0: AC_DEFUN([MOZ_COMPILER_OPTS], michael@0: [ michael@0: if test "${MOZ_PSEUDO_DERECURSE-unset}" = unset; then michael@0: dnl Don't enable on pymake, because of bug 918652. Bug 912979 is an annoyance michael@0: dnl with pymake, too. michael@0: MOZ_PSEUDO_DERECURSE=no-pymake michael@0: fi michael@0: michael@0: MOZ_DEBUGGING_OPTS michael@0: MOZ_RTTI michael@0: if test "$CLANG_CXX"; then michael@0: ## We disable return-type-c-linkage because jsval is defined as a C++ type but is michael@0: ## returned by C functions. This is possible because we use knowledge about the ABI michael@0: ## to typedef it to a C type with the same layout when the headers are included michael@0: ## from C. michael@0: ## michael@0: ## mismatched-tags is disabled (bug 780474) mostly because it's useless. michael@0: ## Worse, it's not supported by gcc, so it will cause tryserver bustage michael@0: ## without any easy way for non-Clang users to check for it. michael@0: _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-unknown-warning-option -Wno-return-type-c-linkage -Wno-mismatched-tags" michael@0: fi michael@0: michael@0: AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) actually is a C++ compiler]) michael@0: AC_LANG_SAVE michael@0: AC_LANG_CPLUSPLUS michael@0: _SAVE_LIBS=$LIBS michael@0: LIBS= michael@0: AC_TRY_LINK([#include ], [int *foo = new int;],, michael@0: AC_MSG_RESULT([no]) michael@0: AC_MSG_ERROR([$CXX $CXXFLAGS $LDFLAGS failed to compile and link a simple C++ source.])) michael@0: LIBS=$_SAVE_LIBS michael@0: AC_LANG_RESTORE michael@0: AC_MSG_RESULT([yes]) michael@0: michael@0: if test -z "$GNU_CC"; then michael@0: case "$target" in michael@0: *-mingw*) michael@0: ## Warning 4099 (equivalent of mismatched-tags) is disabled (bug 780474) michael@0: ## for the same reasons as above. michael@0: _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -wd4099" michael@0: esac michael@0: fi michael@0: michael@0: if test -n "$DEVELOPER_OPTIONS"; then michael@0: MOZ_FORCE_GOLD=1 michael@0: fi michael@0: michael@0: MOZ_ARG_ENABLE_BOOL(gold, michael@0: [ --enable-gold Enable GNU Gold Linker when it is not already the default], michael@0: MOZ_FORCE_GOLD=1, michael@0: MOZ_FORCE_GOLD= michael@0: ) michael@0: michael@0: if test "$GNU_CC" -a -n "$MOZ_FORCE_GOLD"; then michael@0: dnl if the default linker is BFD ld, check if gold is available and try to use it michael@0: dnl for local builds only. michael@0: if $CC -Wl,--version 2>&1 | grep -q "GNU ld"; then michael@0: GOLD=$($CC -print-prog-name=ld.gold) michael@0: case "$GOLD" in michael@0: /*) michael@0: ;; michael@0: *) michael@0: GOLD=$(which $GOLD) michael@0: ;; michael@0: esac michael@0: if test -n "$GOLD"; then michael@0: mkdir -p $_objdir/build/unix/gold michael@0: rm -f $_objdir/build/unix/gold/ld michael@0: ln -s "$GOLD" $_objdir/build/unix/gold/ld michael@0: if $CC -B $_objdir/build/unix/gold -Wl,--version 2>&1 | grep -q "GNU gold"; then michael@0: LDFLAGS="$LDFLAGS -B $_objdir/build/unix/gold" michael@0: else michael@0: rm -rf $_objdir/build/unix/gold michael@0: fi michael@0: fi michael@0: fi michael@0: fi michael@0: michael@0: if test "$GNU_CC"; then michael@0: if test -z "$DEVELOPER_OPTIONS"; then michael@0: CFLAGS="$CFLAGS -ffunction-sections -fdata-sections" michael@0: CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections" michael@0: fi michael@0: CFLAGS="$CFLAGS -fno-math-errno" michael@0: CXXFLAGS="$CXXFLAGS -fno-exceptions -fno-math-errno" michael@0: fi michael@0: michael@0: dnl ======================================================== michael@0: dnl = Identical Code Folding michael@0: dnl ======================================================== michael@0: michael@0: MOZ_ARG_DISABLE_BOOL(icf, michael@0: [ --disable-icf Disable Identical Code Folding], michael@0: MOZ_DISABLE_ICF=1, michael@0: MOZ_DISABLE_ICF= ) michael@0: michael@0: if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$MOZ_DISABLE_ICF" -a -z "$DEVELOPER_OPTIONS"; then michael@0: AC_CACHE_CHECK([whether the linker supports Identical Code Folding], michael@0: LD_SUPPORTS_ICF, michael@0: [echo 'int foo() {return 42;}' \ michael@0: 'int bar() {return 42;}' \ michael@0: 'int main() {return foo() - bar();}' > conftest.${ac_ext} michael@0: # If the linker supports ICF, foo and bar symbols will have michael@0: # the same address michael@0: if AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS -Wl,--icf=safe -ffunction-sections conftest.${ac_ext} $LIBS 1>&2]) && michael@0: test -s conftest${ac_exeext} && michael@0: objdump -t conftest${ac_exeext} | awk changequote(<<, >>)'{a[<<$>>6] = <<$>>1} END {if (a["foo"] && (a["foo"] != a["bar"])) { exit 1 }}'changequote([, ]); then michael@0: LD_SUPPORTS_ICF=yes michael@0: else michael@0: LD_SUPPORTS_ICF=no michael@0: fi michael@0: rm -rf conftest*]) michael@0: if test "$LD_SUPPORTS_ICF" = yes; then michael@0: _SAVE_LDFLAGS="$LDFLAGS -Wl,--icf=safe" michael@0: LDFLAGS="$LDFLAGS -Wl,--icf=safe -Wl,--print-icf-sections" michael@0: AC_TRY_LINK([], [], michael@0: [LD_PRINT_ICF_SECTIONS=-Wl,--print-icf-sections], michael@0: [LD_PRINT_ICF_SECTIONS=]) michael@0: AC_SUBST([LD_PRINT_ICF_SECTIONS]) michael@0: LDFLAGS="$_SAVE_LDFLAGS" michael@0: fi michael@0: fi michael@0: michael@0: dnl ======================================================== michael@0: dnl = Automatically remove dead symbols michael@0: dnl ======================================================== michael@0: michael@0: if test "$GNU_CC" -a "$GCC_USE_GNU_LD" -a -z "$DEVELOPER_OPTIONS"; then michael@0: if test -n "$MOZ_DEBUG_FLAGS"; then michael@0: dnl See bug 670659 michael@0: AC_CACHE_CHECK([whether removing dead symbols breaks debugging], michael@0: GC_SECTIONS_BREAKS_DEBUG_RANGES, michael@0: [echo 'int foo() {return 42;}' \ michael@0: 'int bar() {return 1;}' \ michael@0: 'int main() {return foo();}' > conftest.${ac_ext} michael@0: if AC_TRY_COMMAND([${CC-cc} -o conftest.${ac_objext} $CFLAGS $MOZ_DEBUG_FLAGS -c conftest.${ac_ext} 1>&2]) && michael@0: AC_TRY_COMMAND([${CC-cc} -o conftest${ac_exeext} $LDFLAGS $MOZ_DEBUG_FLAGS -Wl,--gc-sections conftest.${ac_objext} $LIBS 1>&2]) && michael@0: test -s conftest${ac_exeext} -a -s conftest.${ac_objext}; then michael@0: if test "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest.${ac_objext} conftest.${ac_ext}`" = \ michael@0: "`$PYTHON -m mozbuild.configure.check_debug_ranges conftest${ac_exeext} conftest.${ac_ext}`"; then michael@0: GC_SECTIONS_BREAKS_DEBUG_RANGES=no michael@0: else michael@0: GC_SECTIONS_BREAKS_DEBUG_RANGES=yes michael@0: fi michael@0: else michael@0: dnl We really don't expect to get here, but just in case michael@0: GC_SECTIONS_BREAKS_DEBUG_RANGES="no, but it's broken in some other way" michael@0: fi michael@0: rm -rf conftest*]) michael@0: if test "$GC_SECTIONS_BREAKS_DEBUG_RANGES" = no; then michael@0: DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections" michael@0: fi michael@0: else michael@0: DSO_LDOPTS="$DSO_LDOPTS -Wl,--gc-sections" michael@0: fi michael@0: fi michael@0: ]) michael@0: michael@0: dnl GCC and clang will fail if given an unknown warning option like -Wfoobar. michael@0: dnl But later versions won't fail if given an unknown negated warning option michael@0: dnl like -Wno-foobar. So when we are check for support of negated warning michael@0: dnl options, we actually test the positive form, but add the negated form to michael@0: dnl the flags variable. michael@0: michael@0: AC_DEFUN([MOZ_C_SUPPORTS_WARNING], michael@0: [ michael@0: AC_CACHE_CHECK(whether the C compiler supports $1$2, $3, michael@0: [ michael@0: AC_LANG_SAVE michael@0: AC_LANG_C michael@0: _SAVE_CFLAGS="$CFLAGS" michael@0: CFLAGS="$CFLAGS -Werror -W$2" michael@0: AC_TRY_COMPILE([], michael@0: [return(0);], michael@0: $3="yes", michael@0: $3="no") michael@0: CFLAGS="$_SAVE_CFLAGS" michael@0: AC_LANG_RESTORE michael@0: ]) michael@0: if test "${$3}" = "yes"; then michael@0: _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} $1$2" michael@0: fi michael@0: ]) michael@0: michael@0: AC_DEFUN([MOZ_CXX_SUPPORTS_WARNING], michael@0: [ michael@0: AC_CACHE_CHECK(whether the C++ compiler supports $1$2, $3, michael@0: [ michael@0: AC_LANG_SAVE michael@0: AC_LANG_CPLUSPLUS michael@0: _SAVE_CXXFLAGS="$CXXFLAGS" michael@0: CXXFLAGS="$CXXFLAGS -Werror -W$2" michael@0: AC_TRY_COMPILE([], michael@0: [return(0);], michael@0: $3="yes", michael@0: $3="no") michael@0: CXXFLAGS="$_SAVE_CXXFLAGS" michael@0: AC_LANG_RESTORE michael@0: ]) michael@0: if test "${$3}" = "yes"; then michael@0: _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} $1$2" michael@0: fi michael@0: ])