Merge "build/core: introduce internal ndk-build unit tests."
diff --git a/build/core/build-binary.mk b/build/core/build-binary.mk
index 932e113..45107db 100644
--- a/build/core/build-binary.mk
+++ b/build/core/build-binary.mk
@@ -239,9 +239,9 @@
 #
 LOCAL_OBJECTS := $(LOCAL_SRC_FILES)
 $(foreach _ext,$(all_source_extensions),\
-    $(eval LOCAL_OBJECTS := $$(LOCAL_OBJECTS:%$(_ext)=%.o))\
+    $(eval LOCAL_OBJECTS := $$(LOCAL_OBJECTS:%$(_ext)=%$$(TARGET_OBJ_EXTENSION)))\
 )
-LOCAL_OBJECTS := $(filter %.o,$(LOCAL_OBJECTS))
+LOCAL_OBJECTS := $(filter %$(TARGET_OBJ_EXTENSION),$(LOCAL_OBJECTS))
 LOCAL_OBJECTS := $(subst ../,__/,$(LOCAL_OBJECTS))
 LOCAL_OBJECTS := $(foreach _obj,$(LOCAL_OBJECTS),$(LOCAL_OBJS_DIR)/$(_obj))
 
@@ -259,7 +259,7 @@
 #
 ifneq (,$(call module-has-c++-features,$(LOCAL_MODULE),rtti exceptions))
     ifeq (system,$(NDK_APP_STL))
-      LOCAL_LDLIBS := $(LOCAL_LDLIBS) $(call host-path,$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(TARGET_ARCH_ABI)/libsupc++.a)
+      LOCAL_LDLIBS := $(LOCAL_LDLIBS) $(call host-path,$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(TARGET_ARCH_ABI)/libsupc++$(TARGET_LIB_EXTENSION))
     endif
 endif
 
diff --git a/build/core/build-shared-library.mk b/build/core/build-shared-library.mk
index 159aebb..f2e98f8 100644
--- a/build/core/build-shared-library.mk
+++ b/build/core/build-shared-library.mk
@@ -27,7 +27,7 @@
 # we are building target objects
 my := TARGET_
 
-$(call handle-module-filename,lib,.so)
+$(call handle-module-filename,lib,$(TARGET_SONAME_EXTENSION))
 $(call handle-module-built)
 
 LOCAL_MODULE_CLASS := SHARED_LIBRARY
diff --git a/build/core/build-static-library.mk b/build/core/build-static-library.mk
index cab3758..be30e74 100644
--- a/build/core/build-static-library.mk
+++ b/build/core/build-static-library.mk
@@ -26,7 +26,7 @@
 # we are building target objects
 my := TARGET_
 
-$(call handle-module-filename,lib,.a)
+$(call handle-module-filename,lib,$(TARGET_LIB_EXTENSION))
 $(call handle-module-built)
 
 LOCAL_MODULE_CLASS := STATIC_LIBRARY
diff --git a/build/core/default-build-commands.mk b/build/core/default-build-commands.mk
index 1f1c230..79e2c6b 100644
--- a/build/core/default-build-commands.mk
+++ b/build/core/default-build-commands.mk
@@ -123,3 +123,7 @@
 TARGET_ARFLAGS := crs
 
 TARGET_STRIP    = $(TOOLCHAIN_PREFIX)strip
+
+TARGET_OBJ_EXTENSION := .o
+TARGET_LIB_EXTENSION := .a
+TARGET_SONAME_EXTENSION := .so
diff --git a/build/core/definitions.mk b/build/core/definitions.mk
index ca3c23a..2d924df 100644
--- a/build/core/definitions.mk
+++ b/build/core/definitions.mk
@@ -1082,7 +1082,7 @@
         $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain spaces)\
         $(call __ndk_error,Plase correct error. Aborting)\
     )\
-    $(if $(filter %.a %.so,$(LOCAL_MODULE_FILENAME)),\
+    $(if $(filter %$(TARGET_LIB_EXTENSION) %$(TARGET_SONAME_EXTENSION),$(LOCAL_MODULE_FILENAME)),\
         $(call __ndk_info,$(LOCAL_MAKEFILE):$(LOCAL_MODULE): LOCAL_MODULE_FILENAME should not include file extensions)\
     )\
   )
@@ -1109,7 +1109,7 @@
     $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain any space)
     $$(call __ndk_error,Aborting)
 endif
-ifneq (,$$(filter %.a %.so,$$(LOCAL_MODULE_FILENAME)))
+ifneq (,$$(filter %$$(TARGET_LIB_EXTENSION) %$$(TARGET_SONAME_EXTENSION),$$(LOCAL_MODULE_FILENAME)))
     $$(call __ndk_info,$$(LOCAL_MAKEFILE):$$(LOCAL_MODULE): LOCAL_MODULE_FILENAME must not contain a file extension)
     $$(call __ndk_error,Aborting)
 endif
@@ -1147,8 +1147,8 @@
 LOCAL_MODULE_FILENAME := $$(strip $$(LOCAL_MODULE_FILENAME))
 ifndef LOCAL_MODULE_FILENAME
     LOCAL_MODULE_FILENAME := $$(notdir $(LOCAL_SRC_FILES))
-    LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.a=%)
-    LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%.so=%)
+    LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%$$(TARGET_LIB_EXTENSION)=%)
+    LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME:%$$(TARGET_SONAME_EXTENSION)=%)
 endif
 LOCAL_MODULE_FILENAME := $$(LOCAL_MODULE_FILENAME)$1
 $$(eval $$(call ev-check-module-filename))
@@ -1421,7 +1421,7 @@
     $(subst ../,__/,\
         $(eval __obj := $1)\
         $(foreach __ext,.c .s .S $(LOCAL_CPP_EXTENSION),\
-            $(eval __obj := $(__obj:%$(__ext)=%.o))\
+            $(eval __obj := $(__obj:%$(__ext)=%$(TARGET_OBJ_EXTENSION)))\
         )\
         $(__obj)\
     ))
@@ -1540,8 +1540,8 @@
   _ORG_FLAGS := $$(_FLAGS)
   _ORG_TEXT  := $$(_TEXT)
 
-  _OBJ_ASM_ORIGINAL := $$(patsubst %.o,%.s,$$(_ORG_OBJ))
-  _OBJ_ASM_FILTERED := $$(patsubst %.o,%.filtered.s,$$(_ORG_OBJ))
+  _OBJ_ASM_ORIGINAL := $$(patsubst %$$(TARGET_OBJ_EXTENSION),%.s,$$(_ORG_OBJ))
+  _OBJ_ASM_FILTERED := $$(patsubst %$$(TARGET_OBJ_EXTENSION),%.filtered.s,$$(_ORG_OBJ))
 
   # If the source file is a plain assembler file, we're going to
   # use it directly in our filter.
@@ -1818,12 +1818,12 @@
 
 # static libraries:
 # <foo> -> lib<foo>.a by default
-$(call module-class-register,STATIC_LIBRARY,lib,.a)
+$(call module-class-register,STATIC_LIBRARY,lib,$(TARGET_LIB_EXTENSION))
 
 # shared libraries:
 # <foo> -> lib<foo>.so
 # a shared library is installable.
-$(call module-class-register-installable,SHARED_LIBRARY,lib,.so)
+$(call module-class-register-installable,SHARED_LIBRARY,lib,$(TARGET_SONAME_EXTENSION))
 
 # executable
 # <foo> -> <foo>
diff --git a/build/core/prebuilt-library.mk b/build/core/prebuilt-library.mk
index 91e8f3c..4c7d93d 100644
--- a/build/core/prebuilt-library.mk
+++ b/build/core/prebuilt-library.mk
@@ -47,7 +47,7 @@
 
 # If LOCAL_MODULE_FILENAME is defined, it will be used to name the file
 # in the TARGET_OUT directory, and then the installation one. Note that
-# if shouldn't have an .a or .so extension nor contain directory separators.
+# it shouldn't have an .a or .so extension nor contain directory separators.
 #
 # If the variable is not defined, we determine its value from LOCAL_SRC_FILES
 #
diff --git a/build/core/prebuilt-shared-library.mk b/build/core/prebuilt-shared-library.mk
index afe5e4b..77ccb11 100644
--- a/build/core/prebuilt-shared-library.mk
+++ b/build/core/prebuilt-shared-library.mk
@@ -22,6 +22,6 @@
 LOCAL_MAKEFILE     := $(local-makefile)
 
 LOCAL_PREBUILT_PREFIX := lib
-LOCAL_PREBUILT_SUFFIX := .so
+LOCAL_PREBUILT_SUFFIX := $(TARGET_SONAME_EXTENSION)
 
 include $(BUILD_SYSTEM)/prebuilt-library.mk
diff --git a/build/core/prebuilt-static-library.mk b/build/core/prebuilt-static-library.mk
index 26087c3..07d981b 100644
--- a/build/core/prebuilt-static-library.mk
+++ b/build/core/prebuilt-static-library.mk
@@ -22,7 +22,7 @@
 LOCAL_MAKEFILE     := $(local-makefile)
 
 LOCAL_PREBUILT_PREFIX := lib
-LOCAL_PREBUILT_SUFFIX := .a
+LOCAL_PREBUILT_SUFFIX := $(TARGET_LIB_EXTENSION)
 
 # Prebuilt static libraries don't need to be copied to TARGET_OUT
 # to facilitate debugging, so use the prebuilt version directly
diff --git a/build/core/setup-app.mk b/build/core/setup-app.mk
index c972bbc..1e27dc3 100644
--- a/build/core/setup-app.mk
+++ b/build/core/setup-app.mk
@@ -72,7 +72,7 @@
 ifeq ($(NDK_APP.$(_app).cleaned_binaries),)
     NDK_APP.$(_app).cleaned_binaries := true
     clean-installed-binaries::
-	$(hide) $(call host-rm,$(NDK_ALL_ABIS:%=$(NDK_APP_PROJECT_PATH)/libs/%/lib*.so))
+	$(hide) $(call host-rm,$(NDK_ALL_ABIS:%=$(NDK_APP_PROJECT_PATH)/libs/%/lib*$(TARGET_SONAME_EXTENSION)))
 	$(hide) $(call host-rm,$(NDK_ALL_ABIS:%=$(NDK_APP_PROJECT_PATH)/libs/%/gdbserver))
 	$(hide) $(call host-rm,$(NDK_ALL_ABIS:%=$(NDK_APP_PROJECT_PATH)/libs/%/gdb.setup))
 endif
diff --git a/build/core/setup-toolchain.mk b/build/core/setup-toolchain.mk
index 978c4c8..6397772 100644
--- a/build/core/setup-toolchain.mk
+++ b/build/core/setup-toolchain.mk
@@ -66,6 +66,10 @@
         # TARGET_TOOLCHAIN_BASE will be 'foo-bar-zoo'
         #
         TARGET_TOOLCHAIN_BASE := $(subst $(space),-,$(call chop,$(subst -,$(space),$(TARGET_TOOLCHAIN))))
+        # if TARGET_TOOLCHAIN_BASE is llvm, remove clang from NDK_TOOLCHAIN_VERSION
+        ifeq ($(TARGET_TOOLCHAIN_BASE),llvm)
+            NDK_TOOLCHAIN_VERSION := $(subst clang,,$(NDK_TOOLCHAIN_VERSION))
+        endif
         TARGET_TOOLCHAIN := $(TARGET_TOOLCHAIN_BASE)-$(NDK_TOOLCHAIN_VERSION)
         $(call ndk_log,Using target toolchain '$(TARGET_TOOLCHAIN)' for '$(TARGET_ARCH_ABI)' ABI (through NDK_TOOLCHAIN_VERSION))
     else
@@ -144,6 +148,7 @@
 NDK_APP_GDBSETUP := $(NDK_APP_DST_DIR)/gdb.setup
 
 ifeq ($(NDK_APP_DEBUGGABLE),true)
+ifeq ($(TARGET_SONAME_EXTENSION),.so)
 
 installed_modules: $(NDK_APP_GDBSERVER)
 
@@ -173,6 +178,7 @@
 # This prevents parallel execution to clear gdb.setup after it has been written to
 $(NDK_APP_GDBSETUP): clean-installed-binaries
 endif
+endif
 
 # free the dictionary of LOCAL_MODULE definitions
 $(call modules-clear)
diff --git a/build/tools/build-analyzer.sh b/build/tools/build-analyzer.sh
index d56c3d9..05e9871 100755
--- a/build/tools/build-analyzer.sh
+++ b/build/tools/build-analyzer.sh
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-#  This shell script is used to copy clang tool "scan-build"
+#  This shell script is used to copy clang tool "scan-build" and "scan-view"
 #  for the Android NDK.
 #
 
@@ -56,6 +56,12 @@
         exit 1
     fi
 
+    SCAN_VIEW_SRC_DIR=$SRC_DIR/$TOOLCHAIN/clang/tools/scan-view
+    if [ ! -d "$SCAN_VIEW_SRC_DIR" ] ; then
+        echo "ERROR: Source directory does not contain scan-view: $SCAN_VIEW_SRC_DIR"
+        exit 1
+    fi
+
     LICENSE_FILE=$SRC_DIR/$TOOLCHAIN/clang/LICENSE.TXT
     if [ ! -f "$LICENSE_FILE" ] ; then
         echo "ERROR: Source directory does not contain clang license file: $LICENSE_FILE"
@@ -93,18 +99,20 @@
     fail_panic "Could not create package directory: $PACKAGE_DIR"
 fi
 
-# copy scan_build
+# copy scan_build and scan_view
 SCAN_BUILD_SUBDIR="prebuilt/common/scan-build"
 run copy_directory "$SCAN_BUILD_SRC_DIR" "$NDK_DIR/$SCAN_BUILD_SUBDIR"
 cp -p "$LICENSE_FILE" "$NDK_DIR/$SCAN_BUILD_SUBDIR"
-
-# remove unneeded file(s)
 rm -f $NDK_DIR/$SCAN_BUILD_SUBDIR/scan-build.1
 
+SCAN_VIEW_SUBDIR="prebuilt/common/scan-view"
+run copy_directory "$SCAN_VIEW_SRC_DIR" "$NDK_DIR/$SCAN_VIEW_SUBDIR"
+cp -p "$LICENSE_FILE" "$NDK_DIR/$SCAN_VIEW_SUBDIR"
+
 if [ "$PACKAGE_DIR" ]; then
-    ARCHIVE="scan-build.tar.bz2"
+    ARCHIVE="scan-build-view.tar.bz2"
     dump "Packaging $ARCHIVE"
-    pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SCAN_BUILD_SUBDIR"
+    pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SCAN_BUILD_SUBDIR" "$SCAN_VIEW_SUBDIR"
 fi
 
 dump "Done."
diff --git a/build/tools/build-gnu-libstdc++.sh b/build/tools/build-gnu-libstdc++.sh
index f42240e..927cb86 100755
--- a/build/tools/build-gnu-libstdc++.sh
+++ b/build/tools/build-gnu-libstdc++.sh
@@ -64,6 +64,9 @@
 NO_MAKEFILE=
 register_var_option "--no-makefile" NO_MAKEFILE "Do not use makefile to speed-up build"
 
+VISIBLE_LIBGNUSTL_STATIC=
+register_var_option "--visible-libgnustl-static" VISIBLE_LIBGNUSTL_STATIC "Do not use hidden visibility for libgnustl_static.a"
+
 register_jobs_option
 
 extract_parameters "$@"
@@ -184,13 +187,15 @@
     if [ $LIBTYPE = "static" ]; then
         # Ensure we disable visibility for the static library to reduce the
         # size of the code that will be linked against it.
-        LIBTYPE_FLAGS="--enable-static --disable-shared"
-        if [ $GCC_VERSION = "4.4.3" -o $GCC_VERSION = "4.6" ]; then
-            LIBTYPE_FLAGS=$LIBTYPE_FLAGS" --disable-visibility"
-        else
-            LIBTYPE_FLAGS=$LIBTYPE_FLAGS" --disable-libstdcxx-visibility"
+        if [ -z "$VISIBLE_LIBGNUSTL_STATIC" ] ; then
+            LIBTYPE_FLAGS="--enable-static --disable-shared"
+            if [ $GCC_VERSION = "4.4.3" -o $GCC_VERSION = "4.6" ]; then
+                LIBTYPE_FLAGS=$LIBTYPE_FLAGS" --disable-visibility"
+            else
+                LIBTYPE_FLAGS=$LIBTYPE_FLAGS" --disable-libstdcxx-visibility"
+            fi
+            CXXFLAGS=$CXXFLAGS" -fvisibility=hidden -fvisibility-inlines-hidden"
         fi
-        CXXFLAGS=$CXXFLAGS" -fvisibility=hidden -fvisibility-inlines-hidden"
     else
         LIBTYPE_FLAGS="--disable-static --enable-shared"
         #LDFLAGS=$LDFLAGS" -lsupc++"
diff --git a/build/tools/build-host-gcc.sh b/build/tools/build-host-gcc.sh
index 2145396..d6d8250 100755
--- a/build/tools/build-host-gcc.sh
+++ b/build/tools/build-host-gcc.sh
@@ -127,6 +127,9 @@
 NDK_DIR=$ANDROID_NDK_ROOT
 register_var_option "--ndk-dir=<path>" NDK_DIR "Select NDK install directory"
 
+BUILD_DIR=
+register_var_option "--build-dir=<path>" BUILD_DIR "Build GCC into directory"
+
 PACKAGE_DIR=
 register_var_option "--package-dir=<path>" PACKAGE_DIR "Package prebuilt tarballs into directory"
 
@@ -174,6 +177,10 @@
     panic "Please use --toolchain-src-dir=<path> to select toolchain source directory."
 fi
 
+if [ -z "$BUILD_DIR" ]; then
+    BUILD_DIR=/tmp/ndk-$USER/build/host-gcc
+fi
+
 case $DEFAULT_LD in
     gold|bfd)
       ;;
@@ -451,7 +458,6 @@
 
 setup_build ()
 {
-    BUILD_DIR=/tmp/ndk-$USER/build/host-gcc
     run_on_setup mkdir -p "$BUILD_DIR"
     if [ -n "$FORCE" ]; then
         rm -rf "$BUILD_DIR"/*
@@ -489,17 +495,6 @@
     fi
 }
 
-get_default_binutils_version_for_gcc ()
-{
-    local RET
-    case $1 in
-        arm-*-4.4.3|x86-*-4.4.3|x86-4.4.3) RET=2.19;;
-        *-4.6) RET=2.21;;
-        *) RET=2.22;;
-    esac
-    echo "$RET"
-}
-
 # Check that a given compiler generates code correctly
 #
 # This is to detect bad/broken toolchains, e.g. amd64-mingw32msvc
@@ -1262,16 +1257,11 @@
 
     LD_NAME=$DEFAULT_LD
 
-    # Enable Gold, for specific builds. The version before binutils 2.21
-    # is buggy so don't use it
-    case $HOST_OS in
-        windows) BUILD_GOLD=;; # Gold doesn't compile on Windows!
-        darwin) BUILD_GOLD=;;  # Building Gold fails with an internal compiler error on Darwin!
-        *) BUILD_GOLD=true;;
-    esac
+    # Enable Gold globally. It can be built for all hosts.
+    BUILD_GOLD=true
 
-    # Special case, gold in binutil-2.21 doesn't build when targetting mips
-    if [ "$BINUTILS_VERSION" = "2.21" -a "$TARGET" = "mipsel-linux-android" ]; then
+    # Special case, gold is not ready for mips yet.
+    if [ "$TARGET" = "mipsel-linux-android" ]; then
         BUILD_GOLD=
     fi
 
@@ -1280,6 +1270,12 @@
     #
     if [ "$BINUTILS_VERSION" = "2.21" -a "$TARGET" = "i686-linux-android" ]; then
         USE_LD_DEFAULT=true
+        BUILD_GOLD=
+    fi
+
+    # Another special case. Not or 2.19, it wasn't ready
+    if [ "$BINUTILS_VERSION" = "2.19" ]; then
+        BUILD_GOLD=
     fi
 
     if [ "$DEFAULT_LD" = "gold" -a -z "$BUILD_GOLD" ]; then
@@ -1299,6 +1295,7 @@
     # The BFD linker is always built, but to build Gold, we need a specific
     # option for the binutils configure script. Note that its format has
     # changed during development.
+    export host_configargs=
     if [ "$BUILD_GOLD" ]; then
         # The syntax of the --enable-gold option has changed.
         if version_is_greater_than $BINUTILS_VERSION 2.20; then
@@ -1314,11 +1311,19 @@
                 ARGS=$ARGS" --enable-gold=both/gold"
             fi
         fi
+	# This ARG needs quoting when passed to run2.
+	GOLD_LDFLAGS_ARG=
         if [ "$HOST_OS" = 'windows' ]; then
             # gold may have runtime dependency on libgcc_sjlj_1.dll and
             # libstdc++-6.dll when built by newer versions of mingw.
             # Link them statically to avoid that.
-            ARGS=$ARGS" --with-gold-ldflags='-static-libgcc -static-libstdc++'"
+            if version_is_greater_than $BINUTILS_VERSION 2.22; then
+                export host_configargs="--with-gold-ldflags='-static-libgcc -static-libstdc++'"
+            elif version_is_greater_than $BINUTILS_VERSION 2.21; then
+                GOLD_LDFLAGS_ARG="--with-gold-ldflags=-static-libgcc -static-libstdc++"
+            else
+                export LDFLAGS=$LDFLAGS" -static-libgcc -static-libstdc++"
+            fi
         fi
     fi
 
@@ -1408,7 +1413,6 @@
 
     ARGS=$ARGS" --with-gnu-as --with-gnu-ld"
     ARGS=$ARGS" --enable-threads --disable-libssp --disable-libmudflap"
-    ARGS=$ARGS" --disable-libgomp"  # TODO: Add option to enable this
     ARGS=$ARGS" --disable-libstdc__-v3 --disable-sjlj-exceptions"
     ARGS=$ARGS" --disable-tls"
     ARGS=$ARGS" --disable-libquadmath --disable-libitm --disable-bootstrap"
@@ -1418,6 +1422,19 @@
     ARGS=$ARGS" --disable-werror"
     ARGS=$ARGS" --enable-target-optspace"
 
+    case "$GCC_VERSION" in
+     4.4.3)
+       ARGS=$ARGS" --disable-libgomp"
+       ;;
+     *)
+       case $TARGET_ARCH in
+	     arm) ARGS=$ARGS" --enable-libgomp";;
+	     x86) ARGS=$ARGS" --disable-libgomp";;
+	     mips|mipsel) ARGS=$ARGS" --disable-libgomp";;
+	 esac
+	 ;;
+    esac
+
     # Place constructors/destructors in .init_array/.fini_array, not in
     # .ctors/.dtors on Android. Note that upstream Linux GLibc is now doing
     # the same.
diff --git a/build/tools/build-host-gdb.sh b/build/tools/build-host-gdb.sh
index 4727439..2c3f91c 100755
--- a/build/tools/build-host-gdb.sh
+++ b/build/tools/build-host-gdb.sh
@@ -144,7 +144,7 @@
     local ARGS
     local SRCDIR=$TOOLCHAIN_SRC_DIR/expat/expat-2.0.1
     local BUILDDIR=$BH_BUILD_DIR/build-expat-2.0.1-$1
-    local INSTALLDIR=$BH_BUILD_DIR/install-expat-2.0.1-$1
+    local INSTALLDIR=$BH_BUILD_DIR/install-host-$1
 
     ARGS=" --prefix=$INSTALLDIR"
     ARGS=$ARGS" --disable-shared --enable-static"
@@ -184,7 +184,7 @@
     bh_setup_host_env
 
     need_build_expat $1
-    local EXPATPREFIX=$BH_BUILD_DIR/install-expat-2.0.1-$1
+    local EXPATPREFIX=$BH_BUILD_DIR/install-host-$1
 
     ARGS=" --prefix=$INSTALLDIR"
     ARGS=$ARGS" --disable-shared"
@@ -194,7 +194,8 @@
     ARGS=$ARGS" --disable-werror"
     ARGS=$ARGS" --disable-nls"
     ARGS=$ARGS" --disable-docs"
-    ARGS=$ARGS" --with-expat=$EXPATPREFIX"
+    ARGS=$ARGS" --with-expat"
+    ARGS=$ARGS" --with-libexpat-prefix=$EXPATPREFIX"
     if [ "$PYTHON_VERSION" ]; then
         ARGS=$ARGS" --with-python=$(python_build_install_dir $BH_HOST_TAG)/bin/python-config.sh"
         if [ $1 = windows-x86 -o $1 = windows-x86_64 ]; then
@@ -203,7 +204,6 @@
             CXXFLAGS=$CXXFLAGS" -D__USE_MINGW_ANSI_STDIO=1"
         fi
     fi
-
     TEXT="$(bh_host_text) gdb-$BH_TARGET_ARCH-$3:"
 
     mkdir -p "$BUILDDIR" && rm -rf "$BUILDDIR"/* &&
@@ -280,7 +280,7 @@
         bh_setup_build_for_host $SYSTEM
         for ARCH in $ARCHS; do
             for VERSION in $GDB_VERSION; do
-                package_host_gdb $SYSTEM android-$ARCH $VERSION
+                bh_stamps_do package_host_gdb-$SYSTEM-$ARCH-$VERSION package_host_gdb $SYSTEM android-$ARCH $VERSION
             done
         done
     done
diff --git a/build/tools/build-target-prebuilts.sh b/build/tools/build-target-prebuilts.sh
index 725c5c8..4d17e3d 100755
--- a/build/tools/build-target-prebuilts.sh
+++ b/build/tools/build-target-prebuilts.sh
@@ -29,6 +29,9 @@
 PACKAGE_DIR=
 register_var_option "--package-dir=<path>" PACKAGE_DIR "Package toolchain into this directory"
 
+VISIBLE_LIBGNUSTL_STATIC=
+register_var_option "--visible-libgnustl-static" VISIBLE_LIBGNUSTL_STATIC "Do not use hidden visibility for libgnustl_static.a"
+
 register_jobs_option
 
 PROGRAM_PARAMETERS="<toolchain-src-dir>"
@@ -93,6 +96,10 @@
 run $BUILDTOOLS/build-stlport.sh $FLAGS
 fail_panic "Could not build stlport!"
 
+if [ ! -z $VISIBLE_LIBGNUSTL_STATIC ]; then
+    FLAGS=$FLAGS" --visible-libgnustl-static"
+fi
+
 dump "Building $ABIS gnustl binaries..."
 run $BUILDTOOLS/build-gnu-libstdc++.sh $FLAGS "$SRC_DIR"
 fail_panic "Could not build gnustl!"
diff --git a/build/tools/gen-platforms.sh b/build/tools/gen-platforms.sh
index 0ced51f..2fc7d8a 100755
--- a/build/tools/gen-platforms.sh
+++ b/build/tools/gen-platforms.sh
@@ -68,6 +68,7 @@
 OPTION_ARCH=
 OPTION_ABI=
 OPTION_DEBUG_LIBS=
+OPTION_OVERLAY=
 PACKAGE_DIR=
 
 VERBOSE=no
@@ -118,6 +119,9 @@
   --debug-libs)
     OPTION_DEBUG_LIBS=true
     ;;
+  --overlay)
+    OPTION_OVERLAY=true
+    ;;
   *)
     echo "unknown option '$opt', use --help"
     exit 1
@@ -565,7 +569,9 @@
 #   $SRC/android-$PLATFORM/arch-$ARCH/include --> $DST/android-$PLATFORM/arch-$ARCH/usr/include
 #   $SRC/android-$PLATFORM/arch-$ARCH/lib --> $DST/android-$PLATFORM/arch-$ARCH/usr/lib
 #
-rm -rf $DSTDIR/platforms && mkdir -p $DSTDIR/platforms
+if [ -z "$OPTION_OVERLAY" ]; then
+    rm -rf $DSTDIR/platforms && mkdir -p $DSTDIR/platforms
+fi
 for ARCH in $ARCHS; do
     # Find first platform for this arch
     PREV_SYSROOT_DST=
@@ -651,7 +657,9 @@
     # $SRC/android-$PLATFORM/samples/ --> $DST/samples
     #
     dump "Copying generic samples"
-    rm -rf $DSTDIR/samples && mkdir -p $DSTDIR/samples
+    if [ -z "OPTION_OVERLAY" ]; then
+        rm -rf $DSTDIR/samples && mkdir -p $DSTDIR/samples
+    fi
     copy_src_directory  samples samples samples
 
     for PLATFORM in $PLATFORMS; do
diff --git a/build/tools/package-release.sh b/build/tools/package-release.sh
index b6f518b..9e80e80 100755
--- a/build/tools/package-release.sh
+++ b/build/tools/package-release.sh
@@ -456,7 +456,7 @@
     fi
 
     # Unpack other host tools
-    unpack_prebuilt scan-build "$DSTDIR" "$DSTDIR64"
+    unpack_prebuilt scan-build-view "$DSTDIR" "$DSTDIR64"
 
     # Create an archive for the final package. Extension depends on the
     # host system.