build/autoconf/toolchain.m4
author Nick Alexander <nalexander@mozilla.com>
Fri, 12 Oct 2018 22:38:44 +0000
changeset 499408 91300d29898b1a1102e1b62164aeee1f56b2ee86
parent 498014 23f384237f7320a5f5ef99f19781feb0227faf7e
child 499412 a06d50af52573db2ac6265ee169fc8039fbf8b04
permissions -rw-r--r--
Bug 1489443 - Set GCC_USE_GNU_LD based on linker kind. r=froydnj The desired outcome of this change is that we'll set `-Wl,--version-script` based on linker kind and not on the output of `$LINKER -v`. This is a cheap way to address a simple problem that has a complicated ideal solution. The underlying issue is that in some situations, when targeting Android, a macOS system `ld` is interrogated to determine if a cross-compiling linker "is GNU ld" and a particular linker feature is set in that situation. The macOS system `ld` doesn't pass the "is GNU ld" test, and the linker feature isn't set; that causes link failures, even though the actual linker has nothing to do with the system `ld`. The ideal solution is to test for linker capabilities dynamically. We do a lot of that in old-configure.in, and we don't do any of that in toolchain.configure. Rather than start testing in toolchain.configure, we hard-code: a cheap solution to the immediate problem. Differential Revision: https://phabricator.services.mozilla.com/D8471

dnl This Source Code Form is subject to the terms of the Mozilla Public
dnl License, v. 2.0. If a copy of the MPL was not distributed with this
dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.

dnl Several autoconf functions AC_REQUIRE AC_PROG_CPP/AC_PROG_CXXCPP
dnl or AC_HEADER_STDC, meaning they are called even when we don't call
dnl them explicitly.
dnl However, theses checks are not necessary and python configure sets
dnl the corresponding variables already, so just skip those tests
dnl entirely.
define([AC_PROG_CPP],[])
define([AC_PROG_CXXCPP],[])
define([AC_HEADER_STDC], [])

AC_DEFUN([MOZ_TOOL_VARIABLES],
[
GNU_CC=
GNU_CXX=
if test "$CC_TYPE" = "gcc"; then
    GNU_CC=1
    GNU_CXX=1
fi

CLANG_CC=
CLANG_CXX=
CLANG_CL=
if test "$CC_TYPE" = "clang"; then
    GNU_CC=1
    GNU_CXX=1
    CLANG_CC=1
    CLANG_CXX=1
fi
if test "$CC_TYPE" = "clang-cl"; then
    CLANG_CL=1
fi

AC_SUBST(CLANG_CXX)
AC_SUBST(CLANG_CL)
])

AC_DEFUN([MOZ_CROSS_COMPILER],
[
echo "cross compiling from $host to $target"

if test -z "$HOST_AR_FLAGS"; then
    HOST_AR_FLAGS="$AR_FLAGS"
fi
AC_CHECK_PROGS(HOST_RANLIB, $HOST_RANLIB ranlib, ranlib, :)
AC_CHECK_PROGS(HOST_AR, $HOST_AR ar, ar, :)

dnl AC_CHECK_PROGS manually goes through $PATH, and as such fails to handle
dnl absolute or relative paths. Relative paths wouldn't work anyways, but
dnl absolute paths would. Trick AC_CHECK_PROGS into working in that case by
dnl adding / to PATH. This is temporary until this moves to moz.configure
dnl (soon).
_SAVE_PATH=$PATH
case "${TOOLCHAIN_PREFIX}" in
/*)
    PATH="/:$PATH"
    ;;
esac
AC_PROG_CC
AC_PROG_CXX

AC_CHECK_PROGS(RANLIB, "${TOOLCHAIN_PREFIX}ranlib", :)
AC_CHECK_PROGS(AR, "${TOOLCHAIN_PREFIX}ar", :)
AC_CHECK_PROGS(AS, "${TOOLCHAIN_PREFIX}as", :)
AC_CHECK_PROGS(LIPO, "${TOOLCHAIN_PREFIX}lipo", :)
AC_CHECK_PROGS(STRIP, "${TOOLCHAIN_PREFIX}strip", :)
AC_CHECK_PROGS(WINDRES, "${TOOLCHAIN_PREFIX}windres", :)
AC_CHECK_PROGS(OTOOL, "${TOOLCHAIN_PREFIX}otool", :)
AC_CHECK_PROGS(INSTALL_NAME_TOOL, "${TOOLCHAIN_PREFIX}install_name_tool", :)
AC_CHECK_PROGS(OBJCOPY, "${TOOLCHAIN_PREFIX}objcopy", :)
PATH=$_SAVE_PATH
])

AC_DEFUN([MOZ_CXX11],
[
dnl Updates to the test below should be duplicated further below for the
dnl cross-compiling case.
AC_LANG_CPLUSPLUS
if test "$GNU_CXX"; then
    AC_CACHE_CHECK([whether 64-bits std::atomic requires -latomic],
        ac_cv_needs_atomic,
        dnl x86 with clang is a little peculiar.  std::atomic does not require
        dnl linking with libatomic, but using atomic intrinsics does, so we
        dnl force the setting on for such systems.
        if test "$CC_TYPE" = "clang" -a "$CPU_ARCH" = "x86" -a "$OS_ARCH" = "Linux"; then
            ac_cv_needs_atomic=yes
        else
            AC_TRY_LINK(
                [#include <cstdint>
                 #include <atomic>],
                [ std::atomic<uint64_t> foo; foo = 1; ],
                ac_cv_needs_atomic=no,
                _SAVE_LIBS="$LIBS"
                LIBS="$LIBS -latomic"
                AC_TRY_LINK(
                    [#include <cstdint>
                     #include <atomic>],
                    [ std::atomic<uint64_t> foo; foo = 1; ],
                    ac_cv_needs_atomic=yes,
                    ac_cv_needs_atomic="do not know; assuming no")
                LIBS="$_SAVE_LIBS"
            )
        fi
    )
    if test "$ac_cv_needs_atomic" = yes; then
      MOZ_NEEDS_LIBATOMIC=1
    else
      MOZ_NEEDS_LIBATOMIC=
    fi
    AC_SUBST(MOZ_NEEDS_LIBATOMIC)
fi
AC_LANG_C
])