Win SDK: Split the win-sdk makefile and script into 2 parts.

The main makefile+scripts to build the Windows SDK is still this
one here in development/build/tools. However it defers to a new
matching set of files in sdk/build to build and package
things that depend on the sdk.git or external/qemu.git.

This will make it easier for us to prepare SDKs based on
a tools_rN branch that isn't cut at the same time than the
platform branch.

This is a multi-part changeset. The other part is in sdk.git.

This change also definitely removes support for building
the Windows SDK under Cygwin. Only building a specific subset
of individual binaries is supported at this point.

Change-Id: I4e9a2d810cf29fae0097fbd92be0cef89c9b3505
diff --git a/build/tools/patch_windows_sdk.sh b/build/tools/patch_windows_sdk.sh
index 2d3c707..3d9277a 100755
--- a/build/tools/patch_windows_sdk.sh
+++ b/build/tools/patch_windows_sdk.sh
@@ -1,13 +1,41 @@
 #!/bin/bash
 
+# This script takes a Linux SDK, cleans it and injects the necessary Windows
+# binaries needed by the SDK. The script has 2 parts:
+# - development/tools/build/path_windows_sdk.sh to process the
+#   platform-dependent folders and files.
+# - sdk/build/patch_windows_sdk.sh to process folder and files which
+#   depend on the sdk.git repo. This file will be invoked by this one.
+#
+# Input arguments:
+# -q = Optional arg to make this silent. Must be given first.
+# $1 = Temporary SDK directory, that is the Linux SDK being patched into
+#      a Windows one.
+# $2 = The out/host/windows directory, which contains the new Windows
+#      binaries to use.
+# $3 = An optional replacement for $TOPDIR (inherited from the Android
+#      build system), which is the top directory where Android is located.
+
 # Verbose by default. Use -q to make more silent.
 V="-v"
-if [[ "$1" == "-q" ]]; then V=""; shift; fi
+Q=""
+if [[ "$1" == "-q" ]]; then
+    Q="$1"
+    V=""
+    shift
+fi
 
 TEMP_SDK_DIR=$1
 WIN_OUT_DIR=$2
 TOPDIR=${TOPDIR:-$3}
 
+# The unix2dos is provided by the APT package "tofrodos". However
+# as for ubuntu lucid, the package renamed the command to "todos".
+UNIX2DOS=`which unix2dos`
+if [[ ! -x $UNIX2DOS ]]; then
+  UNIX2DOS=`which todos`
+fi
+
 PLATFORMS=( $TEMP_SDK_DIR/platforms/* )
 if [[ ${#PLATFORMS[@]} != 1 ]]; then
     echo "Error: Too many platforms found in $TEMP_SDK_DIR"
@@ -25,8 +53,7 @@
 TOOLS=$TEMP_SDK_DIR/tools
 PLATFORM_TOOLS=$TEMP_SDK_DIR/platform-tools
 LIB=$TEMP_SDK_DIR/tools/lib
-rm $V $TOOLS/{android,apkbuilder,ddms,dmtracedump,draw9patch,emulator,etc1tool}
-rm $V $TOOLS/{hierarchyviewer,hprof-conv,layoutopt,mksdcard,sqlite3,traceview,zipalign,monkeyrunner}
+rm $V $TOOLS/{dmtracedump,etc1tool,hprof-conv,sqlite3,zipalign}
 rm $V $TOOLS/proguard/bin/*.sh
 rm $V $LIB/*/swt.jar
 rm $V $PLATFORM_TOOLS/{adb,aapt,aidl,dx,dexdump}
@@ -39,30 +66,6 @@
 mkdir -pv $LIB/x86_64
 cp $V ${TOPDIR}prebuilt/windows-x86_64/swt/swt.jar  $LIB/x86_64/
 
-# Copy the SDK Manager (aka sdklauncher) to the root of the SDK (it was copied in tools above)
-# and move it also in SDK/tools/lib (so that tools updates can update the root one too)
-cp $TOOLS/sdklauncher.exe $TEMP_SDK_DIR/"SDK Manager.exe"
-mv $TOOLS/sdklauncher.exe $LIB/"SDK Manager.exe"
-
-# Copy the emulator NOTICE in the tools dir
-cp $V ${TOPDIR}external/qemu/NOTICE $TOOLS/emulator_NOTICE.txt
-
-# aapt under cygwin needs to have mgwz.dll
-[[ -n $NEED_MGWZ ]] && cp $V $CYG_MGWZ_PATH $TOOLS/
-
-# Update a bunch of bat files
-cp $V ${TOPDIR}sdk/files/post_tools_install.bat                 $LIB/
-cp $V ${TOPDIR}sdk/files/find_java.bat                          $LIB/
-cp $V ${TOPDIR}sdk/apkbuilder/etc/apkbuilder.bat                $TOOLS/
-cp $V ${TOPDIR}sdk/ddms/app/etc/ddms.bat                        $TOOLS/
-cp $V ${TOPDIR}sdk/traceview/etc/traceview.bat                  $TOOLS/
-cp $V ${TOPDIR}sdk/hierarchyviewer2/app/etc/hierarchyviewer.bat $TOOLS/
-cp $V ${TOPDIR}sdk/layoutopt/app/etc/layoutopt.bat              $TOOLS/
-cp $V ${TOPDIR}sdk/draw9patch/etc/draw9patch.bat                $TOOLS/
-cp $V ${TOPDIR}sdk/sdkmanager/app/etc/android.bat               $TOOLS/
-cp $V ${TOPDIR}sdk/monkeyrunner/etc/monkeyrunner.bat            $TOOLS/
-cp $V ${TOPDIR}sdk/files/proguard/bin/*.bat                     $TOOLS/proguard/bin/
-
 # Put the JetCreator tools, content and docs (not available in the linux SDK)
 JET=$TOOLS/Jet
 JETCREATOR=$JET/JetCreator
@@ -93,14 +96,15 @@
 cp $V ${TOPDIR}dalvik/dx/etc/dx.bat $PLATFORM_TOOLS/
 mv $V $TOOLS/{adb.exe,aapt.exe,aidl.exe,dexdump.exe} $TOOLS/Adb*.dll $PLATFORM_TOOLS/
 
-# When building under cygwin, mgwz.dll must be both in SDK/tools for zipalign
-# and in SDK/platform/XYZ/tools/ for aapt
-[[ -n $NEED_MGWZ ]] && cp $V $TOOLS/mgwz.dll $PLATFORM_TOOLS/
-
 # Fix EOL chars to make window users happy - fix all files at the top level
 # as well as all batch files including those in platforms/<name>/tools/
-find $TEMP_SDK_DIR -maxdepth 1 -name "*.[ht]*" -type f -print0 | xargs -0 unix2dos
-find $TEMP_SDK_DIR -maxdepth 3 -name "*.bat"   -type f -print0 | xargs -0 unix2dos
+if [[ -x $UNIX2DOS ]]; then
+  find $TEMP_SDK_DIR -maxdepth 1 -name "*.[ht]*" -type f -print0 | xargs -0 $UNIX2DOS
+  find $TEMP_SDK_DIR -maxdepth 3 -name "*.bat"   -type f -print0 | xargs -0 $UNIX2DOS
+fi
+
+# Execute the packaging script in the sdk directory
+${TOPDIR}sdk/build/patch_windows_sdk.sh $Q ${TEMP_SDK_DIR} ${WIN_OUT_DIR} ${TOPDIR}
 
 # Just to make it easier on the build servers, we want fastboot and adb (and its DLLs)
 # next to the new SDK, so up one dir.