Bug 1260647 - Unify cross-compilation setup, while moving some of it to moz.configure. r=ted
authorMike Hommey <mh+mozilla@glandium.org>
Wed, 30 Mar 2016 14:47:13 +0900
changeset 291159 0f5f41c619be9ede89c093a7b465ea45e2c6aa21
parent 291158 2e966a1f371c9d2e4bd376202e79ea70b13d800c
child 291160 01b372afc3fc2d0bcd7aceede1c4f9b3c0180d01
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1260647
milestone48.0a1
Bug 1260647 - Unify cross-compilation setup, while moving some of it to moz.configure. r=ted Gonk, Android, and the generic cross-compilation setup all were using a different yet similar way to prefix the toolchain. The latter was even wrong, since the target and target alias usually don't match actual toolchain prefixes (which don't include the machine part of the target).
b2g/moz.configure
build/autoconf/android.m4
build/autoconf/toolchain.m4
build/macosx/cross-mozconfig.common
build/moz.configure/init.configure
build/moz.configure/old.configure
build/moz.configure/toolchain.configure
js/src/old-configure.in
old-configure.in
--- a/b2g/moz.configure
+++ b/b2g/moz.configure
@@ -6,9 +6,19 @@
 
 option('--with-gonk', nargs=1, help='Path to the gonk base directory')
 
 @depends('--with-gonk')
 def gonkdir(value):
     return value[0] if value else ''
 
 
+option('--with-gonk-toolchain-prefix', nargs=1,
+       help='Prefix to gonk toolchain commands')
+
+@depends_if('--with-gonk-toolchain-prefix')
+def gonk_toolchain_prefix(value):
+    return value
+
+imply_option('--with-toolchain-prefix', gonk_toolchain_prefix)
+
+
 include('common.configure')
--- a/build/autoconf/android.m4
+++ b/build/autoconf/android.m4
@@ -128,33 +128,17 @@ case "$target" in
     android_platform="$android_ndk"/platforms/android-"$android_version"/arch-"$target_name"
 
     if test -d "$android_platform" ; then
         AC_MSG_RESULT([$android_platform])
     else
         AC_MSG_ERROR([not found. Please check your NDK. With the current configuration, it should be in $android_platform])
     fi
 
-    dnl set up compilers
     TOOLCHAIN_PREFIX="$android_toolchain/bin/$android_tool_prefix-"
-    AS="$android_toolchain"/bin/"$android_tool_prefix"-as
-    if test -z "$CC"; then
-        CC="$android_toolchain"/bin/"$android_tool_prefix"-gcc
-    fi
-    if test -z "$CXX"; then
-        CXX="$android_toolchain"/bin/"$android_tool_prefix"-g++
-    fi
-    if test -z "$CPP"; then
-        CPP="$android_toolchain"/bin/"$android_tool_prefix"-cpp
-    fi
-    LD="$android_toolchain"/bin/"$android_tool_prefix"-ld
-    AR="$android_toolchain"/bin/"$android_tool_prefix"-ar
-    RANLIB="$android_toolchain"/bin/"$android_tool_prefix"-ranlib
-    STRIP="$android_toolchain"/bin/"$android_tool_prefix"-strip
-    OBJCOPY="$android_toolchain"/bin/"$android_tool_prefix"-objcopy
 
     CPPFLAGS="-idirafter $android_platform/usr/include $CPPFLAGS"
     CFLAGS="-mandroid -fno-short-enums -fno-exceptions $CFLAGS"
     CXXFLAGS="-mandroid -fno-short-enums -fno-exceptions $CXXFLAGS"
     ASFLAGS="-idirafter $android_platform/usr/include -DANDROID $ASFLAGS"
 
     dnl Add -llog by default, since we use it all over the place.
     dnl Add --allow-shlib-undefined, because libGLESv2 links to an
--- a/build/autoconf/toolchain.m4
+++ b/build/autoconf/toolchain.m4
@@ -164,30 +164,43 @@ AC_MSG_CHECKING([whether the host c++ co
 AC_TRY_COMPILE([], [return(0);],
     [ac_cv_prog_hostcxx_works=1 AC_MSG_RESULT([yes])],
     AC_MSG_ERROR([installation or configuration problem: host compiler $HOST_CXX cannot create executables.]) )
 
 CC=$_SAVE_CC
 CFLAGS=$_SAVE_CFLAGS
 LDFLAGS=$_SAVE_LDFLAGS
 
-AC_CHECK_PROGS(CC, "${target_alias}-gcc" "${target}-gcc", :)
+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_CHECK_PROGS(CC, "${TOOLCHAIN_PREFIX}gcc", :)
 unset ac_cv_prog_CC
 AC_PROG_CC
-AC_CHECK_PROGS(CXX, "${target_alias}-g++" "${target}-g++", :)
+AC_CHECK_PROGS(CXX, "${TOOLCHAIN_PREFIX}g++", :)
 unset ac_cv_prog_CXX
 AC_PROG_CXX
 
-AC_CHECK_PROGS(RANLIB, "${target_alias}-ranlib" "${target}-ranlib", :)
-AC_CHECK_PROGS(AR, "${target_alias}-ar" "${target}-ar", :)
-AC_CHECK_PROGS(AS, "${target_alias}-as" "${target}-as", :)
-AC_CHECK_PROGS(LD, "${target_alias}-ld" "${target}-ld", :)
-AC_CHECK_PROGS(STRIP, "${target_alias}-strip" "${target}-strip", :)
-AC_CHECK_PROGS(WINDRES, "${target_alias}-windres" "${target}-windres", :)
-AC_CHECK_PROGS(OTOOL, "${target_alias}-otool" "${target}-otool", :)
+AC_CHECK_PROGS(RANLIB, "${TOOLCHAIN_PREFIX}ranlib", :)
+AC_CHECK_PROGS(AR, "${TOOLCHAIN_PREFIX}ar", :)
+AC_CHECK_PROGS(AS, "${TOOLCHAIN_PREFIX}as", :)
+AC_CHECK_PROGS(LD, "${TOOLCHAIN_PREFIX}ld", :)
+AC_CHECK_PROGS(STRIP, "${TOOLCHAIN_PREFIX}strip", :)
+AC_CHECK_PROGS(WINDRES, "${TOOLCHAIN_PREFIX}windres", :)
+AC_CHECK_PROGS(OTOOL, "${TOOLCHAIN_PREFIX}otool", :)
+AC_CHECK_PROGS(OBJCOPY, "${TOOLCHAIN_PREFIX}objcopy", :)
+PATH=$_SAVE_PATH
 ])
 
 AC_DEFUN([MOZ_CXX11],
 [
 dnl Check whether gcc's c++0x mode works
 dnl Updates to the test below should be duplicated further below for the
 dnl cross-compiling case.
 AC_LANG_CPLUSPLUS
--- a/build/macosx/cross-mozconfig.common
+++ b/build/macosx/cross-mozconfig.common
@@ -20,21 +20,16 @@ CROSS_PRIVATE_FRAMEWORKS=$CROSS_SYSROOT/
 FLAGS="-target x86_64-apple-darwin10 -mlinker-version=136 -B $CROSS_CCTOOLS_PATH/bin -isysroot $CROSS_SYSROOT"
 
 export CC="$topsrcdir/clang/bin/clang $FLAGS"
 export CXX="$topsrcdir/clang/bin/clang++ $FLAGS"
 export CPP="$topsrcdir/clang/bin/clang $FLAGS -E"
 export LLVMCONFIG=$topsrcdir/clang/bin/llvm-config
 export LDFLAGS="-Wl,-syslibroot,$CROSS_SYSROOT -Wl,-dead_strip"
 export TOOLCHAIN_PREFIX=$CROSS_CCTOOLS_PATH/bin/x86_64-apple-darwin10-
-#TODO: bug 1184202 - would be nice if these could be detected with TOOLCHAIN_PREFIX automatically
-export AR=${TOOLCHAIN_PREFIX}ar
-export RANLIB=${TOOLCHAIN_PREFIX}ranlib
-export STRIP=${TOOLCHAIN_PREFIX}strip
-export OTOOL=${TOOLCHAIN_PREFIX}otool
 export DSYMUTIL=$topsrcdir/clang/bin/llvm-dsymutil
 export GENISOIMAGE=$topsrcdir/genisoimage/genisoimage
 export DMG_TOOL=$topsrcdir/dmg/dmg
 
 export HOST_CC="$topsrcdir/clang/bin/clang"
 export HOST_CXX="$topsrcdir/clang/bin/clang++"
 export HOST_CPP="$topsrcdir/clang/bin/clang -E"
 export HOST_CFLAGS="-g"
--- a/build/moz.configure/init.configure
+++ b/build/moz.configure/init.configure
@@ -284,16 +284,17 @@ def wanted_mozconfig_variables(help):
          'MOZ_JPROF',
          'MOZ_PROFILING',
          'MOZ_USE_SYSTRACE',
          'MOZ_VTUNE',
          'MOZTTDIR',
          'PERL',
          'RPMBUILD',
          'TAR',
+         'TOOLCHAIN_PREFIX',
          'UNZIP',
          'USE_FC_FREETYPE',
          'WITHOUT_X',
          'XARGS',
          'YASM',
          'ZIP',
      ])
 
@@ -451,16 +452,19 @@ def split_triplet(triplet):
     return namespace(
         alias=triplet,
         cpu=canonical_cpu,
         kernel=canonical_kernel,
         os=canonical_os,
         endianness=endianness,
         raw_cpu=cpu,
         raw_os=os,
+        # Toolchains, most notably for cross compilation may use cpu-os
+        # prefixes.
+        toolchain='%s-%s' % (cpu, os),
     )
 
 
 @imports('subprocess')
 def config_sub(shell, triplet):
     config_sub = os.path.join(os.path.dirname(__file__), '..',
                               'autoconf', 'config.sub')
     return subprocess.check_output([shell, config_sub, triplet]).strip()
@@ -712,17 +716,18 @@ add_old_configure_assignment('NIGHTLY_BU
                              delayed_getattr(milestone, 'is_nightly'))
 set_config('RELEASE_BUILD', delayed_getattr(milestone, 'is_release'))
 set_define('RELEASE_BUILD', delayed_getattr(milestone, 'is_release'))
 add_old_configure_assignment('RELEASE_BUILD',
                              delayed_getattr(milestone, 'is_release'))
 
 
 # This is temporary until js/src/configure and configure are merged.
-# Use instead of option() in js/moz.configure
+# Use instead of option() in js/moz.configure and more generally, for
+# options that are shared between configure and js/src/configure.
 @template
 def js_option(*args, **kwargs):
     opt = option(*args, **kwargs)
 
     @depends(opt.option, build_project)
     def js_option(value, build_project):
         if build_project != 'js':
             return value.format(opt.option)
--- a/build/moz.configure/old.configure
+++ b/build/moz.configure/old.configure
@@ -320,17 +320,16 @@ def old_configure_options(*options):
     '--with-debug-label',
     '--with-default-mozilla-five-home',
     '--with-distribution-id',
     '--with-doc-include-dirs',
     '--with-doc-input-dirs',
     '--with-doc-output-dir',
     '--with-float-abi',
     '--with-fpu',
-    '--with-gonk-toolchain-prefix',
     '--with-google-api-keyfile',
     '--with-google-oauth-api-keyfile',
     '--with-intl-api',
     '--with-ios-sdk',
     '--with-java-bin-path',
     '--with-jitreport-granularity',
     '--with-linux-headers',
     '--with-macbundlename-prefix',
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -96,8 +96,27 @@ def compiler_wrapper(wrapper, ccache):
 
 add_old_configure_assignment('COMPILER_WRAPPER', compiler_wrapper)
 
 @depends_if(compiler_wrapper)
 def using_compiler_wrapper(compiler_wrapper):
     return True
 
 set_config('MOZ_USING_COMPILER_WRAPPER', using_compiler_wrapper)
+
+
+# Cross-compilation related things.
+# ==============================================================
+js_option('--with-toolchain-prefix', env='TOOLCHAIN_PREFIX', nargs=1,
+          help='Prefix for the target toolchain')
+
+@depends('--with-toolchain-prefix', target, host, cross_compiling)
+def toolchain_prefix(value, target, host, cross_compiling):
+    if value:
+        return value[0]
+    # Special case x86-64 <-> x86 cross compiling until we have the right tests
+    # in moz.configure land.
+    if cross_compiling and not all(i.cpu in ('x86_64', 'x86')
+                                   for i in (target, host)):
+        return '%s-' % target.toolchain
+    return ''
+
+add_old_configure_assignment('TOOLCHAIN_PREFIX', toolchain_prefix)
--- a/js/src/old-configure.in
+++ b/js/src/old-configure.in
@@ -78,40 +78,24 @@ MOZ_DEFAULT_COMPILER
 if test -z "$JS_STANDALONE"; then
   autoconfmk=autoconf-js.mk
   #DIST is exported from top-level configure
 else
   DIST="$MOZ_BUILD_ROOT/dist"
 fi
 AC_SUBST(autoconfmk)
 
-MOZ_ARG_WITH_STRING(gonk-toolchain-prefix,
-[  --with-gonk-toolchain-prefix=DIR
-                          prefix to gonk toolchain commands],
-    gonk_toolchain_prefix=$withval)
-
 if test -n "$gonkdir" ; then
     kernel_name=`uname -s | tr "[[:upper:]]" "[[:lower:]]"`
     dnl Default to ICS
     ANDROID_VERSION=15
     if test -n "${PLATFORM_SDK_VERSION}"; then
         ANDROID_VERSION="${PLATFORM_SDK_VERSION}"
     fi
 
-    dnl set up compilers
-    AS="$gonk_toolchain_prefix"as
-    CC="$gonk_toolchain_prefix"gcc
-    CXX="$gonk_toolchain_prefix"g++
-    CPP="$gonk_toolchain_prefix"cpp
-    LD="$gonk_toolchain_prefix"ld
-    AR="$gonk_toolchain_prefix"ar
-    RANLIB="$gonk_toolchain_prefix"ranlib
-    STRIP="$gonk_toolchain_prefix"strip
-    OBJCOPY="$gonk_toolchain_prefix"objcopy
-
     STLPORT_CPPFLAGS="-I$_topsrcdir/build/stlport/stlport -I$gonkdir/ndk/sources/cxx-stl/system/include"
     STLPORT_LIBS="-lstlport"
 
     CPPFLAGS="-DANDROID $TARGET_C_INCLUDES -I$gonkdir/frameworks/base/native/include -I$gonkdir/system/core/include -isystem $gonkdir/bionic $CPPFLAGS -I$gonkdir/external/valgrind/fxos-include"
     CFLAGS="-mandroid -fno-short-enums -fno-exceptions $CFLAGS"
     CXXFLAGS="-mandroid -fno-short-enums -fno-exceptions $CXXFLAGS $STLPORT_CPPFLAGS"
     LIBS="$LIBS $STLPORT_LIBS"
 
--- a/old-configure.in
+++ b/old-configure.in
@@ -91,47 +91,30 @@ dnl ====================================
 _topsrcdir=`cd \`dirname $0\`; pwd -W 2>/dev/null || pwd -P`
 _objdir=`pwd -P`
 
 MOZ_BUILD_ROOT=`pwd -W 2>/dev/null || pwd -P`
 DIST="$MOZ_BUILD_ROOT/dist"
 
 MOZ_DEFAULT_COMPILER
 
-MOZ_ARG_WITH_STRING(gonk-toolchain-prefix,
-[  --with-gonk-toolchain-prefix=DIR
-                          prefix to gonk toolchain commands],
-    gonk_toolchain_prefix=$withval)
-
 if test -n "$gonkdir" ; then
     dnl export for js/src/configure. We can't pass the option down normally,
     dnl because it's a `--enable-project=b2g`-only option.
     export gonkdir
     kernel_name=`uname -s | tr "[[:upper:]]" "[[:lower:]]"`
     android_source="$gonkdir"
     ANDROID_SOURCE="$android_source"
     ANDROID_NDK="${ANDROID_SOURCE}/ndk"
     dnl Default to ICS
     ANDROID_VERSION=15
     if test -n "${PLATFORM_SDK_VERSION}"; then
         ANDROID_VERSION="${PLATFORM_SDK_VERSION}"
     fi
 
-    dnl set up compilers
-    TOOLCHAIN_PREFIX="$gonk_toolchain_prefix"
-    AS="$gonk_toolchain_prefix"as
-    CC="$gonk_toolchain_prefix"gcc
-    CXX="$gonk_toolchain_prefix"g++
-    CPP="$gonk_toolchain_prefix"cpp
-    LD="$gonk_toolchain_prefix"ld
-    AR="$gonk_toolchain_prefix"ar
-    RANLIB="$gonk_toolchain_prefix"ranlib
-    STRIP="$gonk_toolchain_prefix"strip
-    OBJCOPY="$gonk_toolchain_prefix"objcopy
-
     if ! test -e "$gonkdir/ndk/sources/cxx-stl/stlport/src/iostream.cpp"; then
         AC_MSG_ERROR([Couldn't find path to stlport sources in the gonk tree])
     fi
     STLPORT_CPPFLAGS="-I$_topsrcdir/build/stlport/stlport -I$gonkdir/ndk/sources/cxx-stl/system/include"
 
     case "$ANDROID_VERSION" in
     15)
         GONK_INCLUDES="-I$gonkdir/frameworks/base/opengl/include -I$gonkdir/frameworks/base/native/include -I$gonkdir/frameworks/base/include -I$gonkdir/frameworks/base/services/camera -I$gonkdir/frameworks/base/include/media/ -I$gonkdir/frameworks/base/include/media/stagefright -I$gonkdir/frameworks/base/include/media/stagefright/openmax -I$gonkdir/frameworks/base/media/libstagefright/rtsp -I$gonkdir/frameworks/base/media/libstagefright/include -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib -I$gonkdir/dalvik/libnativehelper/include/nativehelper"