blob: a70d74a2822917e202e0119cacfe4d3ce0f3a20f [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.
Raphael Moll3ae12362009-03-31 17:19:15 -070067 make prebuilt adb fastboot aidl aapt dexdump dmtracedump hprof-conv mksdcard sqlite3 \
68 || die "Build failed"
The Android Open Source Project52d4c302009-03-03 19:29:09 -080069}
70
71function package() {
72 echo
73 echo "Packaging..."
74 DEST_NAME="android-sdk_${SDK_NUMBER}_windows"
75 DEST="$DIST_DIR/$DEST_NAME"
76 DEST_NAME_ZIP="${DEST_NAME}.zip"
77
78 # Unzip current linux/mac SDK and rename using the windows name
79 if [[ -n "$FORCE" || ! -d "$DEST" ]]; then
80 [ -e "$DEST" ] && rm -rfv "$DEST" # cleanup dest first if exists
81 UNZIPPED=`basename "$SDK_ZIP"`
82 UNZIPPED="$DIST_DIR/${UNZIPPED/.zip/}"
83 [ -e "$UNZIPPED" ] && rm -rfv "$UNZIPPED" # cleanup unzip dir (if exists)
84 unzip "$SDK_ZIP" -d "$DIST_DIR"
85 mv -v "$UNZIPPED" "$DEST"
86 fi
87
88 # Assert that the package contains only one platform
89 PLATFORMS="$DEST/platforms"
90 THE_PLATFORM=`echo $PLATFORMS/*`
91 PLATFORM_TOOLS=$THE_PLATFORM/tools
92 echo "Platform found: " $THE_PLATFORM
93 [[ -d "$THE_PLATFORM" ]] || die \
94 "Error: One platform was expected in $SDK_ZIP. " \
95 "Instead found " $THE_PLATFORM
96 [[ -d "$PLATFORM_TOOLS" ]] || die "Missing folder $PLATFORM_TOOLS."
97
98
99 # USB Driver for ADB
100 mkdir -pv $DEST/usb_driver/x86
101 cp -rv development/host/windows/prebuilt/usb/driver/* $DEST/usb_driver/x86/
102 mkdir -pv $DEST/usb_driver/amd64
103 cp -rv development/host/windows/prebuilt/usb/driver_amd_64/* $DEST/usb_driver/amd64/
104
105 # Remove obsolete stuff from tools & platform
106 TOOLS="$DEST/tools"
107 LIB="$DEST/tools/lib"
Raphael Moll3ae12362009-03-31 17:19:15 -0700108 rm -v "$TOOLS"/{adb,emulator,traceview,draw9patch,hierarchyviewer,apkbuilder,ddms,dmtracedump,hprof-conv,mksdcard,sqlite3,android}
The Android Open Source Project52d4c302009-03-03 19:29:09 -0800109 rm -v --force "$LIB"/*.so "$LIB"/*.jnilib
110 rm -v "$PLATFORM_TOOLS"/{aapt,aidl,dx,dexdump}
111
112
113 # Copy all the new stuff in tools
114 # Note: some tools are first copied here and then moved in platforms/<name>/tools/
115 cp -v out/host/windows-x86/bin/*.{exe,dll} "$TOOLS"
116 cp -v prebuilt/windows/swt/*.{jar,dll} "$LIB"
117
118 # If you want the emulator NOTICE in the tools dir, uncomment the following line:
119 # cp -v external/qemu/NOTICE "$TOOLS"/emulator_NOTICE.txt
120
121 # We currently need libz from MinGW for aapt
122 cp -v /cygdrive/c/cygwin/bin/mgwz.dll "$TOOLS"
123
124 # Update a bunch of bat files
125 cp -v development/tools/apkbuilder/etc/apkbuilder.bat "$TOOLS"
126 cp -v development/tools/ddms/app/etc/ddms.bat "$TOOLS"
127 cp -v development/tools/traceview/etc/traceview.bat "$TOOLS"
128 cp -v development/tools/hierarchyviewer/etc/hierarchyviewer.bat "$TOOLS"
129 cp -v development/tools/draw9patch/etc/draw9patch.bat "$TOOLS"
130 cp -v development/tools/sdkmanager/app/etc/android.bat "$TOOLS"
Xavier Ducrohet2e82cdc2009-04-17 11:41:48 -0700131
Xavier Ducrohet1a2b2f02009-04-20 11:01:18 -0700132 # Put the JetCreator tools, content and docs (not available in the linux SDK)
133 JET="$TOOLS/Jet"
134 JETCREATOR="$JET/JetCreator"
135 JETDEMOCONTENT="$JET/demo_content"
136 JETLOGICTEMPLATES="$JET/logic_templates"
Xavier Ducrohet2e82cdc2009-04-17 11:41:48 -0700137 JETDOC="$DEST/docs/JetCreator"
138
139 # need to rm these folders since a Mac SDK will have them and it would create a conflict
Xavier Ducrohet1a2b2f02009-04-20 11:01:18 -0700140 rm -rfv "$JET"
Xavier Ducrohet2e82cdc2009-04-17 11:41:48 -0700141 rm -rfv "$JETDOC"
142
143 # now create fresh folders for JetCreator
Xavier Ducrohet1a2b2f02009-04-20 11:01:18 -0700144 mkdir "$JET"
Xavier Ducrohet2e82cdc2009-04-17 11:41:48 -0700145 mkdir "$JETDOC"
146
Raphael Moll00e25d42009-04-19 09:42:01 -0700147 cp -rv external/sonivox/jet_tools/JetCreator "$JETCREATOR"
Xavier Ducrohet1a2b2f02009-04-20 11:01:18 -0700148 cp -v prebuilt/windows/jetcreator/EASDLL.dll "$JETCREATOR"
149 cp -v prebuilt/windows/jetcreator/EASDLL.dll "$JETCREATOR"
150 cp -rv external/sonivox/jet_tools/JetCreator_content "$JETDEMOCONTENT"
151 cp -rv external/sonivox/jet_tools/logic_templates "$JETLOGICTEMPLATES"
152
153 cp -v external/sonivox/docs/JET_Authoring_Guidelines.html "$JETDOC"/
154 cp -rv external/sonivox/docs/JET_Authoring_Guidelines_files "$JETDOC"/
155 cp -v external/sonivox/docs/JET_Creator_User_Manual.html "$JETDOC"/
156 cp -rv external/sonivox/docs/JET_Creator_User_Manual_files "$JETDOC"/
The Android Open Source Project52d4c302009-03-03 19:29:09 -0800157
158 # Copy or move platform specific tools to the default platform.
159 cp -v dalvik/dx/etc/dx.bat "$PLATFORM_TOOLS"
160 # Note: mgwz.dll must be in same folder than aapt.exe
161 mv -v "$TOOLS"/{aapt.exe,aidl.exe,dexdump.exe,mgwz.dll} "$PLATFORM_TOOLS"
162
163 # Fix EOL chars to make window users happy - fix all files at the top level only
164 # as well as all batch files including those in platforms/<name>/tools/
165 find "$DIST_DIR" -maxdepth 1 -type f -writable -print0 | xargs -0 unix2dos -D
166 find "$DIST_DIR" -maxdepth 3 -name "*.bat" -type f -writable -print0 | xargs -0 unix2dos -D
167
168 # Done.. Zip it
169 pushd "$DIST_DIR" > /dev/null
170 [ -e "$DEST_NAME_ZIP" ] && rm -rfv "$DEST_NAME_ZIP"
171 zip -9r "$DEST_NAME_ZIP" "$DEST_NAME" && rm -rfv "$DEST_NAME"
172 popd > /dev/null
173 echo "Done"
174 echo
175 echo "Resulting SDK is in $DIST_DIR/$DEST_NAME_ZIP"
176
177 # We want fastboot and adb next to the new SDK
178 for i in fastboot.exe adb.exe AdbWinApi.dll; do
179 mv -vf out/host/windows-x86/bin/$i "$DIST_DIR"/$i
180 done
181}
182
183check
184build
185package
186
187echo "Done"