Merge "Move ndk-build into the build package."
diff --git a/ndk-build b/build/ndk-build
similarity index 94%
rename from ndk-build
rename to build/ndk-build
index 9e06186..4f2dee2 100755
--- a/ndk-build
+++ b/build/ndk-build
@@ -202,7 +202,7 @@
 if [ "$OSTYPE" = "cygwin" ] ; then
     GNUMAKE=`cygpath -u $GNUMAKE`
     PROGDIR_MIXED=`cygpath -m $PROGDIR`
-    CYGWIN_GNUMAKE=`$GNUMAKE -f "$PROGDIR_MIXED/build/core/check-cygwin-make.mk" 2>&1`
+    CYGWIN_GNUMAKE=`$GNUMAKE -f "$PROGDIR_MIXED/core/check-cygwin-make.mk" 2>&1`
     if [ $? != 0 ] ; then
         echo "ERROR: You are using a non-Cygwin compatible Make program."
         echo "Currently using: `cygpath -m $GNUMAKE`"
@@ -247,7 +247,7 @@
     {
         local VAR=$1
         local FLAGS=`gen_flags`
-        $GNUMAKE --no-print-dir -f $PROGDIR/build/core/build-local.mk $FLAGS DUMP_${VAR} | tail -1
+        $GNUMAKE --no-print-dir -f $PROGDIR/core/build-local.mk $FLAGS DUMP_${VAR} | tail -1
     }
 
     get_build_var_for_abi ()
@@ -255,7 +255,7 @@
         local VAR=$1
         local ABI=$2
         local FLAGS=`gen_flags`
-        $GNUMAKE --no-print-dir -f $PROGDIR/build/core/build-local.mk $FLAGS DUMP_${VAR} APP_ABI=${ABI} | tail -1
+        $GNUMAKE --no-print-dir -f $PROGDIR/core/build-local.mk $FLAGS DUMP_${VAR} APP_ABI=${ABI} | tail -1
     }
 
     APP_ABIS=`get_build_var APP_ABI`
@@ -267,9 +267,9 @@
             --use-cc ${TOOLCHAIN_PREFIX}gcc \
             --use-c++ ${TOOLCHAIN_PREFIX}g++ \
             --status-bugs \
-            $GNUMAKE -f $PROGDIR/build/core/build-local.mk "$@" APP_ABI=$ABI
+            $GNUMAKE -f $PROGDIR/core/build-local.mk "$@" APP_ABI=$ABI
     done
 else
-    $GNUMAKE -f $PROGDIR/build/core/build-local.mk "$@"
+    $GNUMAKE -f $PROGDIR/core/build-local.mk "$@"
 fi
 
diff --git a/build/ndk-build.cmd b/build/ndk-build.cmd
new file mode 100755
index 0000000..b43819b
--- /dev/null
+++ b/build/ndk-build.cmd
@@ -0,0 +1,3 @@
+@echo off
+set NDK_ROOT=%~dp0\..
+"%NDK_ROOT%\host-tools\bin\make.exe" -f "%NDK_ROOT%\build\core\build-local.mk" SHELL=cmd %*
diff --git a/build/tools/package.py b/build/tools/package.py
index ead726a..dd44a11 100755
--- a/build/tools/package.py
+++ b/build/tools/package.py
@@ -22,6 +22,7 @@
 import os
 import shutil
 import site
+import stat
 import subprocess
 import sys
 import tempfile
@@ -120,11 +121,40 @@
         subprocess.check_call(['tar', 'xf', package_path, '-C', out_dir])
 
 
+def make_ndk_build_shortcut(out_dir, host):
+    if host.startswith('windows'):
+        make_ndk_build_cmd_helper(out_dir)
+    else:
+        make_ndk_build_sh_helper(out_dir)
+
+
+def make_ndk_build_cmd_helper(out_dir):
+    with open(os.path.join(out_dir, 'ndk-build.cmd'), 'w') as helper:
+        helper.writelines([
+            '@echo off\n',
+            r'%~dp0\build\ndk-build.cmd %*',
+        ])
+
+
+def make_ndk_build_sh_helper(out_dir):
+    file_path = os.path.join(out_dir, 'ndk-build')
+    with open(file_path, 'w') as helper:
+        helper.writelines([
+            '#!/bin/sh\n',
+            'DIR="$(cd "$(dirname "$0")" && pwd)"\n',
+            '$DIR/build/ndk-build $*',
+        ])
+    mode = os.stat(file_path).st_mode
+    os.chmod(file_path, mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
+
+
 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)
     extract_all(package_dir, packages, extract_dir)
 
+    make_ndk_build_shortcut(extract_dir, host)
+
     host_tag = build_support.host_to_tag(host)
     package_name = '{}-{}'.format(release_name, host_tag)
     package_path = os.path.join(out_dir, package_name)
diff --git a/checkbuild.py b/checkbuild.py
index d7bc89c..69bb77d 100644
--- a/checkbuild.py
+++ b/checkbuild.py
@@ -480,12 +480,7 @@
 
 def build_build(out_dir, _):
     root_dir = build_support.ndk_path()
-    files = [
-        'build',
-        'ndk-build',
-        'ndk-build.cmd',
-    ]
-    build_support.make_package('build', files, out_dir, root_dir,
+    build_support.make_package('build', ['build'], out_dir, root_dir,
                                repo_prop_dir='build')
 
 
diff --git a/ndk-build.cmd b/ndk-build.cmd
deleted file mode 100755
index 819f9e8..0000000
--- a/ndk-build.cmd
+++ /dev/null
@@ -1,3 +0,0 @@
-@echo off
-set NDK_ROOT=%~dp0
-"%NDK_ROOT%host-tools/bin/make.exe" -f "%NDK_ROOT%build/core/build-local.mk" SHELL=cmd %*