blob: dedf3a785b9b1299f34086637267bec09988c809 [file] [log] [blame]
The Android Open Source Project52d4c302009-03-03 19:29:09 -08001#!/bin/bash
2# Quick semi-auto file to build Windows SDK tools.
3#
4# Limitations:
5# - Expects the emulator has been built first, will pick it up from prebuilt.
6# - Run in Cygwin
7# - Needs Cygwin package zip
8# - Expects to have one of the existing SDK (Darwin or Linux) to build the Windows one
9
10set -e # Fail this script as soon as a command fails -- fail early, fail fast
11
12# Set to 1 to force removal of old unzipped SDK. Only disable for debugging, as it
13# will make some rm/mv commands to fail.
14FORCE="1"
15
16SDK_ZIP="$1"
17DIST_DIR="$2"
18
19function die() {
20 echo "Error:" $*
21 echo "Aborting"
22 exit 1
23}
24
25function check() {
26 [ -f "$SDK_ZIP" ] || die "Pass the path of an existing Linux/Darwin SDK .zip as first parameter"
27 [ -d "$DIST_DIR" ] || die "Pass the output directory as second parameter"
28
29 # Use the BUILD_ID as SDK_NUMBER if defined, otherwise try to get it from the
30 # provided zip filename.
31 if [ -f config/build_id.make ]; then
32 BUILD_ID=`cat config/build_id.make | sed -n '/BUILD_ID=/s/^[^=]\+=\(.*\)$/\1/p'`
33 [ -n "$BUILD_ID" ] && SDK_NUMBER="$BUILD_ID"
34 fi
35 if [ -z "$SDK_NUMBER" ]; then
36 # Look for a pattern like "anything_sdknumber.extension"
37 # The pattern is now "any-thing_sdknumber_anything-else.extension"
38 #
39 # The bottom line is that the SDK number is whatever is enclosed by
40 # the LAST couple of underscores. You can have underscores *before* the
41 # SDK number if you want, but not after, e.g these are valid:
42 # android_sdk_4242_platform.zip or blah_42_.zip
43 #
44 # SDK_NUMBER will be empty if nothing matched.
45 filename=`basename "$SDK_ZIP"`
46 SDK_NUMBER=`echo $filename | sed -n 's/^.*_\([^_./]\+\)_[^_.]*\..*$/\1/p'`
47 fi
48
49 [ -n "$SDK_NUMBER" ] || die "Failed to extract the SDK number from $SDK_ZIP. Check its format."
50
51 [ $OSTYPE == "cygwin" ] || die "This expects to run under Cygwin"
52 [ -e `which zip` ] || die "Please install 'zip' package in Cygwin"
53 [ -f "build/envsetup.sh" ] || die "Please run this from the 'android' directory"
54
55 echo "Using SDK ${SDK_NUMBER}"
56}
57
58function build() {
59
60 echo
61 echo "Building..."
62 [ -n "$MAKE_OPT" ] && echo "Make options: $MAKE_OPT"
63 . build/envsetup.sh
64 make -j 4 emulator || die "Build failed"
65 # Disable parallel build: it generates "permission denied" issues when
66 # multiple "ar.exe" are running in parallel.
67 make prebuilt adb fastboot aidl aapt dexdump dmtracedump mksdcard sqlite3 || die "Build failed"
68}
69
70function package() {
71 echo
72 echo "Packaging..."
73 DEST_NAME="android-sdk_${SDK_NUMBER}_windows"
74 DEST="$DIST_DIR/$DEST_NAME"
75 DEST_NAME_ZIP="${DEST_NAME}.zip"
76
77 # Unzip current linux/mac SDK and rename using the windows name
78 if [[ -n "$FORCE" || ! -d "$DEST" ]]; then
79 [ -e "$DEST" ] && rm -rfv "$DEST" # cleanup dest first if exists
80 UNZIPPED=`basename "$SDK_ZIP"`
81 UNZIPPED="$DIST_DIR/${UNZIPPED/.zip/}"
82 [ -e "$UNZIPPED" ] && rm -rfv "$UNZIPPED" # cleanup unzip dir (if exists)
83 unzip "$SDK_ZIP" -d "$DIST_DIR"
84 mv -v "$UNZIPPED" "$DEST"
85 fi
86
87 # Assert that the package contains only one platform
88 PLATFORMS="$DEST/platforms"
89 THE_PLATFORM=`echo $PLATFORMS/*`
90 PLATFORM_TOOLS=$THE_PLATFORM/tools
91 echo "Platform found: " $THE_PLATFORM
92 [[ -d "$THE_PLATFORM" ]] || die \
93 "Error: One platform was expected in $SDK_ZIP. " \
94 "Instead found " $THE_PLATFORM
95 [[ -d "$PLATFORM_TOOLS" ]] || die "Missing folder $PLATFORM_TOOLS."
96
97
98 # USB Driver for ADB
99 mkdir -pv $DEST/usb_driver/x86
100 cp -rv development/host/windows/prebuilt/usb/driver/* $DEST/usb_driver/x86/
101 mkdir -pv $DEST/usb_driver/amd64
102 cp -rv development/host/windows/prebuilt/usb/driver_amd_64/* $DEST/usb_driver/amd64/
103
104 # Remove obsolete stuff from tools & platform
105 TOOLS="$DEST/tools"
106 LIB="$DEST/tools/lib"
107 rm -v "$TOOLS"/{adb,emulator,traceview,draw9patch,hierarchyviewer,apkbuilder,ddms,dmtracedump,mksdcard,sqlite3,android}
108 rm -v --force "$LIB"/*.so "$LIB"/*.jnilib
109 rm -v "$PLATFORM_TOOLS"/{aapt,aidl,dx,dexdump}
110
111
112 # Copy all the new stuff in tools
113 # Note: some tools are first copied here and then moved in platforms/<name>/tools/
114 cp -v out/host/windows-x86/bin/*.{exe,dll} "$TOOLS"
115 cp -v prebuilt/windows/swt/*.{jar,dll} "$LIB"
116
117 # If you want the emulator NOTICE in the tools dir, uncomment the following line:
118 # cp -v external/qemu/NOTICE "$TOOLS"/emulator_NOTICE.txt
119
120 # We currently need libz from MinGW for aapt
121 cp -v /cygdrive/c/cygwin/bin/mgwz.dll "$TOOLS"
122
123 # Update a bunch of bat files
124 cp -v development/tools/apkbuilder/etc/apkbuilder.bat "$TOOLS"
125 cp -v development/tools/ddms/app/etc/ddms.bat "$TOOLS"
126 cp -v development/tools/traceview/etc/traceview.bat "$TOOLS"
127 cp -v development/tools/hierarchyviewer/etc/hierarchyviewer.bat "$TOOLS"
128 cp -v development/tools/draw9patch/etc/draw9patch.bat "$TOOLS"
129 cp -v development/tools/sdkmanager/app/etc/android.bat "$TOOLS"
130
131 # Copy or move platform specific tools to the default platform.
132 cp -v dalvik/dx/etc/dx.bat "$PLATFORM_TOOLS"
133 # Note: mgwz.dll must be in same folder than aapt.exe
134 mv -v "$TOOLS"/{aapt.exe,aidl.exe,dexdump.exe,mgwz.dll} "$PLATFORM_TOOLS"
135
136 # Fix EOL chars to make window users happy - fix all files at the top level only
137 # as well as all batch files including those in platforms/<name>/tools/
138 find "$DIST_DIR" -maxdepth 1 -type f -writable -print0 | xargs -0 unix2dos -D
139 find "$DIST_DIR" -maxdepth 3 -name "*.bat" -type f -writable -print0 | xargs -0 unix2dos -D
140
141 # Done.. Zip it
142 pushd "$DIST_DIR" > /dev/null
143 [ -e "$DEST_NAME_ZIP" ] && rm -rfv "$DEST_NAME_ZIP"
144 zip -9r "$DEST_NAME_ZIP" "$DEST_NAME" && rm -rfv "$DEST_NAME"
145 popd > /dev/null
146 echo "Done"
147 echo
148 echo "Resulting SDK is in $DIST_DIR/$DEST_NAME_ZIP"
149
150 # We want fastboot and adb next to the new SDK
151 for i in fastboot.exe adb.exe AdbWinApi.dll; do
152 mv -vf out/host/windows-x86/bin/$i "$DIST_DIR"/$i
153 done
154}
155
156check
157build
158package
159
160echo "Done"