Merge "Update changelog"
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 983b74f..cc52371 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -118,24 +118,5 @@
    cause is incompatibility between the LLVM unwinder used by libc++abi for
    ARM32 and libgcc. This is not a regression from r10e.
 
-What's Next?
-------------
-
-A significant proportion of the changes that went into this release were
-organizational changes to the build and to the package layout. The reason for
-this is that we will soon be integrating the NDK into the Android SDK manager as
-several distinct components. The motivations for this change are:
-
- * No wasted bandwidth or disk space on unneeded pieces. Do you really need 14
-   compilers? With the modular NDK you can download just the one Clang, or a
-   single set of GCCs.
- * Easier updating. Just launch the SDK manager and install the updates rather
-   than downloading an entire new NDK.
- * Quicker updates. In the future we’ll be able to release just a portion of the
-   NDK on a quicker schedule. No more waiting for the next big release for a
-   handful of bug fixes or a compiler update.
-
-The integration with the SDK manager should happen Soon™.
-
 [GitHub]: https://github.com/googlesamples/android-ndk
 [Android Developer website]: http://developer.android.com/ndk/index.html
diff --git a/build/core/definitions.mk b/build/core/definitions.mk
index 99a5eb1..9e7d36d 100644
--- a/build/core/definitions.mk
+++ b/build/core/definitions.mk
@@ -2065,7 +2065,7 @@
 $(call ndk-stl-register,\
     c++_static,\
     cxx-stl/llvm-libc++,\
-    c++_static,\
+    c++_static libc++abi libunwind android_support,\
     ,\
     -ldl\
     )
@@ -2075,7 +2075,7 @@
 $(call ndk-stl-register,\
     c++_shared,\
     cxx-stl/llvm-libc++,\
-    ,\
+    libunwind,\
     c++_shared,\
     \
     )
diff --git a/build/core/init.mk b/build/core/init.mk
index f6daa3f..cec6b03 100644
--- a/build/core/init.mk
+++ b/build/core/init.mk
@@ -103,18 +103,22 @@
 # -----------------------------------------------------------------------------
 # Function : host-toolchain-path
 # Arguments: 1: NDK root
+#            2: Toolchain name
 # Returns  : The parent path of all toolchains for this host. Note that
 #            HOST_TAG64 == HOST_TAG for 32-bit systems.
 # -----------------------------------------------------------------------------
-host-toolchain-path = $1/prebuilt/$(HOST_TAG64)
+ifeq ($(NDK_NEW_TOOLCHAINS_LAYOUT),true)
+    host-toolchain-path = $1/$(HOST_TAG64)/$2
+else
+    host-toolchain-path = $1/$2/prebuilt/$(HOST_TAG64)
+endif
 
 # -----------------------------------------------------------------------------
 # Function : get-toolchain-root
-# Arguments: 1: NDK root
-#            2: Toolchain name
+# Arguments: 1: Toolchain name
 # Returns  : Path to the given prebuilt toolchain.
 # -----------------------------------------------------------------------------
-get-toolchain-root = $(call host-toolchain-path,$1/toolchains/$2)
+get-toolchain-root = $(call host-toolchain-path,$(NDK_TOOLCHAINS_ROOT),$1)
 
 # -----------------------------------------------------------------------------
 # Function : get-binutils-root
@@ -510,6 +514,15 @@
 
 $(call ndk_log,Found max platform level: $(NDK_MAX_PLATFORM_LEVEL))
 
+# Allow the user to point at an alternate location for the toolchains. This is
+# particularly helpful if we want to use prebuilt toolchains for building an NDK
+# module. Specifically, we use this to build libc++ using ndk-build instead of
+# the old build-cxx-stl.sh and maintaining two sets of build rules.
+NDK_TOOLCHAINS_ROOT := $(strip $(NDK_TOOLCHAINS_ROOT))
+ifndef NDK_TOOLCHAINS_ROOT
+    NDK_TOOLCHAINS_ROOT := $(strip $(NDK_ROOT)/toolchains)
+endif
+
 # ====================================================================
 #
 # Read all toolchain-specific configuration files.
diff --git a/build/core/setup-app.mk b/build/core/setup-app.mk
index f28f297..bf9dc6f 100644
--- a/build/core/setup-app.mk
+++ b/build/core/setup-app.mk
@@ -136,7 +136,7 @@
 
 # Renderscript
 
-RENDERSCRIPT_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),renderscript)
+RENDERSCRIPT_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,renderscript)
 RENDERSCRIPT_TOOLCHAIN_PREFIX := $(RENDERSCRIPT_TOOLCHAIN_PREBUILT_ROOT)/bin/
 RENDERSCRIPT_TOOLCHAIN_HEADER := $(RENDERSCRIPT_TOOLCHAIN_PREBUILT_ROOT)/lib/clang/3.5/include
 
diff --git a/build/core/setup-toolchain.mk b/build/core/setup-toolchain.mk
index ca5a3cd..ce54072 100644
--- a/build/core/setup-toolchain.mk
+++ b/build/core/setup-toolchain.mk
@@ -132,7 +132,7 @@
 TOOLCHAIN_VERSION := $(call last,$(subst -,$(space),$(TARGET_TOOLCHAIN)))
 
 # Define the root path where toolchain prebuilts are stored
-TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
+TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(TOOLCHAIN_NAME))
 
 # Do the same for TOOLCHAIN_PREFIX. Note that we must chop the version
 # number from the toolchain name, e.g. arm-eabi-4.4.0 -> path/bin/arm-eabi-
diff --git a/build/core/toolchains/aarch64-linux-android-clang3.6/setup.mk b/build/core/toolchains/aarch64-linux-android-clang3.6/setup.mk
index 42d0d1d..30f30d8 100644
--- a/build/core/toolchains/aarch64-linux-android-clang3.6/setup.mk
+++ b/build/core/toolchains/aarch64-linux-android-clang3.6/setup.mk
@@ -27,12 +27,13 @@
 # Override the toolchain prefix
 #
 
-LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),llvm)
+LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,llvm)
 LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
 
 TOOLCHAIN_NAME := aarch64-linux-android
 BINUTILS_ROOT := $(call get-binutils-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
-TOOLCHAIN_PREFIX := $(BINUTILS_ROOT)/bin/$(TOOLCHAIN_NAME)-
+TOOLCHAIN_ROOT := $(call get-toolchain-root,$(TOOLCHAIN_NAME)-4.9)
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_ROOT)/bin/$(TOOLCHAIN_NAME)-
 
 TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
 TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
@@ -40,7 +41,7 @@
 LLVM_TRIPLE := aarch64-none-linux-android
 
 TARGET_CFLAGS := \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -ffunction-sections \
     -funwind-tables \
@@ -51,8 +52,7 @@
     -no-canonical-prefixes
 
 TARGET_LDFLAGS += \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
-    -L $(call get-gcclibs-path,$(NDK_ROOT),$(TOOLCHAIN_NAME)) \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -no-canonical-prefixes
 
diff --git a/build/core/toolchains/arm-linux-androideabi-clang3.6/setup.mk b/build/core/toolchains/arm-linux-androideabi-clang3.6/setup.mk
index 7945576..850f992 100644
--- a/build/core/toolchains/arm-linux-androideabi-clang3.6/setup.mk
+++ b/build/core/toolchains/arm-linux-androideabi-clang3.6/setup.mk
@@ -27,12 +27,13 @@
 # Override the toolchain prefix
 #
 
-LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),llvm)
+LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,llvm)
 LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
 
 TOOLCHAIN_NAME := arm-linux-androideabi
 BINUTILS_ROOT := $(call get-binutils-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
-TOOLCHAIN_PREFIX := $(BINUTILS_ROOT)/bin/$(TOOLCHAIN_NAME)-
+TOOLCHAIN_ROOT := $(call get-toolchain-root,$(TOOLCHAIN_NAME)-4.9)
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_ROOT)/bin/$(TOOLCHAIN_NAME)-
 
 TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
 TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
@@ -42,7 +43,7 @@
 #
 
 TARGET_CFLAGS := \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -fpic \
     -ffunction-sections \
     -funwind-tables \
@@ -56,7 +57,7 @@
     -fno-integrated-as
 
 TARGET_LDFLAGS += \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -no-canonical-prefixes
 
 ifneq ($(filter %armeabi-v7a,$(TARGET_ARCH_ABI)),)
@@ -102,8 +103,6 @@
 endif
 
 GCCLIB_ROOT := $(call get-gcclibs-path,$(NDK_ROOT),$(TOOLCHAIN_NAME))
-TARGET_arm_LDFLAGS += -L $(GCCLIB_ROOT)/$(GCCLIB_SUBDIR)
-TARGET_thumb_LDFLAGS += -L $(GCCLIB_ROOT)/$(GCCLIB_SUBDIR)/thumb
 
 TARGET_CFLAGS.neon := -mfpu=neon
 
diff --git a/build/core/toolchains/mips64el-linux-android-clang3.6/setup.mk b/build/core/toolchains/mips64el-linux-android-clang3.6/setup.mk
index 66518ce..d16bf43 100644
--- a/build/core/toolchains/mips64el-linux-android-clang3.6/setup.mk
+++ b/build/core/toolchains/mips64el-linux-android-clang3.6/setup.mk
@@ -27,12 +27,13 @@
 # Override the toolchain prefix
 #
 
-LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),llvm)
+LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,llvm)
 LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
 
 TOOLCHAIN_NAME := mips64el-linux-android
 BINUTILS_ROOT := $(call get-binutils-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
-TOOLCHAIN_PREFIX := $(BINUTILS_ROOT)/bin/$(TOOLCHAIN_NAME)-
+TOOLCHAIN_ROOT := $(call get-toolchain-root,$(TOOLCHAIN_NAME)-4.9)
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_ROOT)/bin/$(TOOLCHAIN_NAME)-
 
 TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
 TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
@@ -44,7 +45,7 @@
 LLVM_TRIPLE := mips64el-none-linux-android
 
 TARGET_CFLAGS := \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -fpic \
     -fno-strict-aliasing \
@@ -58,8 +59,7 @@
     -no-canonical-prefixes
 
 TARGET_LDFLAGS += \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
-    -L $(call get-gcclibs-path,$(NDK_ROOT),$(TOOLCHAIN_NAME)) \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -no-canonical-prefixes
 
diff --git a/build/core/toolchains/mipsel-linux-android-clang3.6/setup.mk b/build/core/toolchains/mipsel-linux-android-clang3.6/setup.mk
index 5bc796e..1da89d8 100644
--- a/build/core/toolchains/mipsel-linux-android-clang3.6/setup.mk
+++ b/build/core/toolchains/mipsel-linux-android-clang3.6/setup.mk
@@ -27,12 +27,13 @@
 # Override the toolchain prefix
 #
 
-LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),llvm)
+LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,llvm)
 LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
 
 TOOLCHAIN_NAME := mipsel-linux-android
 BINUTILS_ROOT := $(call get-binutils-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
-TOOLCHAIN_PREFIX := $(BINUTILS_ROOT)/bin/$(TOOLCHAIN_NAME)-
+TOOLCHAIN_ROOT := $(call get-toolchain-root,$(TOOLCHAIN_NAME)-4.9)
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_ROOT)/bin/$(TOOLCHAIN_NAME)-
 
 TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
 TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
@@ -44,7 +45,7 @@
 LLVM_TRIPLE := mipsel-none-linux-android
 
 TARGET_CFLAGS := \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -fpic \
     -fno-strict-aliasing \
@@ -58,8 +59,7 @@
     -no-canonical-prefixes
 
 TARGET_LDFLAGS += \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
-    -L $(call get-gcclibs-path,$(NDK_ROOT),$(TOOLCHAIN_NAME)) \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -no-canonical-prefixes
 
diff --git a/build/core/toolchains/x86-clang3.6/setup.mk b/build/core/toolchains/x86-clang3.6/setup.mk
index 1aa99f5..4d457a6 100644
--- a/build/core/toolchains/x86-clang3.6/setup.mk
+++ b/build/core/toolchains/x86-clang3.6/setup.mk
@@ -27,12 +27,13 @@
 # Override the toolchain prefix
 #
 
-LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),llvm)
+LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,llvm)
 LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
 
 TOOLCHAIN_NAME := i686-linux-android
 BINUTILS_ROOT := $(call get-binutils-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
-TOOLCHAIN_PREFIX := $(BINUTILS_ROOT)/bin/$(TOOLCHAIN_NAME)-
+TOOLCHAIN_ROOT := $(call get-toolchain-root,x86-4.9)
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_ROOT)/bin/$(TOOLCHAIN_NAME)-
 
 TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
 TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
@@ -40,7 +41,7 @@
 LLVM_TRIPLE := i686-none-linux-android
 
 TARGET_CFLAGS := \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -ffunction-sections \
     -funwind-tables \
@@ -52,8 +53,7 @@
 
 # Add and LDFLAGS for the target here
 TARGET_LDFLAGS += \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
-    -L $(call get-gcclibs-path,$(NDK_ROOT),$(TOOLCHAIN_NAME)) \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -no-canonical-prefixes
 
diff --git a/build/core/toolchains/x86_64-clang3.6/setup.mk b/build/core/toolchains/x86_64-clang3.6/setup.mk
index f424743..323b779 100644
--- a/build/core/toolchains/x86_64-clang3.6/setup.mk
+++ b/build/core/toolchains/x86_64-clang3.6/setup.mk
@@ -27,12 +27,13 @@
 # Override the toolchain prefix
 #
 
-LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,$(NDK_ROOT),llvm)
+LLVM_TOOLCHAIN_PREBUILT_ROOT := $(call get-toolchain-root,llvm)
 LLVM_TOOLCHAIN_PREFIX := $(LLVM_TOOLCHAIN_PREBUILT_ROOT)/bin/
 
 TOOLCHAIN_NAME := x86_64-linux-android
 BINUTILS_ROOT := $(call get-binutils-root,$(NDK_ROOT),$(TOOLCHAIN_NAME))
-TOOLCHAIN_PREFIX := $(BINUTILS_ROOT)/bin/$(TOOLCHAIN_NAME)-
+TOOLCHAIN_ROOT := $(call get-toolchain-root,x86_64-4.9)
+TOOLCHAIN_PREFIX := $(TOOLCHAIN_ROOT)/bin/$(TOOLCHAIN_NAME)-
 
 TARGET_CC := $(LLVM_TOOLCHAIN_PREFIX)clang$(HOST_EXEEXT)
 TARGET_CXX := $(LLVM_TOOLCHAIN_PREFIX)clang++$(HOST_EXEEXT)
@@ -40,7 +41,7 @@
 LLVM_TRIPLE := x86_64-none-linux-android
 
 TARGET_CFLAGS := \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -ffunction-sections \
     -funwind-tables \
@@ -51,8 +52,7 @@
     -no-canonical-prefixes
 
 TARGET_LDFLAGS += \
-    -B $(call host-path,$(BINUTILS_ROOT))/$(TOOLCHAIN_NAME)/bin \
-    -L $(call get-gcclibs-path,$(NDK_ROOT),$(TOOLCHAIN_NAME)) \
+    -gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
     -target $(LLVM_TRIPLE) \
     -no-canonical-prefixes
 
diff --git a/build/lib/build_support.py b/build/lib/build_support.py
index 1b10220..4e88cad 100644
--- a/build/lib/build_support.py
+++ b/build/lib/build_support.py
@@ -23,6 +23,9 @@
 import zipfile
 
 
+THIS_DIR = os.path.realpath(os.path.dirname(__file__))
+
+
 # TODO: Make the x86 toolchain names just be the triple.
 ALL_TOOLCHAINS = (
     'arm-linux-androideabi',
@@ -39,7 +42,7 @@
     'aarch64-linux-android',
     'mipsel-linux-android',
     'mips64el-linux-android',
-    'x86-linux-android',
+    'i686-linux-android',
     'x86_64-linux-android',
 )
 
@@ -102,9 +105,9 @@
     }[arch]
 
 
-def android_path(path=''):
-    top = os.getenv('ANDROID_BUILD_TOP', '')
-    return os.path.realpath(os.path.join(top, path))
+def android_path(*args):
+    top = os.path.realpath(os.path.join(THIS_DIR, '../../..'))
+    return os.path.normpath(os.path.join(top, *args))
 
 
 def sysroot_path(toolchain):
@@ -113,15 +116,15 @@
 
     prebuilt_ndk = 'prebuilts/ndk/current'
     sysroot_subpath = 'platforms/android-{}/arch-{}'.format(version, arch)
-    return android_path(os.path.join(prebuilt_ndk, sysroot_subpath))
+    return android_path(prebuilt_ndk, sysroot_subpath)
 
 
-def ndk_path(path=''):
-    return android_path(os.path.join('ndk', path))
+def ndk_path(*args):
+    return android_path('ndk', *args)
 
 
-def toolchain_path(path=''):
-    return android_path(os.path.join('toolchain', path))
+def toolchain_path(*args):
+    return android_path('toolchain', *args)
 
 
 def default_api_level(arch):
@@ -135,10 +138,11 @@
     return '-j{}'.format(multiprocessing.cpu_count() * 2)
 
 
-def build(cmd, args):
+def build(cmd, args, intermediate_package=False):
+    package_dir = args.out_dir if intermediate_package else args.dist_dir
     common_args = [
         '--verbose',
-        '--package-dir={}'.format(args.package_dir),
+        '--package-dir={}'.format(package_dir),
     ]
 
     build_env = dict(os.environ)
@@ -147,12 +151,19 @@
     subprocess.check_call(cmd + common_args, env=build_env)
 
 
-def get_default_package_dir():
-    DEFAULT_OUT_DIR = android_path('out/ndk')
-    out_dir = os.path.realpath(os.getenv('DIST_DIR', DEFAULT_OUT_DIR))
-    if not os.path.isdir(out_dir):
-        os.makedirs(out_dir)
-    return out_dir
+def _get_dir_from_env(default, env_var):
+    path = os.path.realpath(os.getenv(env_var, default))
+    if not os.path.isdir(path):
+        os.makedirs(path)
+    return path
+
+
+def get_out_dir():
+    return _get_dir_from_env(android_path('out'), 'OUT_DIR')
+
+
+def get_dist_dir(out_dir):
+    return _get_dir_from_env(os.path.join(out_dir, 'dist'), 'DIST_DIR')
 
 
 def get_default_host():
@@ -216,7 +227,7 @@
     basename = os.path.basename(directory)
     try:
         subprocess.check_call(
-            ['zip', '-x', '*.pyc', '-x', '*.pyo', '-x', '*.pyd', '-x', '*.swp',
+            ['zip', '-x', '*.pyc', '-x', '*.pyo', '-x', '*.swp',
              '-x', '*.git*', '-9qr', path, basename])
     finally:
         os.chdir(cwd)
@@ -239,9 +250,17 @@
             '--host', choices=('darwin', 'linux', 'windows', 'windows64'),
             default=get_default_host(),
             help='Build binaries for given OS (e.g. linux).')
+
         self.add_argument(
-            '--package-dir', help='Directory to place the packaged artifact.',
-            type=os.path.realpath, default=get_default_package_dir())
+            '--out-dir', help='Directory to place temporary build files.',
+            type=os.path.realpath, default=get_out_dir())
+
+        # The default for --dist-dir has to be handled after parsing all
+        # arguments because the default is derived from --out-dir. This is
+        # handled in run().
+        self.add_argument(
+            '--dist-dir', help='Directory to place the packaged artifact.',
+            type=os.path.realpath)
 
 
 def run(main_func, arg_parser=ArgParser):
@@ -251,6 +270,9 @@
 
     args = arg_parser().parse_args()
 
+    if args.dist_dir is None:
+        args.dist_dir = get_dist_dir(args.out_dir)
+
     # We want any paths to be relative to the invoked build script.
     main_filename = os.path.realpath(sys.modules['__main__'].__file__)
     os.chdir(os.path.dirname(main_filename))
diff --git a/build/tools/build-cxx-stl.sh b/build/tools/build-cxx-stl.sh
index 7581034..8ac0f63 100755
--- a/build/tools/build-cxx-stl.sh
+++ b/build/tools/build-cxx-stl.sh
@@ -648,7 +648,6 @@
     fi
 done
 
-# If needed, package files into tarballs
 if [ -n "$PACKAGE_DIR" ] ; then
     if [ "$CXX_STL" = "libc++" ]; then
         STL_DIR="llvm-libc++"
@@ -663,48 +662,6 @@
     log "Packaging: $PACKAGE"
     pack_archive "$PACKAGE" "$OUT_DIR/sources/cxx-stl" "$STL_DIR"
     fail_panic "Could not package $CXX_STL binaries!"
-
-    # TODO(danalbert): Move these up into checkbuild.py?
-    # None of these actually have a build step, so we could just pack them up
-    # simply in checkbuild.py.
-    #
-    # gabi++ and libc++abi should actually probably be moved around to be in the
-    # same package as stlport and libc++ respectively since they are actually
-    # bound to each other.
-    if [ "$CXX_STL" = "libc++" ]; then
-        # We need to package libc++abi in case the user needs to rebuild libc++.
-        SUBDIR="sources/cxx-stl"
-        make_repo_prop "$OUT_DIR/$SUBDIR/llvm-libc++abi"
-        PACKAGE="$PACKAGE_DIR/libcxxabi.zip"
-        log "Packaging: $PACKAGE"
-        pack_archive "$PACKAGE" "$OUT_DIR/$SUBDIR" "llvm-libc++abi"
-        fail_panic "Could not package libc++abi!"
-
-        # libc++ needs libandroid_support.
-        make_repo_prop "$OUT_DIR/sources/android/support"
-        PACKAGE="$PACKAGE_DIR/libandroid_support.zip"
-        log "Packaging: $PACKAGE"
-        pack_archive "$PACKAGE" "$OUT_DIR/sources/android" "support"
-        fail_panic "Could not package libandroid_support!"
-    elif [ "$CXX_STL" = "stlport" ]; then
-        # Stlport depends on gabi++.
-        SUBDIR="sources/cxx-stl"
-        make_repo_prop "$OUT_DIR/$SUBDIR/gabi++"
-        PACKAGE="$PACKAGE_DIR/gabixx.zip"
-        log "Packaging: $PACKAGE"
-        pack_archive "$PACKAGE" "$OUT_DIR/$SUBDIR" "gabi++"
-        fail_panic "Could not package gabi++!"
-
-        # ... and the system STL.
-        SUBDIR="sources/cxx-stl"
-        make_repo_prop "$OUT_DIR/$SUBDIR/system"
-        PACKAGE="$PACKAGE_DIR/system-stl.zip"
-        log "Packaging: $PACKAGE"
-        pack_archive "$PACKAGE" "$OUT_DIR/$SUBDIR" "system"
-        fail_panic "Could not package gabi++!"
-    else
-        panic "Unknown STL: $CXX_STL"
-    fi
 fi
 
 if [ -z "$OPTION_BUILD_DIR" ]; then
diff --git a/build/tools/build-gcc.py b/build/tools/build-gcc.py
index a97951d..21ff39d 100755
--- a/build/tools/build-gcc.py
+++ b/build/tools/build-gcc.py
@@ -65,7 +65,7 @@
 
     host_tag = build_support.host_to_tag(args.host)
     for arch in arches:
-        package_gcc(args.package_dir, host_tag, arch, GCC_VERSION)
+        package_gcc(args.dist_dir, host_tag, arch, GCC_VERSION)
 
 
 if __name__ == '__main__':
diff --git a/build/tools/build-llvm.py b/build/tools/build-llvm.py
index 02e973d..7081c91 100755
--- a/build/tools/build-llvm.py
+++ b/build/tools/build-llvm.py
@@ -38,7 +38,7 @@
     LLVM_VERSION = 'clang-2481030'
 
     host = args.host
-    package_dir = args.package_dir
+    package_dir = args.dist_dir
 
     # TODO(danalbert): Fix 64-bit Windows LLVM.
     # This wrongly packages 32-bit Windows LLVM for 64-bit as well, but the
diff --git a/build/tools/common-build-host-funcs.sh b/build/tools/common-build-host-funcs.sh
index 4e07fa8..df9631b 100644
--- a/build/tools/common-build-host-funcs.sh
+++ b/build/tools/common-build-host-funcs.sh
@@ -805,7 +805,7 @@
 #  python_ndk_install_dir with nothing.
 python_build_install_dir ()
 {
-    echo "$BH_BUILD_DIR/install/host-tools"
+    echo "$BH_BUILD_DIR/$1/install/host-tools"
 }
 
 # Same as python_build_install_dir, but for the final NDK installation
diff --git a/build/tools/dev-cleanup.sh b/build/tools/dev-cleanup.sh
index 7260985..0ce9985 100755
--- a/build/tools/dev-cleanup.sh
+++ b/build/tools/dev-cleanup.sh
@@ -47,6 +47,9 @@
 rm -rf $DIR/$LIBCXX_SUBDIR/libs
 rm -rf $DIR/$SUPPORT_SUBDIR/libs
 
+# Remove the temp directory.
+rm -rf $TMPDIR
+
 clean_dir ()
 {
     if [ -d "$1" ] ; then
diff --git a/build/tools/ndk-common.sh b/build/tools/ndk-common.sh
index 4f699c6..f0af5c2 100644
--- a/build/tools/ndk-common.sh
+++ b/build/tools/ndk-common.sh
@@ -725,7 +725,7 @@
     mkdir -p `dirname $ARCHIVE`
 
     TARFLAGS="--exclude='*.py[cod]' --exclude='*.swp' --exclude=.git --exclude=.gitignore -cf"
-    ZIPFLAGS="-x *.git* -x *.pyc -x *.pyo -x *.pyd -9qr"
+    ZIPFLAGS="-x *.git* -x *.pyc -x *.pyo -9qr"
     # Ensure symlinks are stored as is in zip files. for toolchains
     # this can save up to 7 MB in the size of the final archive
     #ZIPFLAGS="$ZIPFLAGS --symlinks"
diff --git a/build/tools/package-release.sh b/build/tools/package-release.sh
deleted file mode 100755
index e0d4071..0000000
--- a/build/tools/package-release.sh
+++ /dev/null
@@ -1,493 +0,0 @@
-#!/bin/sh
-#
-# Copyright (C) 2009-2010 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This script is used to package complete Android NDK release packages.
-#
-# You will need prebuilt toolchain binary tarballs or a previous
-# NDK release package to do that.
-#
-
-. `dirname $0`/prebuilt-common.sh
-
-NDK_ROOT_DIR="$ANDROID_NDK_ROOT"
-
-# the list of platforms / API levels we want to package in
-# this release. This can be overriden with the --platforms
-# option, see below.
-#
-PLATFORMS="$API_LEVELS"
-
-# the default release name (use today's date)
-RELEASE=`date +%Y%m%d`
-register_var_option "--release=<name>" RELEASE "Specify release name"
-
-# the directory containing all prebuilts
-PREBUILT_DIR=
-register_var_option "--prebuilt-dir=<path>" PREBUILT_DIR "Specify prebuilt directory"
-
-# a prebuilt NDK archive (.zip file). empty means don't use any
-PREBUILT_NDK=
-register_var_option "--prebuilt-ndk=<file>" PREBUILT_NDK "Specify prebuilt ndk package"
-
-# the list of supported host development systems
-SYSTEMS=$DEFAULT_SYSTEMS
-register_var_option "--systems=<list>" SYSTEMS "Specify host systems"
-
-# ARCH to build for
-ARCHS="$DEFAULT_ARCHS"
-register_var_option "--arch=<arch>" ARCHS "Specify target architecture(s)"
-
-# set to 'yes' if we should use 'git ls-files' to list the files to
-# be copied into the archive.
-NO_GIT=no
-register_var_option "--no-git" NO_GIT "Don't use git to list input files, take all of them."
-
-# set of toolchain prebuilts we need to package
-OPTION_TOOLCHAINS=
-register_var_option "--toolchains=<list>" OPTION_TOOLCHAINS "Specify list of toolchains."
-
-# set of platforms to package (all by default)
-register_var_option "--platforms=<list>" PLATFORMS "Specify API levels"
-
-# the package prefix
-PREFIX=android-ndk
-register_var_option "--prefix=<name>" PREFIX "Specify package prefix"
-
-# default location for generated packages
-OUT_DIR=$TMPDIR/release
-OPTION_OUT_DIR=
-register_var_option "--out-dir=<path>" OPTION_OUT_DIR "Specify output package directory" "$OUT_DIR"
-
-# Find the location of the platforms root directory
-DEVELOPMENT_ROOT=`dirname $ANDROID_NDK_ROOT`/development/ndk
-register_var_option "--development-root=<path>" DEVELOPMENT_ROOT "Specify platforms directory"
-
-GCC_VERSION_LIST="default" # it's arch defined by default so use default keyword
-register_var_option "--gcc-version-list=<vers>" GCC_VERSION_LIST "List of GCC release versions"
-
-GDB_VERSION=$DEFAULT_GDB_VERSION
-register_var_option "--gdb-version=<versions>" GDB_VERSION "GDB release version"
-
-register_try64_option
-
-PROGRAM_PARAMETERS=
-PROGRAM_DESCRIPTION=\
-"Package a new set of release packages for the Android NDK.
-
-You will need to have generated one or more prebuilt binary tarballs
-with the checkbuild.py script. These files should be named like
-<toolname>-<system>.tar.bz2, where <toolname> is an arbitrary tool name, and
-<system> is one of: $SYSTEMS
-
-Use the --prebuilt-dir=<path> option to build release packages from the
-binary tarballs stored in <path>.
-
-Alternatively, you can use --prebuilt-ndk=<file> where <file> is the path
-to a previous NDK release package. It will be used to extract the toolchain
-binaries and copy them to your new release. Only use this for experimental
-package releases.
-
-The generated release packages will be stored in a temporary directory that
-will be printed at the end of the generation process.
-"
-
-extract_parameters "$@"
-
-# Ensure that SYSTEMS is space-separated
-SYSTEMS=$(commas_to_spaces $SYSTEMS)
-
-ARCHS=$(commas_to_spaces $ARCHS)
-
-# Compute ABIS from ARCHS
-ABIS=
-for ARCH in $ARCHS; do
-    DEFAULT_ABIS=$(get_default_abis_for_arch $ARCH)
-    if [ -z "$ABIS" ]; then
-        ABIS=$DEFAULT_ABIS
-    else
-        ABIS=$ABIS" $DEFAULT_ABIS"
-    fi
-done
-
-# If --arch is used to list x86 as a target architecture, Add x86-4.8 to
-# the list of default toolchains to package. That is, unless you also
-# explicitely use --toolchains=<list>
-#
-# Ensure that TOOLCHAINS is space-separated after this.
-#
-if [ "$OPTION_TOOLCHAINS" != "$TOOLCHAINS" ]; then
-    TOOLCHAINS=$(commas_to_spaces $OPTION_TOOLCHAINS)
-else
-    for ARCH in $ARCHS; do
-       case $ARCH in
-           arm|arm64|x86|x86_64|mips|mips64) TOOLCHAINS=$TOOLCHAINS" "$(get_toolchain_name_list_for_arch $ARCH) ;;
-           *) echo "ERROR: Unknown arch to package: $ARCH"; exit 1 ;;
-       esac
-    done
-    TOOLCHAINS=$(commas_to_spaces $TOOLCHAINS)
-fi
-
-if [ "$GCC_VERSION_LIST" != "default" ]; then
-   TOOLCHAIN_NAMES=
-   for VERSION in $(commas_to_spaces $GCC_VERSION_LIST); do
-      for TOOLCHAIN in $TOOLCHAINS; do
-         if [ $TOOLCHAIN != ${TOOLCHAIN%%$VERSION} ]; then
-            TOOLCHAIN_NAMES="$TOOLCHAIN $TOOLCHAIN_NAMES"
-         fi
-      done
-   done
-   TOOLCHAINS=$TOOLCHAIN_NAMES
-fi
-
-# Check the prebuilt path
-#
-if [ -n "$PREBUILT_NDK" -a -n "$PREBUILT_DIR" ] ; then
-    echo "ERROR: You cannot use both --prebuilt-ndk and --prebuilt-dir at the same time."
-    exit 1
-fi
-
-if [ -z "$PREBUILT_DIR" -a -z "$PREBUILT_NDK" ] ; then
-    echo "ERROR: You must use one of --prebuilt-dir or --prebuilt-ndk. See --help for details."
-    exit 1
-fi
-
-# Check the option directory.
-if [ -n "$OPTION_OUT_DIR" ] ; then
-    OUT_DIR="$OPTION_OUT_DIR"
-    mkdir -p $OUT_DIR
-    if [ $? != 0 ] ; then
-        echo "ERROR: Could not create output directory: $OUT_DIR"
-        exit 1
-    fi
-else
-    rm -rf $OUT_DIR && mkdir -p $OUT_DIR
-fi
-
-# Handle the prebuilt binaries now
-#
-if [ -n "$PREBUILT_DIR" ] ; then
-    if [ ! -d "$PREBUILT_DIR" ] ; then
-        echo "ERROR: the --prebuilt-dir argument is not a directory: $PREBUILT_DIR"
-        exit 1
-    fi
-    if [ -z "$SYSTEMS" ] ; then
-        echo "ERROR: Your systems list is empty, use --systems=LIST to specify a different one."
-        exit 1
-    fi
-else
-    if [ ! -f "$PREBUILT_NDK" ] ; then
-        echo "ERROR: the --prebuilt-ndk argument is not a file: $PREBUILT_NDK"
-        exit 1
-    fi
-    # Check that the name ends with the proper host tag
-    HOST_NDK_SUFFIX="$HOST_TAG.zip"
-    echo "$PREBUILT_NDK" | grep -q "$HOST_NDK_SUFFIX"
-    fail_panic "The name of the prebuilt NDK must end in $HOST_NDK_SUFFIX"
-    SYSTEMS=$HOST_TAG
-fi
-
-echo "Architectures: $ARCHS"
-echo "CPU ABIs: $ABIS"
-echo "GCC Toolchains: $TOOLCHAINS"
-echo "Host systems: $SYSTEMS"
-
-
-# The list of git files to copy into the archives
-if [ "$NO_GIT" != "yes" ] ; then
-    echo "Collecting sources from git (use --no-git to copy all files instead)."
-    GIT_FILES=`cd $NDK_ROOT_DIR && git ls-files`
-else
-    echo "Collecting all sources files under tree."
-    # Get all files under the NDK root
-    GIT_FILES=`cd $NDK_ROOT_DIR && find .`
-    GIT_FILES=`echo $GIT_FILES | sed -e "s!\./!!g"`
-fi
-
-# temporary directory used for packaging
-TMPDIR=$NDK_TMPDIR
-
-RELEASE_PREFIX=$PREFIX-$RELEASE
-
-# ensure that the generated files are ug+rx
-umask 0022
-
-# Translate name to 64-bit's counterpart
-# $1: prebuilt name
-name64 ()
-{
-    local NAME=$1
-    case $NAME in
-        *windows)
-            NAME=${NAME}-x86_64
-            ;;
-        *linux-x86|*darwin-x86)
-            NAME=${NAME}_64
-            ;;
-    esac
-    echo $NAME
-}
-
-# Unpack a prebuilt into specified destination directory
-# $1: prebuilt name, relative to $PREBUILT_DIR
-# $2: destination directory
-unpack_prebuilt ()
-{
-    local PREBUILT=$1
-    local DDIR="$2"
-
-    PREBUILT=${PREBUILT}.tar.bz2
-
-    echo "Unpacking $PREBUILT"
-    if [ -f "$PREBUILT_DIR/$PREBUILT" ] ; then
-        unpack_archive "$PREBUILT_DIR/$PREBUILT" "$DDIR"
-        fail_panic "Could not unpack prebuilt $PREBUILT. Aborting."
-    else
-        fail_panic "Could not find $PREBUILT in $PREBUILT_DIR"
-    fi
-}
-
-# Copy a prebuilt directory from the previous
-# $1: Source directory relative to
-copy_prebuilt ()
-{
-    local SUBDIR="$1"
-    if [ -d "$1" ] ; then
-        echo "Copying: $SUBDIR"
-        copy_directory "$SUBDIR" "$DSTDIR/$2"
-    else
-        echo "Ignored: $SUBDIR"
-    fi
-}
-
-
-rm -rf $TMPDIR && mkdir -p $TMPDIR
-
-# Unpack the previous NDK package if any
-if [ -n "$PREBUILT_NDK" ] ; then
-    echo "Unpacking prebuilt toolchains from $PREBUILT_NDK"
-    UNZIP_DIR=$TMPDIR/prev-ndk
-    rm -rf $UNZIP_DIR && mkdir -p $UNZIP_DIR
-    fail_panic "Could not create temporary directory: $UNZIP_DIR"
-    unpack_archive "$PREBUILT_NDK" "$UNZIP_DIR"
-    fail_panic "Could not unzip NDK package $PREBUILT_NDK"
-fi
-
-# first create the reference ndk directory from the git reference
-echo "Creating reference from source files"
-REFERENCE=$TMPDIR/reference && rm -rf $REFERENCE/* &&
-copy_file_list "$NDK_ROOT_DIR" "$REFERENCE" $GIT_FILES &&
-rm -f $REFERENCE/Android.mk
-fail_panic "Could not create reference. Aborting."
-
-# Copy platform and sample files
-if [ "$PREBUILT_DIR" ]; then
-    echo "Unpacking platform files" &&
-    unpack_archive "$PREBUILT_DIR/platforms.tar.bz2" "$REFERENCE"
-    fail_panic "Could not unpack platform files"
-elif [ "$PREBUILT_NDK" ]; then
-    echo "ERROR: NOT IMPLEMENTED!"
-    exit 1
-else
-    # copy platform and sample files
-    echo "Copying platform and sample files"
-    FLAGS="--src-dir=$DEVELOPMENT_ROOT --dst-dir=$REFERENCE"
-    FLAGS="$FLAGS --platform=$(spaces_to_commas $PLATFORMS)"
-    FLAGS="$FLAGS --arch=$(spaces_to_commas $ARCHS)"
-    $NDK_ROOT_DIR/build/tools/gen-platforms.sh $FLAGS
-    fail_panic "Could not copy platform files. Aborting."
-fi
-
-cp -r $NDK_ROOT_DIR/samples $REFERENCE
-
-# Remove the source for host tools to make the final package smaller
-rm -rf $REFERENCE/sources/host-tools
-
-# Remove leftovers, just in case...
-rm -rf $REFERENCE/tests/build/*/{obj,libs} &&
-rm -rf $REFERENCE/tests/device/*/{obj,libs}
-
-# copy sources files
-if [ -d $DEVELOPMENT_ROOT/sources ] ; then
-    echo "Copying NDK sources files"
-    copy_file_list "$DEVELOPMENT_ROOT" "$REFERENCE" "sources"
-    fail_panic "Could not copy sources. Aborting."
-fi
-
-# Unpack prebuilt C++ runtimes headers and libraries
-if [ -z "$PREBUILT_NDK" ]; then
-    # Unpack gdbserver
-    for ARCH in $ARCHS; do
-        unpack_prebuilt gdbserver-$ARCH "$REFERENCE"
-    done
-    # Unpack C++ runtimes
-    for VERSION in $DEFAULT_GCC_VERSION_LIST; do
-        unpack_prebuilt gnustl-$VERSION "$REFERENCE"
-    done
-
-    unpack_prebuilt stlport "$REFERENCE"
-    unpack_prebuilt libcxx "$REFERENCE"
-fi
-
-# create a release file named 'RELEASE.TXT' containing the release
-# name. This is used by the build script to detect whether you're
-# invoking the NDK from a release package or from the development
-# tree.
-#
-if [ "$TRY64" = "yes" ]; then
-    echo "$RELEASE (64-bit)" > $REFERENCE/RELEASE.TXT
-else
-    echo "$RELEASE" > $REFERENCE/RELEASE.TXT
-fi
-
-# Remove un-needed files
-rm -f $REFERENCE/CleanSpec.mk
-
-# now, for each system, create a package
-#
-DSTDIR=$TMPDIR/$RELEASE_PREFIX
-
-for SYSTEM in $SYSTEMS; do
-    if [ "$TRY64" = "yes" ]; then
-        SYSTEM=`name64 $SYSTEM`
-    fi
-
-    echo "Preparing package for system $SYSTEM."
-    BIN_RELEASE=$RELEASE_PREFIX-$SYSTEM
-    rm -rf "$DSTDIR" &&
-    mkdir -p "$DSTDIR" &&
-    copy_directory "$REFERENCE" "$DSTDIR"
-    fail_panic "Could not copy reference. Aborting."
-
-    if [ "$PREBUILT_NDK" ]; then
-        cd $UNZIP_DIR/android-ndk-* && cp -rP toolchains/$SYSTEM/* \
-            $DSTDIR/toolchains/$SYSTEM
-        fail_panic "Could not copy toolchain files from $PREBUILT_NDK"
-
-        if [ -d "$DSTDIR/$GABIXX_SUBDIR" ]; then
-            GABIXX_ABIS=$PREBUILT_ABIS
-            for GABIXX_ABI in $GABIXX_ABIS; do
-                copy_prebuilt "$GABIXX_SUBDIR/libs/$GABIXX_ABI" "$GABIXX_SUBDIR/libs"
-            done
-        else
-            echo "WARNING: Could not find GAbi++ source tree!"
-        fi
-
-        if [ -d "$DSTDIR/$STLPORT_SUBDIR" ] ; then
-            STLPORT_ABIS=$PREBUILT_ABIS
-            for STL_ABI in $STLPORT_ABIS; do
-                copy_prebuilt "$STLPORT_SUBDIR/libs/$STL_ABI" "$STLPORT_SUBDIR/libs"
-            done
-        else
-            echo "WARNING: Could not find STLport source tree!"
-        fi
-
-        if [ -d "$DSTDIR/$LIBCXX_SUBDIR" ]; then
-            LIBCXX_ABIS=$PREBUILT_ABIS
-            for STL_ABI in $LIBCXX_ABIS; do
-                copy_prebuilt "$LIBCXX_SUBDIR/libs/$STL_ABI" "$LIBCXX_SUBDIR/libs"
-            done
-        else
-            echo "WARNING: Could not find Libc++ source tree!"
-        fi
-
-        for VERSION in $DEFAULT_GCC_VERSION_LIST; do
-            copy_prebuilt "$GNUSTL_SUBDIR/$VERSION/include" "$GNUSTL_SUBDIR/$VERSION/"
-            for STL_ABI in $PREBUILT_ABIS; do
-                copy_prebuilt "$GNUSTL_SUBDIR/$VERSION/libs/$STL_ABI" "$GNUSTL_SUBDIR/$VERSION/libs"
-            done
-        done
-    else
-        for ARCH in $ARCHS; do
-            unpack_prebuilt gcc-$ARCH-$SYSTEM "$DSTDIR"
-            unpack_prebuilt binutils-$ARCH-$SYSTEM "$DSTDIR"
-            unpack_prebuilt gcclibs-$ARCH "$DSTDIR"
-        done
-
-        # Unpack clang/llvm
-        unpack_prebuilt llvm-$SYSTEM "$DSTDIR"
-
-        rm -rf $DSTDIR/toolchains/$SYSTEM/*l
-
-        # Unpack renderscript tools; http://b/22377128.
-        echo "WARNING: no renderscript-$SYSTEM tools! http://b/22377128"
-        #unpack_prebuilt renderscript-$SYSTEM "$DSTDIR"
-
-        # Unpack prebuilt ndk-stack and other host tools
-        unpack_prebuilt host-tools-$SYSTEM "$DSTDIR"
-    fi
-
-    # Unpack renderscript headers/libs; http://b/22377128.
-    echo "WARNING: no renderscript headers/libs! http://b/22377128"
-    #unpack_prebuilt renderscript "$DSTDIR"
-
-    # Unpack misc stuff
-    if [ -f "$PREBUILT_DIR/misc.tar.bz2" ]; then
-        unpack_prebuilt misc "$DSTDIR"
-    fi
-
-    # Remove duplicated files in case-insensitive file system
-    if [ "$SYSTEM" = "windows" -o "$SYSTEM" = "windows-x86_64" -o \
-         "$SYSTEM" = "darwin-x86" ]; then
-        rm -rf $DSTDIR/tests/build/c++-stl-source-extensions
-        find "$DSTDIR/platforms" | sort -f | uniq -di | xargs rm
-    fi
-
-    # Remove include-fixed/linux/a.out.h.   See b.android.com/73728
-    find "$DSTDIR/toolchains" -name a.out.h | grep include-fixed/ | xargs rm
-
-    # Remove redundant pretty-printers/libstdcxx
-    rm -rf $DSTDIR/prebuilt/share/pretty-printers/libstdcxx/gcc-l*
-    rm -rf $DSTDIR/prebuilt/share/pretty-printers/libstdcxx/gcc-4.9-*
-
-    # Remove python *.pyc and *.pyo files
-    find $DSTDIR/prebuilt/lib/python* -name "*.pyc" -exec rm -rf {} \;
-    find $DSTDIR/prebuilt/lib/python* -name "*.pyo" -exec rm -rf {} \;
-
-    # Remove .git*
-    find $DSTDIR -name ".git*" -exec rm -rf {} \;
-
-    # Create an archive for the final package. Extension depends on the
-    # host system.
-    ARCHIVE=$BIN_RELEASE
-    if [ "$SYSTEM" = "windows" ]; then
-        ARCHIVE=$ARCHIVE-x86
-    fi
-    case "$SYSTEM" in
-        windows|windows-x86_64)
-            ARCHIVE="$ARCHIVE.zip"
-            ;;
-        *)
-            ARCHIVE="$ARCHIVE.tar.bz2"
-            ;;
-    esac
-
-    make_repo_prop $DSTDIR
-
-    echo "Creating $ARCHIVE"
-    # make all file universally readable, and all executable (including directory)
-    # universally executable, punt intended
-    find $DSTDIR -exec chmod a+r {} \;
-    find $DSTDIR -executable -exec chmod a+x {} \;
-    pack_archive "$OUT_DIR/$ARCHIVE" "$TMPDIR" "$RELEASE_PREFIX"
-    fail_panic "Could not create archive: $OUT_DIR/$ARCHIVE"
-done
-
-echo "Cleaning up."
-rm -rf $TMPDIR/reference
-rm -rf $TMPDIR/prev-ndk
-
-echo "Done, please see packages in $OUT_DIR:"
-ls -lh $OUT_DIR | tee $OUT_DIR/artifacts.txt
diff --git a/build/tools/package.py b/build/tools/package.py
index d401695..213eb3c 100755
--- a/build/tools/package.py
+++ b/build/tools/package.py
@@ -107,12 +107,10 @@
     ]
 
     old_layout = [
-        ('binutils-{arch}-{host}', 'binutils/{triple}'),
         ('build', 'build'),
         ('cpufeatures', 'sources/android/cpufeatures'),
         ('gabixx', 'sources/cxx-stl/gabi++'),
         ('gcc-{arch}-{host}', 'toolchains/{toolchain}-4.9/prebuilt/{host}'),
-        ('gcclibs-{arch}', 'gcclibs/{triple}'),
         ('gdbserver-{arch}', 'prebuilt/android-{arch}/gdbserver'),
         ('gnustl-4.9', 'sources/cxx-stl/gnu-libstdc++/4.9'),
         ('gtest', 'sources/third_party/googletest'),
@@ -243,6 +241,15 @@
     os.chmod(file_path, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
 
 
+def make_source_properties(out_dir):
+    path = os.path.join(out_dir, 'source.properties')
+    with open(path, 'w') as source_properties:
+        source_properties.write('\n'.join([
+            'Pkg.Desc = Android NDK',
+            'Pkg.Revision = 11.0.0',
+        ]))
+
+
 def copy_changelog(out_dir):
     changelog_path = build_support.ndk_path('CHANGELOG.md')
     shutil.copy2(changelog_path, out_dir)
@@ -251,9 +258,12 @@
 def make_package(release, package_dir, packages, host, out_dir, temp_dir):
     release_name = 'android-ndk-{}'.format(release)
     extract_dir = os.path.join(temp_dir, release_name)
+    if os.path.exists(extract_dir):
+        shutil.rmtree(extract_dir)
     extract_all(package_dir, packages, extract_dir)
 
     make_ndk_build_shortcut(extract_dir, host)
+    make_source_properties(extract_dir)
     copy_changelog(extract_dir)
 
     host_tag = build_support.host_to_tag(host)
@@ -305,8 +315,8 @@
             '-f', '--force', dest='force', action='store_true',
             help='Clobber out directory if it exists.')
         self.add_argument(
-            '--package-dir', type=os.path.realpath,
-            default=build_support.get_default_package_dir(),
+            '--dist-dir', type=os.path.realpath,
+            default=build_support.get_dist_dir(build_support.get_out_dir()),
             help='Directory containing NDK modules.')
         self.add_argument(
             '--unpack', action='store_true',
@@ -332,18 +342,14 @@
             sys.exit(args.out_dir + ' already exists. Use -f to overwrite.')
 
     packages = get_all_packages(args.host, arches)
-    check_packages(args.package_dir, packages)
+    check_packages(args.dist_dir, packages)
 
     if args.unpack:
-        extract_all(args.package_dir, packages, args.out_dir)
+        extract_all(args.dist_dir, packages, args.out_dir)
         make_ndk_build_shortcut(args.out_dir, args.host)
     else:
-        package_dir = tempfile.mkdtemp()
-        try:
-            make_package(args.release, args.package_dir, packages, args.host,
-                         args.out_dir, package_dir)
-        finally:
-            shutil.rmtree(package_dir)
+        make_package(args.release, args.dist_dir, packages, args.host,
+                     args.out_dir, build_support.get_out_dir())
 
 
 if __name__ == '__main__':
diff --git a/build/tools/unwanted-symbols/arm/libc.so.functions.txt b/build/tools/unwanted-symbols/arm/libc.so.functions.txt
deleted file mode 100644
index 9140658..0000000
--- a/build/tools/unwanted-symbols/arm/libc.so.functions.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-atexit
-dlmalloc
-free_malloc_leak_info
-get_malloc_leak_info
-__srget
-__swbuf
-__srefill
-__swsetup
-__sflags
-__sfp
-__sinit
-__smakebuf
-__sflush
-__sread
-__swrite
-__sseek
-__sclose
-_fwalk
-__get_thread
-__wait4
-__futex_wake
-__open
-__get_tls
-__getdents64
diff --git a/build/tools/unwanted-symbols/arm/libc.so.variables.txt b/build/tools/unwanted-symbols/arm/libc.so.variables.txt
deleted file mode 100644
index 0a1e307..0000000
--- a/build/tools/unwanted-symbols/arm/libc.so.variables.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-__dso_handle
-__sdidinit
-__sglue
\ No newline at end of file
diff --git a/build/tools/unwanted-symbols/arm64/libc.so.functions.txt b/build/tools/unwanted-symbols/arm64/libc.so.functions.txt
deleted file mode 100644
index 0485158..0000000
--- a/build/tools/unwanted-symbols/arm64/libc.so.functions.txt
+++ /dev/null
@@ -1,61 +0,0 @@
-android_getaddrinfofornet
-android_gethostbyaddrfornet
-android_gethostbynamefornet
-__android_set_abort_message
-arc4random_addrandom
-arc4random_stir
-basename_r
-__bionic_name_mem
-dirname_r
-dlmalloc
-dlmalloc_inspect_all
-dlmalloc_trim
-dlmalloc_usable_size
-__findenv
-free_malloc_leak_info
-__futex_wake
-_fwalk
-__getdents64
-get_malloc_leak_info
-__get_thread
-__get_tls
-localtime_tz
-mktime_tz
-__open
-posix2time
-__pthread_gettid
-__sclose
-__sflags
-__sflush
-__sfp
-SHA1Final
-SHA1Init
-SHA1Transform
-SHA1Update
-__sinit
-__smakebuf
-__sread
-__srefill
-__srget
-__sseek
-strftime_tz
-__swbuf
-__swrite
-__swsetup
-__system_properties_init
-__system_property_add
-__system_property_area_init
-__system_property_find
-__system_property_find_nth
-__system_property_foreach
-__system_property_get
-__system_property_read
-__system_property_serial
-__system_property_set
-__system_property_set_filename
-__system_property_update
-__system_property_wait_any
-_thread_created_hook
-time2posix
-tzsetwall
-__wait4
diff --git a/build/tools/unwanted-symbols/arm64/libc.so.variables.txt b/build/tools/unwanted-symbols/arm64/libc.so.variables.txt
deleted file mode 100644
index 4c62496..0000000
--- a/build/tools/unwanted-symbols/arm64/libc.so.variables.txt
+++ /dev/null
@@ -1,12 +0,0 @@
-__atexit
-__atexit_invalid
-_C_ctype_
-_C_tolower_
-_C_toupper_
-gMallocLeakZygoteChild
-__isthreaded
-__sdidinit
-__sglue
-__system_property_area__
-_tolower_tab_
-_toupper_tab_
diff --git a/build/tools/unwanted-symbols/mips/libc.so.functions.txt b/build/tools/unwanted-symbols/mips/libc.so.functions.txt
deleted file mode 100644
index 9140658..0000000
--- a/build/tools/unwanted-symbols/mips/libc.so.functions.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-atexit
-dlmalloc
-free_malloc_leak_info
-get_malloc_leak_info
-__srget
-__swbuf
-__srefill
-__swsetup
-__sflags
-__sfp
-__sinit
-__smakebuf
-__sflush
-__sread
-__swrite
-__sseek
-__sclose
-_fwalk
-__get_thread
-__wait4
-__futex_wake
-__open
-__get_tls
-__getdents64
diff --git a/build/tools/unwanted-symbols/mips/libc.so.variables.txt b/build/tools/unwanted-symbols/mips/libc.so.variables.txt
deleted file mode 100644
index ae3404a..0000000
--- a/build/tools/unwanted-symbols/mips/libc.so.variables.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-__sdidinit
-__sglue
\ No newline at end of file
diff --git a/build/tools/unwanted-symbols/mips64/libc.so.functions.txt b/build/tools/unwanted-symbols/mips64/libc.so.functions.txt
deleted file mode 120000
index 2c3c27a..0000000
--- a/build/tools/unwanted-symbols/mips64/libc.so.functions.txt
+++ /dev/null
@@ -1 +0,0 @@
-../arm64/libc.so.functions.txt
\ No newline at end of file
diff --git a/build/tools/unwanted-symbols/mips64/libc.so.variables.txt b/build/tools/unwanted-symbols/mips64/libc.so.variables.txt
deleted file mode 120000
index 2fa7efd..0000000
--- a/build/tools/unwanted-symbols/mips64/libc.so.variables.txt
+++ /dev/null
@@ -1 +0,0 @@
-../arm64/libc.so.variables.txt
\ No newline at end of file
diff --git a/build/tools/unwanted-symbols/x86/libc.so.functions.txt b/build/tools/unwanted-symbols/x86/libc.so.functions.txt
deleted file mode 100644
index 111cf4c..0000000
--- a/build/tools/unwanted-symbols/x86/libc.so.functions.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-dlmalloc
-free_malloc_leak_info
-get_malloc_leak_info
-__srget
-__swbuf
-__srefill
-__swsetup
-__sflags
-__sfp
-__sinit
-__smakebuf
-__sflush
-__sread
-__swrite
-__sseek
-__sclose
-_fwalk
-__get_thread
-__wait4
-__futex_wake
-__open
-__get_tls
-__getdents64
diff --git a/build/tools/unwanted-symbols/x86/libc.so.variables.txt b/build/tools/unwanted-symbols/x86/libc.so.variables.txt
deleted file mode 100644
index ae3404a..0000000
--- a/build/tools/unwanted-symbols/x86/libc.so.variables.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-__sdidinit
-__sglue
\ No newline at end of file
diff --git a/build/tools/unwanted-symbols/x86_64/libc.so.functions.txt b/build/tools/unwanted-symbols/x86_64/libc.so.functions.txt
deleted file mode 120000
index 2c3c27a..0000000
--- a/build/tools/unwanted-symbols/x86_64/libc.so.functions.txt
+++ /dev/null
@@ -1 +0,0 @@
-../arm64/libc.so.functions.txt
\ No newline at end of file
diff --git a/build/tools/unwanted-symbols/x86_64/libc.so.variables.txt b/build/tools/unwanted-symbols/x86_64/libc.so.variables.txt
deleted file mode 120000
index 2fa7efd..0000000
--- a/build/tools/unwanted-symbols/x86_64/libc.so.variables.txt
+++ /dev/null
@@ -1 +0,0 @@
-../arm64/libc.so.variables.txt
\ No newline at end of file
diff --git a/checkbuild.py b/checkbuild.py
index c42b015..35b64b1 100644
--- a/checkbuild.py
+++ b/checkbuild.py
@@ -43,18 +43,22 @@
     'build',
     'clang',
     'cpufeatures',
+    'gabi++',
     'gcc',
     'gcclibs',
     'gdbserver',
     'gnustl',
     'gtest',
     'host-tools',
+    'libandroid_support',
     'libc++',
+    'libc++abi',
     'native_app_glue',
     'ndk_helper',
     'platforms',
     'python-packages',
     'stlport',
+    'system-stl',
 }
 
 
@@ -122,9 +126,9 @@
     _invoke_build(build_support.android_path(script), args)
 
 
-def package_ndk(out_dir, args):
-    package_args = common_build_args(out_dir, args)
-    package_args.append(out_dir)
+def package_ndk(out_dir, dist_dir, args):
+    package_args = common_build_args(out_dir, dist_dir, args)
+    package_args.append(dist_dir)
 
     if args.release is not None:
         package_args.append('--release={}'.format(args.release))
@@ -136,52 +140,41 @@
 
 
 def test_ndk(out_dir, args):
-    # TODO(danalbert): Remove the unpack step.
-    # We're building modules, unpacking them, repacking them, and then
-    # unpacking to test. This is dumb. Unpack to a known location to cut out
-    # half of these steps.
-    unpack_dir = tempfile.mkdtemp()
-    try:
-        host_tag = build_support.host_to_tag(args.system)
-        release = args.release
-        if args.release is None:
-            release = datetime.date.today().strftime('%Y%m%d')
+    release = args.release
+    if args.release is None:
+        release = datetime.date.today().strftime('%Y%m%d')
 
-        package_name = 'android-ndk-{}-{}.tar.bz2'.format(release, host_tag)
-        package_path = os.path.join(out_dir, package_name)
+    # The packaging step extracts all the modules to a known directory for
+    # packaging. This directory is not cleaned up after packaging, so we can
+    # reuse that for testing.
+    test_dir = os.path.join(out_dir, 'android-ndk-{}'.format(release))
 
-        print('Extracting {} to {}'.format(package_path, unpack_dir))
-        subprocess.check_call(['tar', 'xf', package_path, '-C', unpack_dir])
-        test_dir = os.path.join(
-            unpack_dir, 'android-ndk-{}'.format(release))
+    test_env = dict(os.environ)
+    test_env['NDK'] = test_dir
 
-        test_env = dict(os.environ)
-        test_env['NDK'] = test_dir
+    abis = build_support.ALL_ABIS
+    if args.arch is not None:
+        abis = build_support.arch_to_abis(args.arch)
 
-        abis = build_support.ALL_ABIS
-        if args.arch is not None:
-            abis = build_support.arch_to_abis(args.arch)
+    results = {}
+    for abi in abis:
+        cmd = [
+            'python', build_support.ndk_path('tests/run-all.py'),
+            '--abi', abi, '--suite', 'build'
+        ]
+        print('Running tests: {}'.format(' '.join(cmd)))
+        result = subprocess.call(cmd, env=test_env)
+        results[abi] = result == 0
 
-        results = {}
-        for abi in abis:
-            cmd = [
-                'python', build_support.ndk_path('tests/run-all.py'),
-                '--abi', abi, '--suite', 'build'
-            ]
-            print('Running tests: {}'.format(' '.join(cmd)))
-            result = subprocess.call(cmd, env=test_env)
-            results[abi] = result == 0
-
-        print('Results:')
-        for abi, result in results.iteritems():
-            print('{}: {}'.format(abi, 'PASS' if result else 'FAIL'))
-        return all(results.values())
-    finally:
-        shutil.rmtree(unpack_dir)
+    print('Results:')
+    for abi, result in results.iteritems():
+        print('{}: {}'.format(abi, 'PASS' if result else 'FAIL'))
+    return all(results.values())
 
 
-def common_build_args(out_dir, args):
-    build_args = ['--package-dir={}'.format(out_dir)]
+def common_build_args(out_dir, dist_dir, args):
+    build_args = ['--out-dir={}'.format(out_dir)]
+    build_args = ['--dist-dir={}'.format(dist_dir)]
     build_args.append('--host={}'.format(args.system))
     return build_args
 
@@ -285,7 +278,7 @@
     return os.path.join(system_path, toolchain_dir)
 
 
-def build_binutils(out_dir, args):
+def build_binutils(out_dir, dist_dir, args):
     print('Extracting binutils package from GCC...')
 
     arches = build_support.ALL_ARCHITECTURES
@@ -299,45 +292,44 @@
         toolchain_path = get_prebuilt_gcc(args.system, arch)
 
         triple = fixup_toolchain_triple(toolchain)
-        tmpdir = tempfile.mkdtemp()
-        try:
-            install_dir = os.path.join(tmpdir, 'binutils', triple)
-            os.makedirs(install_dir)
 
-            has_gold = True
-            if host_tag == 'windows':
-                # Note: 64-bit Windows is fine.
-                has_gold = False
-            if arch in ('mips', 'mips64'):
-                has_gold = False
+        install_dir = os.path.join(out_dir, 'binutils', triple)
+        if os.path.exists(install_dir):
+            shutil.rmtree(install_dir)
+        os.makedirs(install_dir)
 
-            is_windows = host_tag.startswith('windows')
-            for file_name in get_binutils_files(triple, has_gold, is_windows):
-                install_file(file_name, toolchain_path, install_dir)
+        has_gold = True
+        if host_tag == 'windows':
+            # Note: 64-bit Windows is fine.
+            has_gold = False
+        if arch in ('mips', 'mips64'):
+            has_gold = False
 
-            license_path = build_support.android_path(
-                'toolchain/binutils/binutils-2.25/COPYING')
-            shutil.copy2(license_path, os.path.join(install_dir, 'NOTICE'))
+        is_windows = host_tag.startswith('windows')
+        for file_name in get_binutils_files(triple, has_gold, is_windows):
+            install_file(file_name, toolchain_path, install_dir)
 
-            pack_binutils(arch, host_tag, out_dir, install_dir)
-        finally:
-            shutil.rmtree(tmpdir)
+        license_path = build_support.android_path(
+            'toolchain/binutils/binutils-2.25/COPYING')
+        shutil.copy2(license_path, os.path.join(install_dir, 'NOTICE'))
+
+        pack_binutils(arch, host_tag, dist_dir, install_dir)
 
 
-def build_clang(out_dir, args):
+def build_clang(out_dir, dist_dir, args):
     print('Building Clang...')
-    invoke_build('build-llvm.py', common_build_args(out_dir, args))
+    invoke_build('build-llvm.py', common_build_args(out_dir, dist_dir, args))
 
 
-def build_gcc(out_dir, args):
+def build_gcc(out_dir, dist_dir, args):
     print('Building GCC...')
-    build_args = common_build_args(out_dir, args)
+    build_args = common_build_args(out_dir, dist_dir, args)
     if args.arch is not None:
         build_args.append('--arch={}'.format(args.arch))
     invoke_build('build-gcc.py', build_args)
 
 
-def build_gcc_libs(out_dir, args):
+def build_gcc_libs(out_dir, dist_dir, args):
     print('Packaging GCC libs...')
 
     arches = build_support.ALL_ARCHITECTURES
@@ -371,35 +363,33 @@
             for subdir, lib in lib_names:
                 libs.append((subdir, os.path.join(lib_dir, lib)))
 
-        tmpdir = tempfile.mkdtemp()
-        try:
-            install_dir = os.path.join(tmpdir, 'gcclibs', triple)
-            os.makedirs(install_dir)
+        install_dir = os.path.join(out_dir, 'gcclibs', triple)
+        if os.path.exists(install_dir):
+            shutil.rmtree(install_dir)
+        os.makedirs(install_dir)
 
-            # These are target libraries, so the OS we use here is not
-            # important. We explicitly use Linux because for whatever reason
-            # the Windows aarch64 toolchain doesn't include libatomic.
-            gcc_path = get_prebuilt_gcc('linux', arch)
-            for gcc_subdir, lib in libs:
-                src = os.path.join(gcc_path, gcc_subdir, lib)
-                dst = os.path.join(install_dir, lib)
-                dst_dir = os.path.dirname(dst)
-                if not os.path.exists(dst_dir):
-                    os.makedirs(dst_dir)
-                shutil.copy2(src, dst)
+        # These are target libraries, so the OS we use here is not
+        # important. We explicitly use Linux because for whatever reason
+        # the Windows aarch64 toolchain doesn't include libatomic.
+        gcc_path = get_prebuilt_gcc('linux', arch)
+        for gcc_subdir, lib in libs:
+            src = os.path.join(gcc_path, gcc_subdir, lib)
+            dst = os.path.join(install_dir, lib)
+            dst_dir = os.path.dirname(dst)
+            if not os.path.exists(dst_dir):
+                os.makedirs(dst_dir)
+            shutil.copy2(src, dst)
 
-                shutil.copy2(
-                    os.path.join(gcc_path, 'NOTICE'),
-                    os.path.join(install_dir, 'NOTICE'))
+            shutil.copy2(
+                os.path.join(gcc_path, 'NOTICE'),
+                os.path.join(install_dir, 'NOTICE'))
 
-                archive_name = os.path.join(out_dir, 'gcclibs-' + arch)
-                build_support.make_package(archive_name, install_dir, out_dir)
-        finally:
-            shutil.rmtree(tmpdir)
+        archive_name = os.path.join('gcclibs-' + arch)
+        build_support.make_package(archive_name, install_dir, dist_dir)
 
 
-def build_host_tools(out_dir, args):
-    build_args = common_build_args(out_dir, args)
+def build_host_tools(out_dir, dist_dir, args):
+    build_args = common_build_args(out_dir, dist_dir, args)
 
     print('Building ndk-stack...')
     invoke_external_build(
@@ -431,7 +421,7 @@
     print('Building YASM...')
     invoke_external_build('toolchain/yasm/build.py', build_args)
 
-    package_host_tools(out_dir, args.system)
+    package_host_tools(out_dir, dist_dir, args.system)
 
 
 def merge_license_files(output_path, files):
@@ -444,7 +434,7 @@
         output_file.write('\n'.join(licenses))
 
 
-def package_host_tools(out_dir, host):
+def package_host_tools(out_dir, dist_dir, host):
     packages = [
         'gdb-multiarch-7.10',
         'ndk-awk',
@@ -467,113 +457,134 @@
     host_tag = build_support.host_to_tag(host)
 
     package_names = [p + '-' + host_tag + '.tar.bz2' for p in packages]
-    temp_dir = tempfile.mkdtemp()
-    try:
-        for package_name in package_names:
-            package_path = os.path.join(out_dir, package_name)
-            subprocess.check_call(['tar', 'xf', package_path, '-C', temp_dir])
+    for package_name in package_names:
+        package_path = os.path.join(out_dir, package_name)
+        subprocess.check_call(['tar', 'xf', package_path, '-C', out_dir])
 
-        for f in files:
-            shutil.copy2(f, os.path.join(temp_dir, 'host-tools/bin'))
+    for f in files:
+        shutil.copy2(f, os.path.join(out_dir, 'host-tools/bin'))
 
-        merge_license_files(os.path.join(temp_dir, 'host-tools/NOTICE'), [
-            build_support.android_path('toolchain/gdb/gdb-7.10/COPYING'),
-            build_support.ndk_path('sources/host-tools/nawk-20071023/NOTICE'),
-            build_support.ndk_path('sources/host-tools/ndk-depends/NOTICE'),
-            build_support.ndk_path('sources/host-tools/make-3.81/COPYING'),
-            build_support.android_path(
-                'toolchain/python/Python-2.7.5/LICENSE'),
-            build_support.ndk_path('sources/host-tools/ndk-stack/NOTICE'),
-            build_support.ndk_path('sources/host-tools/toolbox/NOTICE'),
-            build_support.android_path('toolchain/yasm/COPYING'),
-            build_support.android_path('toolchain/yasm/BSD.txt'),
-            build_support.android_path('toolchain/yasm/Artistic.txt'),
-            build_support.android_path('toolchain/yasm/GNU_GPL-2.0'),
-            build_support.android_path('toolchain/yasm/GNU_LGPL-2.0'),
-        ])
+    merge_license_files(os.path.join(out_dir, 'host-tools/NOTICE'), [
+        build_support.android_path('toolchain/gdb/gdb-7.10/COPYING'),
+        build_support.ndk_path('sources/host-tools/nawk-20071023/NOTICE'),
+        build_support.ndk_path('sources/host-tools/ndk-depends/NOTICE'),
+        build_support.ndk_path('sources/host-tools/make-3.81/COPYING'),
+        build_support.android_path(
+            'toolchain/python/Python-2.7.5/LICENSE'),
+        build_support.ndk_path('sources/host-tools/ndk-stack/NOTICE'),
+        build_support.ndk_path('sources/host-tools/toolbox/NOTICE'),
+        build_support.android_path('toolchain/yasm/COPYING'),
+        build_support.android_path('toolchain/yasm/BSD.txt'),
+        build_support.android_path('toolchain/yasm/Artistic.txt'),
+        build_support.android_path('toolchain/yasm/GNU_GPL-2.0'),
+        build_support.android_path('toolchain/yasm/GNU_LGPL-2.0'),
+    ])
 
-        package_name = 'host-tools-' + host_tag
-        path = os.path.join(temp_dir, 'host-tools')
-        build_support.make_package(package_name, path, out_dir)
-    finally:
-        shutil.rmtree(temp_dir)
+    package_name = 'host-tools-' + host_tag
+    path = os.path.join(out_dir, 'host-tools')
+    build_support.make_package(package_name, path, dist_dir)
 
 
-def build_gdbserver(out_dir, args):
+def build_gdbserver(out_dir, dist_dir, args):
     print('Building gdbserver...')
-    build_args = common_build_args(out_dir, args)
+    build_args = common_build_args(out_dir, dist_dir, args)
     if args.arch is not None:
         build_args.append('--arch={}'.format(args.arch))
     invoke_build('build-gdbserver.py', build_args)
 
 
-def _build_stl(out_dir, args, stl):
-    build_args = common_build_args(out_dir, args)
+def _build_stl(out_dir, dist_dir, args, stl):
+    build_args = common_build_args(out_dir, dist_dir, args)
     if args.arch is not None:
         build_args.append('--arch={}'.format(args.arch))
     script = 'ndk/sources/cxx-stl/{}/build.py'.format(stl)
     invoke_external_build(script, build_args)
 
 
-def build_gnustl(out_dir, args):
+def build_gnustl(out_dir, dist_dir, args):
     print('Building gnustl...')
-    _build_stl(out_dir, args, 'gnu-libstdc++')
+    _build_stl(out_dir, dist_dir, args, 'gnu-libstdc++')
 
 
-def build_libcxx(out_dir, args):
+def build_libcxx(out_dir, dist_dir, args):
     print('Building libc++...')
-    _build_stl(out_dir, args, 'llvm-libc++')
+    _build_stl(out_dir, dist_dir, args, 'llvm-libc++')
 
 
-def build_stlport(out_dir, args):
+def build_stlport(out_dir, dist_dir, args):
     print('Building stlport...')
-    _build_stl(out_dir, args, 'stlport')
+    _build_stl(out_dir, dist_dir, args, 'stlport')
 
 
-def build_platforms(out_dir, args):
+def build_platforms(out_dir, dist_dir, args):
     print('Building platforms...')
-    invoke_build('build-platforms.py', common_build_args(out_dir, args))
+    build_args = common_build_args(out_dir, dist_dir, args)
+    invoke_build('build-platforms.py', build_args)
 
 
-def build_cpufeatures(out_dir, _):
+def build_cpufeatures(_, dist_dir, __):
     path = build_support.ndk_path('sources/android/cpufeatures')
-    build_support.make_package('cpufeatures', path, out_dir)
+    build_support.make_package('cpufeatures', path, dist_dir)
 
 
-def build_native_app_glue(out_dir, _):
+def build_native_app_glue(_, dist_dir, __):
     path = build_support.android_path(
         'development/ndk/sources/android/native_app_glue')
-    build_support.make_package('native_app_glue', path, out_dir)
+    build_support.make_package('native_app_glue', path, dist_dir)
 
 
-def build_ndk_helper(out_dir, _):
+def build_ndk_helper(_, dist_dir, __):
     path = build_support.android_path(
         'development/ndk/sources/android/ndk_helper')
-    build_support.make_package('ndk_helper', path, out_dir)
+    build_support.make_package('ndk_helper', path, dist_dir)
 
 
-def build_gtest(out_dir, _):
+def build_gtest(_, dist_dir, __):
     path = build_support.ndk_path('sources/third_party/googletest')
-    build_support.make_package('gtest', path, out_dir)
+    build_support.make_package('gtest', path, dist_dir)
 
 
-def build_build(out_dir, _):
+def build_build(_, dist_dir, __):
     path = build_support.ndk_path('build')
-    build_support.make_package('build', path, out_dir)
+    build_support.make_package('build', path, dist_dir)
 
 
-def build_python_packages(out_dir, _):
+def build_python_packages(_, dist_dir, __):
     # Stage the files in a temporary directory to make things easier.
     temp_dir = tempfile.mkdtemp()
     try:
         path = os.path.join(temp_dir, 'python-packages')
         shutil.copytree(
             build_support.android_path('development/python-packages'), path)
-        build_support.make_package('python-packages', path, out_dir)
+        build_support.make_package('python-packages', path, dist_dir)
     finally:
         shutil.rmtree(temp_dir)
 
 
+def build_gabixx(_out_dir, dist_dir, _args):
+    print('Building gabi++...')
+    path = build_support.ndk_path('sources/cxx-stl/gabi++')
+    build_support.make_package('gabixx', path, dist_dir)
+
+
+def build_system_stl(_out_dir, dist_dir, _args):
+    print('Building system-stl...')
+    path = build_support.ndk_path('sources/cxx-stl/system')
+    build_support.make_package('system-stl', path, dist_dir)
+
+
+def build_libandroid_support(_out_dir, dist_dir, _args):
+    print('Building libandroid_support...')
+    path = build_support.ndk_path('sources/android/support')
+    build_support.make_package('libandroid_support', path, dist_dir)
+
+
+def build_libcxxabi(_out_dir, dist_dir, _args):
+    print('Building libc++abi...')
+    path = build_support.ndk_path('sources/cxx-stl/llvm-libc++abi')
+    build_support.make_package('libcxxabi', path, dist_dir)
+
+
 def main():
     parser = ArgParser()
     args = parser.parse_args()
@@ -611,12 +622,9 @@
     # Set ANDROID_BUILD_TOP.
     if 'ANDROID_BUILD_TOP' not in os.environ:
         os.environ['ANDROID_BUILD_TOP'] = os.path.realpath('..')
-    build_top = os.getenv('ANDROID_BUILD_TOP')
 
-    DEFAULT_OUT_DIR = os.path.join(build_top, 'out/ndk')
-    out_dir = os.path.realpath(os.getenv('DIST_DIR', DEFAULT_OUT_DIR))
-    if not os.path.isdir(out_dir):
-        os.makedirs(out_dir)
+    out_dir = build_support.get_out_dir()
+    dist_dir = build_support.get_dist_dir(out_dir)
 
     print('Cleaning up...')
     invoke_build('dev-cleanup.sh')
@@ -626,26 +634,30 @@
         ('build', build_build),
         ('clang', build_clang),
         ('cpufeatures', build_cpufeatures),
+        ('gabi++', build_gabixx),
         ('gcc', build_gcc),
         ('gcclibs', build_gcc_libs),
         ('gdbserver', build_gdbserver),
         ('gnustl', build_gnustl),
         ('gtest', build_gtest),
         ('host-tools', build_host_tools),
+        ('libandroid_support', build_libandroid_support),
         ('libc++', build_libcxx),
+        ('libc++abi', build_libcxxabi),
         ('native_app_glue', build_native_app_glue),
         ('ndk_helper', build_ndk_helper),
         ('platforms', build_platforms),
         ('python-packages', build_python_packages),
         ('stlport', build_stlport),
+        ('system-stl', build_system_stl),
     ])
 
     print('Building modules: {}'.format(' '.join(modules)))
     for module in modules:
-        module_builds[module](out_dir, args)
+        module_builds[module](out_dir, dist_dir, args)
 
     if do_package:
-        package_ndk(out_dir, args)
+        package_ndk(out_dir, dist_dir, args)
 
     if args.test:
         result = test_ndk(out_dir, args)
diff --git a/sources/android/cpufeatures/Android.mk b/sources/android/cpufeatures/Android.mk
index 4604471..7c453fa 100644
--- a/sources/android/cpufeatures/Android.mk
+++ b/sources/android/cpufeatures/Android.mk
@@ -14,6 +14,7 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := cpufeatures
 LOCAL_SRC_FILES := cpu-features.c
+LOCAL_CFLAGS := -Wall -Wextra -Werror
 LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
 LOCAL_EXPORT_LDLIBS := -ldl
 include $(BUILD_STATIC_LIBRARY)
diff --git a/sources/android/cpufeatures/cpu-features.c b/sources/android/cpufeatures/cpu-features.c
index 06cfa0b..b2069c0 100644
--- a/sources/android/cpufeatures/cpu-features.c
+++ b/sources/android/cpufeatures/cpu-features.c
@@ -198,6 +198,7 @@
     return count;
 }
 
+#ifdef __arm__
 /* Extract the content of a the first occurence of a given field in
  * the content of /proc/cpuinfo and return it as a heap-allocated
  * string that must be freed by the caller.
@@ -283,6 +284,7 @@
     }
     return 0;
 }
+#endif /* __arm__ */
 
 /* Parse a number starting from 'input', but not going further
  * than 'limit'. Return the value into '*result'.
@@ -327,11 +329,13 @@
     return parse_number(input, limit, 10, result);
 }
 
+#ifdef __arm__
 static const char*
 parse_hexadecimal(const char* input, const char* limit, int* result)
 {
     return parse_number(input, limit, 16, result);
 }
+#endif /* __arm__ */
 
 /* This small data type is used to represent a CPU list / mask, as read
  * from sysfs on Linux. See http://www.kernel.org/doc/Documentation/cputopology.txt
diff --git a/sources/android/support/.gitignore b/sources/android/support/.gitignore
deleted file mode 100644
index f2febe5..0000000
--- a/sources/android/support/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/repo.prop
diff --git a/sources/cxx-stl/gabi++/.gitignore b/sources/cxx-stl/gabi++/.gitignore
index ad7d20e..25f7406 100644
--- a/sources/cxx-stl/gabi++/.gitignore
+++ b/sources/cxx-stl/gabi++/.gitignore
@@ -1,2 +1 @@
-/repo.prop
 /libs/
diff --git a/sources/cxx-stl/llvm-libc++/.gitignore b/sources/cxx-stl/llvm-libc++/.gitignore
index 8f45b0d..28a55e5 100644
--- a/sources/cxx-stl/llvm-libc++/.gitignore
+++ b/sources/cxx-stl/llvm-libc++/.gitignore
@@ -1,3 +1,2 @@
 libs/
-/repo.prop
 /libcxx/test/lit.site.cfg
diff --git a/sources/cxx-stl/llvm-libc++/Android.mk b/sources/cxx-stl/llvm-libc++/Android.mk
index 8ebbb13..dad7f74 100644
--- a/sources/cxx-stl/llvm-libc++/Android.mk
+++ b/sources/cxx-stl/llvm-libc++/Android.mk
@@ -17,83 +17,51 @@
   endif
 endif
 
-llvm_libc++_includes := $(LOCAL_PATH)/libcxx/include
-llvm_libc++_export_includes := $(llvm_libc++_includes)
-llvm_libc++_sources := \
-	algorithm.cpp \
-	bind.cpp \
-	chrono.cpp \
-	condition_variable.cpp \
-	debug.cpp \
-	exception.cpp \
-	future.cpp \
-	hash.cpp \
-	ios.cpp \
-	iostream.cpp \
-	locale.cpp \
-	memory.cpp \
-	mutex.cpp \
-	new.cpp \
-	optional.cpp \
-	random.cpp \
-	regex.cpp \
-	shared_mutex.cpp \
-	stdexcept.cpp \
-	string.cpp \
-	strstream.cpp \
-	system_error.cpp \
-	thread.cpp \
-	typeinfo.cpp \
-	utility.cpp \
-	valarray.cpp \
-	support/android/locale_android.cpp
+libcxx_includes := $(LOCAL_PATH)/libcxx/include
+libcxx_export_includes := $(libcxx_includes)
+libcxx_sources := \
+    algorithm.cpp \
+    bind.cpp \
+    chrono.cpp \
+    condition_variable.cpp \
+    debug.cpp \
+    exception.cpp \
+    future.cpp \
+    hash.cpp \
+    ios.cpp \
+    iostream.cpp \
+    locale.cpp \
+    memory.cpp \
+    mutex.cpp \
+    new.cpp \
+    optional.cpp \
+    random.cpp \
+    regex.cpp \
+    shared_mutex.cpp \
+    stdexcept.cpp \
+    string.cpp \
+    strstream.cpp \
+    system_error.cpp \
+    thread.cpp \
+    typeinfo.cpp \
+    utility.cpp \
+    valarray.cpp \
+    support/android/locale_android.cpp
 
-llvm_libc++_sources := $(llvm_libc++_sources:%=libcxx/src/%)
+libcxx_sources := $(libcxx_sources:%=libcxx/src/%)
 
 # For now, this library can only be used to build C++11 binaries.
-llvm_libc++_export_cxxflags := -std=c++11
+libcxx_export_cxxflags := -std=c++11
 
 ifeq (,$(filter clang%,$(NDK_TOOLCHAIN_VERSION)))
 # Add -fno-strict-aliasing because __list_imp::_end_ breaks TBAA rules by declaring
 # simply as __list_node_base then casted to __list_node derived from that.  See
 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61571 for details
-llvm_libc++_export_cxxflags += -fno-strict-aliasing
+libcxx_export_cxxflags += -fno-strict-aliasing
 endif
 
-llvm_libc++_cxxflags := $(llvm_libc++_export_cxxflags)
-llvm_libc++_cflags :=
-
-libcxxabi_sources_dir := $(strip $(wildcard $(LOCAL_PATH)/../llvm-libc++abi))
-ifdef libcxxabi_sources_dir
-  libcxxabi_sources_prefix := ../llvm-libc++abi
-else
-  libcxxabi_sources_dir := $(strip $(wildcard $(NDK_ROOT)/sources/cxx-stl/llvm-libc++abi))
-  ifndef libcxxabi_sources_dir
-    $(error Can't find libcxxabi sources directory!!)
-  endif
-  libcxxabi_sources_prefix := $(libcxxabi_sources_dir)
-endif
-
-include $(libcxxabi_sources_dir)/sources.mk
-
-ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
-# for armeabi*, use llvm libunwind
-llvm_libc++_sources += $(addprefix $(libcxxabi_sources_prefix:%/=%)/,$(libcxxabi_src_files))
-llvm_libc++_cxxflags += -DLIBCXXABI_USE_LLVM_UNWINDER=1 -D__STDC_FORMAT_MACROS
-else
-llvm_libc++_sources += $(addprefix $(libcxxabi_sources_prefix:%/=%)/,$(libcxxabi_src_base_files))
-llvm_libc++_cxxflags += -DLIBCXXABI_USE_LLVM_UNWINDER=0
-endif
-
-llvm_libc++_includes += $(libcxxabi_c_includes)
-llvm_libc++_export_includes += $(libcxxabi_c_includes)
-llvm_libc++_cflags += -D__STDC_FORMAT_MACROS
-
-ifeq (clang3.5,$(NDK_TOOLCHAIN_VERSION))
-# Workaround an issue of integrated-as (default in clang3.5) where it fails to compile
-# llvm-libc++abi/libcxxabi/src/Unwind/UnwindRegistersRestore.S
-llvm_libc++_cflags += -no-integrated-as
-endif
+libcxx_cxxflags := $(libcxx_export_cxxflags)
+libcxx_cflags := -D__STDC_FORMAT_MACROS
 
 ifneq ($(LIBCXX_FORCE_REBUILD),true)
 
@@ -104,31 +72,15 @@
 include $(CLEAR_VARS)
 LOCAL_MODULE := c++_static
 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
-# For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
-ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
-ifneq (arm,$(LOCAL_ARM_MODE))
-ifneq (arm,$(TARGET_ARM_MODE))
-LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
-endif
-endif
-endif
-LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
-LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
+LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes) $(android_support_c_includes)
+LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
 include $(PREBUILT_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
 LOCAL_MODULE := c++_shared
 LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
-# For armeabi*, choose thumb mode unless LOCAL_ARM_MODE := arm
-ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
-ifneq (arm,$(LOCAL_ARM_MODE))
-ifneq (arm,$(TARGET_ARM_MODE))
-LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/thumb/lib$(LOCAL_MODULE)$(TARGET_SONAME_EXTENSION)
-endif
-endif
-endif
-LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes) $(android_support_c_includes)
-LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
+LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes) $(android_support_c_includes)
+LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
 include $(PREBUILT_SHARED_LIBRARY)
 
 else
@@ -138,28 +90,35 @@
 
 include $(CLEAR_VARS)
 LOCAL_MODULE := c++_static
-LOCAL_SRC_FILES := $(llvm_libc++_sources)
-LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
-LOCAL_CFLAGS := $(llvm_libc++_cflags)
-LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
+LOCAL_SRC_FILES := $(libcxx_sources)
+LOCAL_C_INCLUDES := $(android_support_c_includes) $(libcxx_includes)
+LOCAL_CFLAGS := $(libcxx_cflags)
+LOCAL_CPPFLAGS := $(libcxx_cxxflags)
 LOCAL_CPP_FEATURES := rtti exceptions
-LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
-LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
-LOCAL_STATIC_LIBRARIES := android_support
+LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes)
+LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
+LOCAL_STATIC_LIBRARIES := libc++abi android_support
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
 LOCAL_MODULE := c++_shared
-LOCAL_SRC_FILES := $(llvm_libc++_sources)
-LOCAL_C_INCLUDES := $(android_support_c_includes) $(llvm_libc++_includes)
-LOCAL_CFLAGS := $(llvm_libc++_cflags)
-LOCAL_CPPFLAGS := $(llvm_libc++_cxxflags)
-LOCAL_CPP_FEATURES := rtti exceptions
-LOCAL_EXPORT_C_INCLUDES := $(llvm_libc++_export_includes)
-LOCAL_EXPORT_CPPFLAGS := $(llvm_libc++_export_cxxflags)
-LOCAL_STATIC_LIBRARIES := android_support
+LOCAL_WHOLE_STATIC_LIBRARIES := c++_static
+LOCAL_EXPORT_C_INCLUDES := $(libcxx_export_includes)
+LOCAL_EXPORT_CPPFLAGS := $(libcxx_export_cxxflags)
+LOCAL_STATIC_LIBRARIES := libc++abi android_support
+
+# We use the LLVM unwinder for all the 32-bit ARM targets.
+ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
+    LOCAL_STATIC_LIBRARIES += libunwind
+endif
+
+# But only need -latomic for armeabi.
+ifeq ($(TARGET_ARCH_ABI),armeabi)
+    LOCAL_LDLIBS := -latomic
+endif
 include $(BUILD_SHARED_LIBRARY)
 
 endif # LIBCXX_FORCE_REBUILD == true
 
 $(call import-module, android/support)
+$(call import-module, cxx-stl/llvm-libc++abi)
diff --git a/sources/cxx-stl/llvm-libc++/Application.mk b/sources/cxx-stl/llvm-libc++/Application.mk
new file mode 100644
index 0000000..eada7ed
--- /dev/null
+++ b/sources/cxx-stl/llvm-libc++/Application.mk
@@ -0,0 +1,4 @@
+NDK_TOOLCHAIN_VERSION := clang
+# Even the system STL is too much because it will link libsupc++ for rtti and
+# exceptions.
+APP_STL := none
diff --git a/sources/cxx-stl/llvm-libc++/build.py b/sources/cxx-stl/llvm-libc++/build.py
index df26bba..724ff8e 100755
--- a/sources/cxx-stl/llvm-libc++/build.py
+++ b/sources/cxx-stl/llvm-libc++/build.py
@@ -18,15 +18,18 @@
 from __future__ import print_function
 
 import os
+import shutil
 import site
+import subprocess
 
-site.addsitedir(os.path.join(os.path.dirname(__file__), '../../../build/lib'))
+THIS_DIR = os.path.realpath(os.path.dirname(__file__))
+site.addsitedir(os.path.join(THIS_DIR, '../../../build/lib'))
 
-import build_support
+import build_support  # pylint: disable=import-error
 
 
 class ArgParser(build_support.ArgParser):
-    def __init__(self):
+    def __init__(self):  # pylint: disable=super-on-old-class
         super(ArgParser, self).__init__()
 
         self.add_argument(
@@ -43,18 +46,66 @@
     for arch in arches:
         abis.extend(build_support.arch_to_abis(arch))
 
-    print('Building libc++ for ABIs: {}'.format(' '.join(abis)))
+    ndk_build = build_support.ndk_path('build/ndk-build')
+    prebuilt_ndk = build_support.android_path('prebuilts/ndk/current')
+    platforms_root = os.path.join(prebuilt_ndk, 'platforms')
+    toolchains_root = os.path.join(prebuilt_ndk, 'toolchains')
+    libcxx_path = build_support.ndk_path('sources/cxx-stl/llvm-libc++')
+    obj_out = os.path.join(args.out_dir, 'libcxx/obj')
 
-    abis_arg = '--abis={}'.format(','.join(abis))
-    ndk_dir_arg = '--ndk-dir={}'.format(build_support.ndk_path())
-    script = build_support.ndk_path('build/tools/build-cxx-stl.sh')
+    # TODO(danalbert): Stop building to the source directory.
+    # This is historical, and simplifies packaging a bit. We need to pack up
+    # all the source as well as the libraries. If build_support.make_package
+    # were to change to allow a list of directories instead of one directory,
+    # we could make this unnecessary.  Will be a follow up CL.
+    lib_out = os.path.join(libcxx_path, 'libs')
+
     build_cmd = [
-        'bash', script, '--stl=libc++-libc++abi', abis_arg, ndk_dir_arg,
-        build_support.jobs_arg(), build_support.toolchain_path(),
-        '--with-debug-info', '--llvm-version=3.6',
-    ]
+        'bash', ndk_build, '-C', THIS_DIR, build_support.jobs_arg(), 'V=1',
+        'APP_ABI=' + ' '.join(abis),
 
-    build_support.build(build_cmd, args)
+        # Use the prebuilt platforms and toolchains.
+        'NDK_PLATFORMS_ROOT=' + platforms_root,
+        'NDK_TOOLCHAINS_ROOT=' + toolchains_root,
+        'NDK_NEW_TOOLCHAINS_LAYOUT=true',
+
+        # Tell ndk-build where all of our makefiles are and where outputs
+        # should go. The defaults in ndk-build are only valid if we have a
+        # typical ndk-build layout with a jni/{Android,Application}.mk.
+        'NDK_PROJECT_PATH=null',
+        'APP_BUILD_SCRIPT=' + os.path.join(THIS_DIR, 'Android.mk'),
+        'NDK_APPLICATION_MK=' + os.path.join(THIS_DIR, 'Application.mk'),
+        'NDK_OUT=' + obj_out,
+        'NDK_LIBS_OUT=' + lib_out,
+
+        # Make sure we don't pick up a cached copy.
+        'LIBCXX_FORCE_REBUILD=true',
+
+        # Put armeabi-v7a-hard in its own directory.
+        '_NDK_TESTING_ALL_=yes',
+    ]
+    print('Building libc++ for ABIs: {}'.format(', '.join(abis)))
+    subprocess.check_call(build_cmd)
+
+    # The static libraries are installed to NDK_OUT, not NDK_LIB_OUT, so we
+    # need to install them to our package directory.
+    for abi in abis:
+        static_lib_dir = os.path.join(obj_out, 'local', abi)
+        install_dir = os.path.join(lib_out, abi)
+        is_arm = abi.startswith('armeabi')
+
+        if is_arm:
+            shutil.copy2(
+                os.path.join(static_lib_dir, 'libunwind.a'), install_dir)
+
+        shutil.copy2(os.path.join(static_lib_dir, 'libc++abi.a'), install_dir)
+        shutil.copy2(
+            os.path.join(static_lib_dir, 'libandroid_support.a'), install_dir)
+        shutil.copy2(
+            os.path.join(static_lib_dir, 'libc++_static.a'), install_dir)
+
+    build_support.make_package('libcxx', libcxx_path, args.dist_dir)
+
 
 if __name__ == '__main__':
     build_support.run(main, ArgParser)
diff --git a/sources/cxx-stl/llvm-libc++/libcxx/test/libcxx/ndk/test/config.py b/sources/cxx-stl/llvm-libc++/libcxx/test/libcxx/ndk/test/config.py
index 701f478..56ccd94 100644
--- a/sources/cxx-stl/llvm-libc++/libcxx/test/libcxx/ndk/test/config.py
+++ b/sources/cxx-stl/llvm-libc++/libcxx/test/libcxx/ndk/test/config.py
@@ -58,18 +58,16 @@
         # Configure libc++ library paths.
         self.cxx.link_flags.append('-L' + self.cxx_library_root)
 
-        triple = self.get_lit_conf('target_triple')
-        binutils_dir = os.path.join(
-            self.get_lit_conf('binutils_path'), triple, 'bin')
-        self.cxx.link_flags.append('-B' + binutils_dir)
+        gcc_toolchain = self.get_lit_conf('gcc_toolchain')
+        self.cxx.link_flags.append('-gcc-toolchain')
+        self.cxx.link_flags.append(gcc_toolchain)
 
-        gcclibs_dir = os.path.join(
-            os.environ['NDK'], 'gcclibs', triple)
-        self.cxx.link_flags.append('-L' + gcclibs_dir)
+        triple = self.get_lit_conf('target_triple')
+        if triple.startswith('arm-'):
+            self.cxx.link_flags.append('-lunwind')
+            self.cxx.link_flags.append('-latomic')
 
         self.cxx.link_flags.append('-lgcc')
-        if triple.startswith('arm-'):
-            self.cxx.link_flags.append('-latomic')
 
         self.cxx.link_flags.append('-lc++_shared')
         self.cxx.link_flags.append('-lc')
diff --git a/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in b/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in
index 9c19118..6dd253c 100644
--- a/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in
+++ b/sources/cxx-stl/llvm-libc++/libcxx/test/lit.ndk.cfg.in
@@ -15,7 +15,7 @@
 libcxx_src_dir = os.path.join(libcxx_dir, 'libcxx')
 
 config.cxx_under_test = os.path.join(
-    ndk, "toolchains/llvm/bin/clang++")
+    ndk, "toolchains/llvm/prebuilt/linux-x86_64/bin/clang++")
 config.std = "c++11"
 config.libcxx_src_root = libcxx_src_dir
 config.libcxx_obj_root = libcxx_src_dir
@@ -31,7 +31,8 @@
 config.configuration_variant = "libcxx.ndk"
 config.target_triple = "%TRIPLE%"
 config.sysroot = os.path.join(ndk, "platforms/android-21/arch-%ARCH%/")
-config.binutils_path = os.path.join(ndk, "binutils/%TRIPLE%")
+config.gcc_toolchain = os.path.join(
+    ndk, "toolchains/%TRIPLE%-4.9/prebuilt/linux-x86_64")
 
 # Let the main config do the real work.
 lit_config.load_config(
diff --git a/sources/cxx-stl/llvm-libc++abi/.gitignore b/sources/cxx-stl/llvm-libc++abi/.gitignore
deleted file mode 100644
index f2febe5..0000000
--- a/sources/cxx-stl/llvm-libc++abi/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/repo.prop
diff --git a/sources/cxx-stl/llvm-libc++abi/Android.mk b/sources/cxx-stl/llvm-libc++abi/Android.mk
new file mode 100644
index 0000000..5f9dead
--- /dev/null
+++ b/sources/cxx-stl/llvm-libc++abi/Android.mk
@@ -0,0 +1,109 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+libcxxabi_src_files := \
+    libcxxabi/src/abort_message.cpp \
+    libcxxabi/src/cxa_aux_runtime.cpp \
+    libcxxabi/src/cxa_default_handlers.cpp \
+    libcxxabi/src/cxa_demangle.cpp \
+    libcxxabi/src/cxa_exception.cpp \
+    libcxxabi/src/cxa_exception_storage.cpp \
+    libcxxabi/src/cxa_guard.cpp \
+    libcxxabi/src/cxa_handlers.cpp \
+    libcxxabi/src/cxa_new_delete.cpp \
+    libcxxabi/src/cxa_personality.cpp \
+    libcxxabi/src/cxa_thread_atexit.cpp \
+    libcxxabi/src/cxa_unexpected.cpp \
+    libcxxabi/src/cxa_vector.cpp \
+    libcxxabi/src/cxa_virtual.cpp \
+    libcxxabi/src/exception.cpp \
+    libcxxabi/src/private_typeinfo.cpp \
+    libcxxabi/src/stdexcept.cpp \
+    libcxxabi/src/typeinfo.cpp
+
+libunwind_src_files := \
+    libcxxabi/src/Unwind/libunwind.cpp \
+    libcxxabi/src/Unwind/Unwind-EHABI.cpp \
+    libcxxabi/src/Unwind/Unwind-sjlj.c \
+    libcxxabi/src/Unwind/UnwindLevel1.c \
+    libcxxabi/src/Unwind/UnwindLevel1-gcc-ext.c \
+    libcxxabi/src/Unwind/UnwindRegistersRestore.S \
+    libcxxabi/src/Unwind/UnwindRegistersSave.S
+
+libcxxabi_includes := \
+    $(LOCAL_PATH)/libcxxabi/include \
+    $(LOCAL_PATH)/../llvm-libc++/libcxx/include \
+
+libcxxabi_cflags := -D__STDC_FORMAT_MACROS
+libcxxabi_cppflags := -std=c++11
+
+ifneq (,$(filter armeabi%,$(TARGET_ARCH_ABI)))
+    use_llvm_unwinder := true
+    libcxxabi_cppflags += -DLIBCXXABI_USE_LLVM_UNWINDER=1
+else
+    use_llvm_unwinder := false
+    libcxxabi_cppflags += -DLIBCXXABI_USE_LLVM_UNWINDER=0
+endif
+
+ifneq ($(LIBCXX_FORCE_REBUILD),true) # Using prebuilt
+
+ifeq ($(use_llvm_unwinder),true)
+include $(CLEAR_VARS)
+LOCAL_MODULE := libunwind
+LOCAL_SRC_FILES := ../llvm-libc++/libs/$(TARGET_ARCH_ABI)/$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libcxxabi/include
+include $(PREBUILT_STATIC_LIBRARY)
+endif
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libc++abi
+LOCAL_SRC_FILES := ../llvm-libc++/libs/$(TARGET_ARCH_ABI)/$(LOCAL_MODULE)$(TARGET_LIB_EXTENSION)
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libcxxabi/include
+include $(PREBUILT_STATIC_LIBRARY)
+
+else # Building
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libunwind
+LOCAL_SRC_FILES := $(libunwind_src_files)
+LOCAL_C_INCLUDES := $(libcxxabi_includes)
+LOCAL_CFLAGS := $(libcxxabi_cflags) -fvisibility=hidden
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libcxxabi/include
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libc++abi
+LOCAL_SRC_FILES := $(libcxxabi_src_files)
+LOCAL_C_INCLUDES := $(libcxxabi_includes)
+LOCAL_CPPFLAGS := $(libcxxabi_cppflags)
+LOCAL_CPP_FEATURES := rtti exceptions
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libcxxabi/include
+LOCAL_STATIC_LIBRARIES := android_support
+
+# Unlike the platform build, ndk-build will actually perform dependency checking
+# on static libraries and topologically sort them to determine link order.
+# Though there is no link step, without this we may link libunwind before
+# libc++abi, which won't succeed.
+ifeq ($(use_llvm_unwinder),true)
+    LOCAL_STATIC_LIBRARIES += libunwind
+endif
+include $(BUILD_STATIC_LIBRARY)
+
+endif # Prebuilt/building
+
+$(call import-module, android/support)
diff --git a/sources/cxx-stl/llvm-libc++abi/Application.mk b/sources/cxx-stl/llvm-libc++abi/Application.mk
new file mode 100644
index 0000000..f98280d
--- /dev/null
+++ b/sources/cxx-stl/llvm-libc++abi/Application.mk
@@ -0,0 +1,18 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+NDK_TOOLCHAIN_VERSION := clang
+APP_STL := none
diff --git a/sources/cxx-stl/llvm-libc++abi/sources.mk b/sources/cxx-stl/llvm-libc++abi/sources.mk
deleted file mode 100644
index 40ef4ea..0000000
--- a/sources/cxx-stl/llvm-libc++abi/sources.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-libcxxabi_path := $(call my-dir)
-
-libcxxabi_src_base_files := \
-        libcxxabi/src/abort_message.cpp \
-        libcxxabi/src/cxa_aux_runtime.cpp \
-        libcxxabi/src/cxa_default_handlers.cpp \
-        libcxxabi/src/cxa_demangle.cpp \
-        libcxxabi/src/cxa_exception.cpp \
-        libcxxabi/src/cxa_exception_storage.cpp \
-        libcxxabi/src/cxa_guard.cpp \
-        libcxxabi/src/cxa_handlers.cpp \
-        libcxxabi/src/cxa_new_delete.cpp \
-        libcxxabi/src/cxa_personality.cpp \
-        libcxxabi/src/cxa_thread_atexit.cpp \
-        libcxxabi/src/cxa_unexpected.cpp \
-        libcxxabi/src/cxa_vector.cpp \
-        libcxxabi/src/cxa_virtual.cpp \
-        libcxxabi/src/exception.cpp \
-        libcxxabi/src/private_typeinfo.cpp \
-        libcxxabi/src/stdexcept.cpp \
-        libcxxabi/src/typeinfo.cpp
-
-libcxxabi_src_unwind_files := \
-        libcxxabi/src/Unwind/libunwind.cpp \
-        libcxxabi/src/Unwind/Unwind-EHABI.cpp \
-        libcxxabi/src/Unwind/Unwind-sjlj.c \
-        libcxxabi/src/Unwind/UnwindLevel1.c \
-        libcxxabi/src/Unwind/UnwindLevel1-gcc-ext.c \
-        libcxxabi/src/Unwind/UnwindRegistersRestore.S \
-        libcxxabi/src/Unwind/UnwindRegistersSave.S
-
-libcxxabi_src_files := $(libcxxabi_src_base_files) $(libcxxabi_src_unwind_files)
-
-libcxxabi_c_includes := $(libcxxabi_path)/libcxxabi/include
-
diff --git a/sources/cxx-stl/system/.gitignore b/sources/cxx-stl/system/.gitignore
deleted file mode 100644
index f2febe5..0000000
--- a/sources/cxx-stl/system/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/repo.prop
diff --git a/sources/host-tools/make-3.81/build.py b/sources/host-tools/make-3.81/build.py
index cbdc8e1..5f9d670 100755
--- a/sources/host-tools/make-3.81/build.py
+++ b/sources/host-tools/make-3.81/build.py
@@ -22,7 +22,7 @@
 
 site.addsitedir(os.path.join(os.path.dirname(__file__), '../../../build/lib'))
 
-import build_support
+import build_support  # pylint: disable=import-error
 
 
 def main(args):
@@ -36,7 +36,7 @@
     if args.host != 'windows':
         build_cmd.append('--try-64')
 
-    build_support.build(build_cmd, args)
+    build_support.build(build_cmd, args, intermediate_package=True)
 
 if __name__ == '__main__':
     build_support.run(main)
diff --git a/sources/host-tools/nawk-20071023/build.py b/sources/host-tools/nawk-20071023/build.py
index aae38ed..621e411 100755
--- a/sources/host-tools/nawk-20071023/build.py
+++ b/sources/host-tools/nawk-20071023/build.py
@@ -22,7 +22,7 @@
 
 site.addsitedir(os.path.join(os.path.dirname(__file__), '../../../build/lib'))
 
-import build_support
+import build_support  # pylint: disable=import-error
 
 
 def main(args):
@@ -36,7 +36,7 @@
     if args.host != 'windows':
         build_cmd.append('--try-64')
 
-    build_support.build(build_cmd, args)
+    build_support.build(build_cmd, args, intermediate_package=True)
 
 if __name__ == '__main__':
     build_support.run(main)
diff --git a/sources/host-tools/ndk-depends/build.py b/sources/host-tools/ndk-depends/build.py
index cd4d2b6..59c5a6f 100755
--- a/sources/host-tools/ndk-depends/build.py
+++ b/sources/host-tools/ndk-depends/build.py
@@ -22,7 +22,7 @@
 
 site.addsitedir(os.path.join(os.path.dirname(__file__), '../../../build/lib'))
 
-import build_support
+import build_support  # pylint: disable=import-error
 
 
 def main(args):
@@ -38,7 +38,7 @@
     if args.host != 'windows':
         build_cmd.append('--try-64')
 
-    build_support.build(build_cmd, args)
+    build_support.build(build_cmd, args, intermediate_package=True)
 
 if __name__ == '__main__':
     build_support.run(main)
diff --git a/sources/host-tools/ndk-stack/build.py b/sources/host-tools/ndk-stack/build.py
index af667a2..a930ff4 100755
--- a/sources/host-tools/ndk-stack/build.py
+++ b/sources/host-tools/ndk-stack/build.py
@@ -22,7 +22,7 @@
 
 site.addsitedir(os.path.join(os.path.dirname(__file__), '../../../build/lib'))
 
-import build_support
+import build_support  # pylint: disable=import-error
 
 
 def main(args):
@@ -38,7 +38,7 @@
     if args.host != 'windows':
         build_cmd.append('--try-64')
 
-    build_support.build(build_cmd, args)
+    build_support.build(build_cmd, args, intermediate_package=True)
 
 if __name__ == '__main__':
     build_support.run(main)
diff --git a/sources/host-tools/toolbox/build.py b/sources/host-tools/toolbox/build.py
index 6182814..58dd40a 100755
--- a/sources/host-tools/toolbox/build.py
+++ b/sources/host-tools/toolbox/build.py
@@ -26,7 +26,7 @@
 
 site.addsitedir(os.path.join(os.path.dirname(__file__), '../../../build/lib'))
 
-import build_support
+import build_support  # pylint: disable=import-error
 
 
 def main(args):
@@ -40,7 +40,7 @@
     if args.host != 'windows':
         build_cmd.append('--try-64')
 
-    build_support.build(build_cmd, args)
+    build_support.build(build_cmd, args, intermediate_package=True)
 
 if __name__ == '__main__':
     build_support.run(main)
diff --git a/tests/device/libcxx-unwind/jni/Android.mk b/tests/device/libcxx-unwind/jni/Android.mk
new file mode 100644
index 0000000..5202e5d
--- /dev/null
+++ b/tests/device/libcxx-unwind/jni/Android.mk
@@ -0,0 +1,7 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := foo
+LOCAL_SRC_FILES := foo.cpp
+LOCAL_CPPFLAGS := -std=c++11 -fexceptions -frtti -UNDEBUG -O0
+include $(BUILD_EXECUTABLE)
diff --git a/tests/device/libcxx-unwind/jni/Application.mk b/tests/device/libcxx-unwind/jni/Application.mk
new file mode 100644
index 0000000..e29ff01
--- /dev/null
+++ b/tests/device/libcxx-unwind/jni/Application.mk
@@ -0,0 +1,4 @@
+APP_STL := c++_shared
+APP_ABI := armeabi-v7a
+APP_PLATFORM := android-21
+NDK_TOOLCHAIN_VERSION := clang
diff --git a/tests/device/libcxx-unwind/jni/foo.cpp b/tests/device/libcxx-unwind/jni/foo.cpp
new file mode 100644
index 0000000..1ee5fa2
--- /dev/null
+++ b/tests/device/libcxx-unwind/jni/foo.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <cassert>
+#include <map>
+
+int main() {
+  typedef std::pair<const int, double> V;
+  V ar[] = {
+      V(1, 1.5), V(2, 2.5), V(3, 3.5), V(4, 4.5),
+      V(5, 5.5), V(7, 7.5), V(8, 8.5),
+  };
+  std::map<int, double> m(ar, ar + sizeof(ar) / sizeof(ar[0]));
+  m.at(1) = -1.5;
+  try {
+    m.at(6);
+    assert(0);
+  } catch (std::out_of_range &) {
+  }
+}
diff --git a/tests/ndk.py b/tests/ndk.py
index 73960af..5e392db 100644
--- a/tests/ndk.py
+++ b/tests/ndk.py
@@ -26,21 +26,25 @@
 NDK_ROOT = os.path.realpath(os.path.join(THIS_DIR, '..'))
 
 
-def get_tool(tool):
-    ext = ''
-    if sys.platform == 'win32':
-        ext = '.exe'
-
+def get_host_tag():
     if sys.platform.startswith('linux'):
-        host_tag = 'linux-x86_64'
+        return 'linux-x86_64'
     elif sys.platform == 'darwin':
-        host_tag = 'darwin-x86_64'
+        return 'darwin-x86_64'
     elif sys.platform == 'win32':
         host_tag = 'windows-x86_64'
         test_path = os.path.join(os.environ['NDK'], 'prebuilt', host_tag)
         if not os.path.exists(test_path):
             host_tag = 'windows'
+        return host_tag
 
+
+def get_tool(tool):
+    ext = ''
+    if sys.platform == 'win32':
+        ext = '.exe'
+
+    host_tag = get_host_tag()
     prebuilt_path = os.path.join(os.environ['NDK'], 'prebuilt', host_tag)
     return os.path.join(prebuilt_path, 'bin', tool) + ext
 
diff --git a/tests/run-all.py b/tests/run-all.py
index fd32388..1f5ef08 100644
--- a/tests/run-all.py
+++ b/tests/run-all.py
@@ -43,6 +43,7 @@
 
 import adb
 import filters
+import ndk
 import printers
 import tests
 
@@ -171,7 +172,8 @@
 
 def asan_device_setup():
     path = os.path.join(
-        os.environ['NDK'], 'toolchains', 'llvm', 'bin', 'asan_device_setup')
+        os.environ['NDK'], 'toolchains', 'llvm', 'prebuilt',
+        ndk.get_host_tag(), 'bin', 'asan_device_setup')
     subprocess.check_call([path])
 
 
@@ -208,8 +210,8 @@
             help=('Run tests against the specified platform version. Defaults '
                   'to the contents of APP_PLATFORM in jni/Application.mk'))
         self.add_argument(
-            '--toolchain', default='4.9', choices=('4.9', 'clang'),
-            help='Toolchain for building tests. Defaults to gcc-4.9.')
+            '--toolchain', default='clang', choices=('4.9', 'clang'),
+            help='Toolchain for building tests. Defaults to clang.')
 
         self.add_argument(
             '--show-commands', action='store_true',