Merge "Minor fixes in native media documentation"
diff --git a/build/core/build-local.mk b/build/core/build-local.mk
index 802ba6e..c60320e 100644
--- a/build/core/build-local.mk
+++ b/build/core/build-local.mk
@@ -22,6 +22,7 @@
 #
 NDK_ROOT := $(dir $(lastword $(MAKEFILE_LIST)))
 NDK_ROOT := $(strip $(NDK_ROOT:%build/core/=%))
+NDK_ROOT := $(subst \,/,$(NDK_ROOT))
 NDK_ROOT := $(NDK_ROOT:%/=%)
 ifeq ($(NDK_ROOT),)
     # for the case when we're invoked from the NDK install path
@@ -53,7 +54,7 @@
 #
 # ====================================================================
 
-find-project-dir = $(strip $(call find-project-dir-inner,$1,$2))
+find-project-dir = $(strip $(call find-project-dir-inner,$(abspath $1),$2))
 
 find-project-dir-inner = \
     $(eval __found_project_path := )\
diff --git a/build/core/definitions.mk b/build/core/definitions.mk
index cff301b..cd38dda 100644
--- a/build/core/definitions.mk
+++ b/build/core/definitions.mk
@@ -159,8 +159,7 @@
 #            to remove some files.
 # -----------------------------------------------------------------------------
 ifeq ($(HOST_OS),windows)
-host-rm = del /f/q/e $1
-host-rm = $(foreach _filepattern,$1,$(if $(strip $(wildcard $(_filepattern))),del /f/q/e $(subst /,\,$(_filepattern))))
+host-rm = $(foreach _filepattern,$1,$(if $(strip $(wildcard $(_filepattern))),del /f/q/s $(subst /,\,$(_filepattern)) >NUL))
 else
 host-rm = rm -f $1
 endif
@@ -173,9 +172,9 @@
 #            to remove some files _and_ directories.
 # -----------------------------------------------------------------------------
 ifeq ($(HOST_OS),windows)
-host-rmdir = del /f/s/e/q $1
+host-rmdir = del /f/s/e/q $(subst /,\,$1) >NUL 2>NUL
 else
-host-rmdir = rm -f $1
+host-rmdir = rm -rf $1
 endif
 
 # -----------------------------------------------------------------------------
@@ -186,7 +185,7 @@
 #            to create a path if it doesn't exist.
 # -----------------------------------------------------------------------------
 ifeq ($(HOST_OS),windows)
-host-mkdir = md $(subst /,\,$1)
+host-mkdir = if not exist $(subst /,\,$1) md $(subst /,\,$1)
 else
 host-mkdir = mkdir -p $1
 endif
@@ -200,7 +199,7 @@
 #            to copy a single file
 # -----------------------------------------------------------------------------
 ifeq ($(HOST_OS),windows)
-host-cp = copy /b/y $(subst /,\,$1 $2)
+host-cp = copy /b/y $(subst /,\,$1 $2) > NUL
 else
 host-cp = cp -f $1 $2
 endif
@@ -215,7 +214,7 @@
 #            (if possible).
 # -----------------------------------------------------------------------------
 ifeq ($(HOST_OS),windows)
-host-install = copy /b/y $(subst /,\,$1 $2)
+host-install = copy /b/y $(subst /,\,$1 $2) > NUL
 else
 host-install = install -p $1 $2
 endif
diff --git a/build/tools/DEV-SCRIPTS-USAGE.TXT b/build/tools/DEV-SCRIPTS-USAGE.TXT
index 755e932..e425775 100644
--- a/build/tools/DEV-SCRIPTS-USAGE.TXT
+++ b/build/tools/DEV-SCRIPTS-USAGE.TXT
@@ -252,7 +252,7 @@
 
    mkdir -p /tmp/ndk-$USER/toolchain
    cd /tmp/ndk-$USER/toolchain
-   repo init git://android.git.kernel.org/toolchain/manifest.git
+   repo init https://android.googlesource.com/toolchain/manifest.git
    repo sync
 
 then use with:
diff --git a/build/tools/build-gnu-libstdc++.sh b/build/tools/build-gnu-libstdc++.sh
index 6005a49..65ec4a2 100755
--- a/build/tools/build-gnu-libstdc++.sh
+++ b/build/tools/build-gnu-libstdc++.sh
@@ -106,17 +106,25 @@
 mkdir -p "$BUILD_DIR"
 fail_panic "Could not create build directory: $BUILD_DIR"
 
+# $1: ABI name
+# $2: Build directory
+# $3: "static" or "shared"
+# $4: Destination directory (optional, will default to $GNUSTL_SUBDIR/lib/$ABI)
 build_gnustl_for_abi ()
 {
     local ARCH BINPREFIX SYSROOT
     local ABI=$1
     local BUILDDIR="$2"
-    local DSTDIR="$3"
+    local LIBTYPE="$3"
+    local DSTDIR="$4"
     local SRC OBJ OBJECTS CFLAGS CXXFLAGS
 
     prepare_target_build $ABI $PLATFORM $NDK_DIR
     fail_panic "Could not setup target build."
 
+    INSTALLDIR=$BUILDDIR/install
+    BUILDDIR=$BUILDDIR/$LIBTYPE-$ABI
+
     # If the output directory is not specified, use default location
     if [ -z "$DSTDIR" ]; then
         DSTDIR=$NDK_DIR/$GNUSTL_SUBDIR/libs/$ABI
@@ -147,7 +155,7 @@
             ;;
     esac
 
-    export CXXFLAGS="$CXXFLAGS --sysroot=$SYSROOT -fexceptions -frtti -D__BIONIC__ -O2 -fvisibility=hidden -fvisibility-inlines-hidden"
+    export CXXFLAGS="$CXXFLAGS --sysroot=$SYSROOT -fexceptions -frtti -D__BIONIC__ -O2"
 
     export CC=${BINPREFIX}gcc
     export CXX=${BINPREFIX}g++
@@ -161,18 +169,32 @@
 
     export LDFLAGS="-nostdinc -L$SYSROOT/usr/lib -lc"
 
-    PROJECT="GNU libstdc++ $ABI"
+    LIBTYPE_FLAGS=
+    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_FLAG="--enable-static --disable-shared --disable-visibility"
+        CXXFLAGS=$CXXFLAGS" -fvisibility=hidden -fvisibility-inlines-hidden"
+    else
+        LIBTYPE_FLAG="--disable-static --enable-shared"
+        #LDFLAGS=$LDFLAGS" -lsupc++"
+    fi
+
+    PROJECT="gnustl_$LIBTYPE $ABI"
     echo "$PROJECT: configuring"
-    mkdir -p $BUILD_DIR/$ABI &&
+    mkdir -p $BUILDDIR && rm -rf $BUILDDIR/* &&
     cd $BUILDDIR &&
     run $GNUSTL_SRCDIR/configure \
-        --prefix=$BUILDDIR/install \
+        --prefix=$INSTALLDIR \
         --host=$BUILD_HOST \
-        --enable-shared --enable-static \
+        $LIBTYPE_FLAGS \
         --disable-symvers \
         --disable-multilib \
-        --enable-threads --disable-nls \
-        --disable-sjlj-exceptions --disable-tls
+        --enable-threads \
+        --disable-nls \
+        --disable-sjlj-exceptions \
+        --disable-tls \
+        --disable-libstdcxx-pch
 
     fail_panic "Could not configure $PROJECT"
 
@@ -227,8 +249,9 @@
 
 
 for ABI in $ABIS; do
-    build_gnustl_for_abi $ABI "$BUILD_DIR/$ABI"
-    copy_gnustl_libs $ABI "$BUILD_DIR/$ABI"
+    build_gnustl_for_abi $ABI "$BUILD_DIR" static
+    build_gnustl_for_abi $ABI "$BUILD_DIR" shared
+    copy_gnustl_libs $ABI "$BUILD_DIR"
 done
 
 # If needed, package files into tarballs
diff --git a/build/tools/dev-defaults.sh b/build/tools/dev-defaults.sh
index 60fd203..550597f 100644
--- a/build/tools/dev-defaults.sh
+++ b/build/tools/dev-defaults.sh
@@ -21,7 +21,7 @@
 # root directory.
 GNUSTL_SUBDIR=sources/cxx-stl/gnu-libstdc++
 
-# The date to use when downloading toolchain sources from android.git.kernel.org
+# The date to use when downloading toolchain sources from AOSP servers
 # Leave it empty for tip of tree.
 TOOLCHAIN_GIT_DATE=2011-02-23
 
diff --git a/build/tools/download-toolchain-sources.sh b/build/tools/download-toolchain-sources.sh
index 3e36367..13d1ba1 100755
--- a/build/tools/download-toolchain-sources.sh
+++ b/build/tools/download-toolchain-sources.sh
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 #  This shell script is used to download the sources of the Android NDK toolchain
-#  from the git server at android.git.kernel.org and package them in a nice tarball
+#  from the git server at android.googlesource.com and package them in a nice tarball
 #  that can later be used with the 'built-toolchain.sh' script.
 #
 
@@ -42,14 +42,11 @@
 GITCMD=git
 register_var_option "--git=<executable>" GITCMD "Use this version of the git tool"
 
-OPTION_GIT_HTTP=no
-register_var_option "--git-http" OPTION_GIT_HTTP "Use http to download sources from git"
-
-OPTION_GIT_BASE=
+OPTION_GIT_BASE=https://android.googlesource.com/toolchain
 register_var_option "--git-base=<git-uri>" OPTION_GIT_BASE "Use specific git repository base"
 
 OPTION_GIT_REFERENCE=
-register_var_option "--git-reference=<path>" OPTION_GIT_REFERENCE "Use local git reference base"
+register_var_option "--git-reference=<path>" OPTION_GIT_REFERENCE "Use local git reference"
 
 OPTION_PACKAGE=no
 register_var_option "--package" OPTION_PACKAGE "Create source package in /tmp/ndk-$USER"
@@ -59,7 +56,7 @@
 
 PROGRAM_PARAMETERS="<src-dir>"
 PROGRAM_DESCRIPTION=\
-"Download the NDK toolchain sources from android.git.kernel.org into <src-dir>.
+"Download the NDK toolchain sources from android.googlesource.com into <src-dir>.
 You will need to run this script before being able to rebuilt the NDK toolchain
 binaries from scratch with build/tools/build-gcc.sh."
 
@@ -67,7 +64,7 @@
   PROGRAM_DESCRIPTION="$PROGRAM_DESCRIPTION\
 
 
-By default, this script will download sources from android.git.kernel.org that
+By default, this script will download sources from android.googlesource.com that
 correspond to the date of $TOOLCHAIN_GIT_DATE. If you want to use the tip of
 tree, use '--git-date=now' instead.
 
@@ -84,11 +81,6 @@
 
 extract_parameters "$@"
 
-if [ -n "$OPTION_GIT_BASE" -a "$OPTION_GIT_HTTP" = "yes" ] ; then
-    echo "ERROR: You can't use --git-base and --git-http at the same time."
-    exit 1
-fi
-
 # Check that 'git' works
 $GITCMD --version > /dev/null 2>&1
 if [ $? != 0 ] ; then
@@ -118,15 +110,7 @@
 fail_panic "Could not create temporary directory: $TMPDIR"
 
 # prefix used for all clone operations
-if [ -n "$OPTION_GIT_BASE" ] ; then
-    GITPREFIX="$OPTION_GIT_BASE"
-else
-    GITPROTO=git
-    if [ "$OPTION_GIT_HTTP" = "yes" ] ; then
-        GITPROTO=http
-    fi
-    GITPREFIX=${GITPROTO}://android.git.kernel.org/toolchain
-fi
+GITPREFIX="$OPTION_GIT_BASE"
 dump "Using git clone prefix: $GITPREFIX"
 
 GITREFERENCE=
diff --git a/build/tools/package-release.sh b/build/tools/package-release.sh
index 84b85a6..524751d 100755
--- a/build/tools/package-release.sh
+++ b/build/tools/package-release.sh
@@ -303,6 +303,9 @@
     fail_panic "Could not copy platform files. Aborting."
 fi
 
+# 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/samples/*/{obj,libs,build.xml,local.properties,Android.mk} &&
 rm -rf $REFERENCE/tests/build/*/{obj,libs} &&
diff --git a/docs/CHANGES.html b/docs/CHANGES.html
index 0cc8813..31855d5 100644
--- a/docs/CHANGES.html
+++ b/docs/CHANGES.html
@@ -213,6 +213,9 @@
   on a non-stable ABI symbol (e.g. any libgcc.a symbol that changes
   each time the toolchain used to build the platform is changed).
 
+- download-toolchain-sources.sh: Script was updated to download the toolchain
+  sources from android.googlesource.com, the new location for AOSP servers.
+
 -------------------------------------------------------------------------------
 android-ndk-r6b
 
diff --git a/docs/DEVELOPMENT.html b/docs/DEVELOPMENT.html
index ec591ab..504efce 100644
--- a/docs/DEVELOPMENT.html
+++ b/docs/DEVELOPMENT.html
@@ -19,8 +19,8 @@
 
   mkdir workdir
   cd workdir
-  git clone git://android.git.kernel.org/platform/ndk.git ndk
-  git clone git://android.git.kernel.org/platform/development.git development
+  git clone https://android.googlesource.com/platform/ndk.git ndk
+  git clone https://android.googlesource.com/platform/development.git development
   export NDK=`pwd`/ndk
 
 
@@ -77,7 +77,7 @@
 
       The NDK comes with several scripts that can be used to rebuild the
       binaries from scratch, after downloading their sources from
-      android.git.kernel.org.
+      android.googlesource.com.
 
       There are several ways to do that, the most naive one, which will
       always work but will be *very* long (expect a few hours on a typical
@@ -88,7 +88,7 @@
       This will perform all the steps required to rebuild the binaries,
       which include:
 
-        - downloading the sources from android.git.kernel.org
+        - downloading the sources from android.googlesource.com
         - patching them with appropriate changes, if needed
         - rebuilding everything from scratch
         - copying the generated binaries to the proper location under $NDK
diff --git a/docs/LICENSES.html b/docs/LICENSES.html
index e9a7a34..8db658c 100644
--- a/docs/LICENSES.html
+++ b/docs/LICENSES.html
@@ -3,7 +3,8 @@
 
 Note that the public Android NDK release packages also contain prebuilt binaries
 for the compiler, linker, archiver, etc... The source code for the toolchain is
-available at http://android.git.kernel.org/pub
+available at android.googlesource.com (you can use the script under
+build/tools/download-toolchain-sources.sh to download it automatically).
 
 The prebuilt binaries are covered by either the GNU General Public License (GPL),
 or the GNU Lesser General Public License (LGPL). For details, see the files
diff --git a/sources/cxx-stl/gnu-libstdc++/Android.mk b/sources/cxx-stl/gnu-libstdc++/Android.mk
index eb4e4cb..e959dbd 100644
--- a/sources/cxx-stl/gnu-libstdc++/Android.mk
+++ b/sources/cxx-stl/gnu-libstdc++/Android.mk
@@ -14,4 +14,5 @@
 LOCAL_EXPORT_CPPFLAGS := -fexceptions -frtti
 LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include \
                            $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/include
+LOCAL_EXPORT_LDLIBS := $(LOCAL_PATH)/libs/$(TARGET_ARCH_ABI)/libsupc++.a
 include $(PREBUILT_SHARED_LIBRARY)
diff --git a/tests/device/exceptions-crash/jni/Android.mk b/tests/device/exceptions-crash/jni/Android.mk
index 69adc4b..e767690 100644
--- a/tests/device/exceptions-crash/jni/Android.mk
+++ b/tests/device/exceptions-crash/jni/Android.mk
@@ -1,7 +1,29 @@
 LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
-LOCAL_MODULE := test_exception_crash
-LOCAL_SRC_FILES := main.cpp
+LOCAL_MODULE := libfoo_static
+LOCAL_SRC_FILES := foo.cpp
 LOCAL_CPP_FEATURES := exceptions
+LOCAL_SHARED_LIBRARIES := gnustl_static
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := test_exception_crash_static
+LOCAL_SRC_FILES := main.cpp
+LOCAL_SHARED_LIBRARIES := libfoo_static
 include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libfoo_shared
+LOCAL_SRC_FILES := foo.cpp
+LOCAL_CPP_FEATURES := exceptions
+LOCAL_SHARED_LIBRARIES := gnustl_shared
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := test_exception_crash_shared
+LOCAL_SRC_FILES := main.cpp
+LOCAL_SHARED_LIBRARIES := libfoo_shared
+include $(BUILD_EXECUTABLE)
+
+$(call import-module,cxx-stl/gnu-libstdc++)
\ No newline at end of file
diff --git a/tests/device/exceptions-crash/jni/Application.mk b/tests/device/exceptions-crash/jni/Application.mk
index 3563119..a0e3100 100644
--- a/tests/device/exceptions-crash/jni/Application.mk
+++ b/tests/device/exceptions-crash/jni/Application.mk
@@ -1,2 +1,2 @@
 APP_ABI := all
-APP_STL := gnustl_static
+APP_STL := none
diff --git a/tests/device/exceptions-crash/jni/foo.cpp b/tests/device/exceptions-crash/jni/foo.cpp
new file mode 100644
index 0000000..c9a10d6
--- /dev/null
+++ b/tests/device/exceptions-crash/jni/foo.cpp
@@ -0,0 +1,15 @@
+#include <new>
+#include <exception>
+#include <cstdio>
+
+int foo(void)
+{
+    try {
+        ::printf("Hello ");
+        throw std::exception();
+    }
+    catch (std::exception e) {
+        ::printf(" World!\n");
+    }
+}
+
diff --git a/tests/device/exceptions-crash/jni/main.cpp b/tests/device/exceptions-crash/jni/main.cpp
index 0815a62..8c8578a 100644
--- a/tests/device/exceptions-crash/jni/main.cpp
+++ b/tests/device/exceptions-crash/jni/main.cpp
@@ -2,23 +2,11 @@
  * when running on Eclair or older platform releases. It will
  * always succeed on later versions of the  platform!
  */
-#include <new>
-#include <exception>
-#include <cstdio>
 
-static int foo(void)
-{
-    try {
-	::printf("Hello ");
-	throw std::exception();
-    }
-    catch (std::exception e) {
-        ::printf(" World!\n");
-    }
-}
+extern int foo(void);
 
 int main(int argc, char** argv)
 {
-    foo();
+    (void) foo();
     return 0;
 }
diff --git a/tests/device/gnustl-shared-1/README b/tests/device/gnustl-shared-1/README
new file mode 100644
index 0000000..615b700
--- /dev/null
+++ b/tests/device/gnustl-shared-1/README
@@ -0,0 +1,4 @@
+This checks that one can link against gnustl_shared and still throw exceptions
+between several binaries. I.e. one exception is thrown in libfoo.so and caught
+into the main executable.
+
diff --git a/tests/device/gnustl-shared-1/jni/Android.mk b/tests/device/gnustl-shared-1/jni/Android.mk
new file mode 100644
index 0000000..de47448
--- /dev/null
+++ b/tests/device/gnustl-shared-1/jni/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libfoo
+LOCAL_SRC_FILES := foo.cpp
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := test_gnustl_shared_link
+LOCAL_SRC_FILES := main.cpp
+LOCAL_SHARED_LIBRARIES := libfoo
+include $(BUILD_EXECUTABLE)
diff --git a/tests/device/gnustl-shared-1/jni/Application.mk b/tests/device/gnustl-shared-1/jni/Application.mk
new file mode 100644
index 0000000..8e97b4d
--- /dev/null
+++ b/tests/device/gnustl-shared-1/jni/Application.mk
@@ -0,0 +1,2 @@
+APP_STL := gnustl_shared
+APP_ABI := all
diff --git a/tests/device/gnustl-shared-1/jni/foo.cpp b/tests/device/gnustl-shared-1/jni/foo.cpp
new file mode 100644
index 0000000..89ea883
--- /dev/null
+++ b/tests/device/gnustl-shared-1/jni/foo.cpp
@@ -0,0 +1,10 @@
+#include <new>
+#include <exception>
+#include <cstdio>
+
+int foo(void)
+{
+    ::printf("Hello ");
+    throw std::exception();
+}
+
diff --git a/tests/device/gnustl-shared-1/jni/main.cpp b/tests/device/gnustl-shared-1/jni/main.cpp
new file mode 100644
index 0000000..4ed4991
--- /dev/null
+++ b/tests/device/gnustl-shared-1/jni/main.cpp
@@ -0,0 +1,15 @@
+#include <cstdio>
+#include <exception>
+
+int foo(void);
+
+int main(void)
+{
+    try {
+        (void) foo();
+    }
+    catch (std::exception e) {
+        ::printf(" World!\n");
+    }
+    return 0;
+}
\ No newline at end of file
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index 530021c..64d4161 100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -433,7 +433,7 @@
         DEVNDK_DIR=`dirname $NDK`/development/ndk
         if [ ! -d "$DEVNDK_DIR" ] ; then
             dump "ERROR: Could not find development NDK directory: $DEVNDK_DIR"
-            dump "Please clone platform/development.git from android.git.kernel.org"
+            dump "Please clone platform/development.git from android.googlesource.com"
             exit 1
         fi
         SAMPLES_DIRS="$DEVNDK_DIR/samples"