Fix oops in r30242. I didn't want to change/reduce the buffer size.
[maemo-rb.git] / android / installToolchain.sh
blob18b21432480d6a41a0e760d2eb4c73542c335cb5
1 #!/bin/bash
3 # Abort execution as soon as an error is encountered
4 # That way the script do not let the user think the process completed correctly
5 # and leave the opportunity to fix the problem and restart compilation where
6 # it stopped
7 set -e
9 # http://developer.android.com/sdk/index.html
10 SDK_URL_LNX="http://dl.google.com/android/android-sdk_r11-linux_x86.tgz"
11 SDK_URL_MAC="http://dl.google.com/android/android-sdk_r11-mac_x86.zip"
12 SDK_URL_WIN="http://dl.google.com/android/android-sdk_r11-windows.zip"
13 # http://developer.android.com/sdk/ndk/index.html
14 NDK_URL_LNX="http://dl.google.com/android/ndk/android-ndk-r5c-linux-x86.tar.bz2"
15 NDK_URL_MAC="http://dl.google.com/android/ndk/android-ndk-r5c-darwin-x86.tar.bz2"
16 NDK_URL_WIN="http://dl.google.com/android/ndk/android-ndk-r5c-windows.zip"
18 OS=`uname`
19 case $OS in
20 Linux)
21 SDK_URL=$SDK_URL_LNX
22 NDK_URL=$NDK_URL_LNX
23 ANDROID=tools/android
26 Darwin)
27 SDK_URL=$SDK_URL_MAC
28 NDK_URL=$NDK_URL_MAC
29 ANDROID=tools/android
32 CYGWIN*)
33 SDK_URL=$SDK_URL_WIN
34 NDK_URL=$NDK_URL_WIN
35 ANDROID=tools/android.bat
37 esac
39 prefix="${INSTALL_PREFIX:-$HOME}"
40 dldir="${DOWNLOAD_DIR:-/tmp}"
42 SDK_PATH=$(find $prefix -maxdepth 1 -name "android-sdk-*")
43 NDK_PATH=$(find $prefix -maxdepth 1 -name "android-ndk-*")
45 download_and_extract() {
46 url="$1"
47 name=${url##*/}
48 local_file="$dldir/$name"
49 if [ \! -f "$local_file" ]; then
50 echo " * Downloading $name..."
51 wget -O "$local_file" $1
54 echo " * Extracting $name..."
55 case ${local_file#*.} in
56 zip)
57 unzip -qo -d "$prefix" "$local_file"
59 tgz|tar.gz)
60 (cd $prefix; tar -xf "$local_file")
62 tar.bz2)
63 (cd $prefix; tar -xjf "$local_file")
66 echo "Couldn't figure out how to extract $local_file" ! 1>&2
68 esac
71 if [ -z "$SDK_PATH" ]; then
72 download_and_extract $SDK_URL
73 # OS X doesn't know about realname, use basename instead.
74 SDK_PATH=$prefix/$(basename $prefix/android-sdk-*)
76 if [ -z "$NDK_PATH" ]; then
77 download_and_extract $NDK_URL
78 NDK_PATH=$prefix/$(basename $prefix/android-ndk-*)
81 if [ -z "$(find $SDK_PATH/platforms -type d -name 'android-*')" ]; then
82 echo " * Installing Android platforms..."
83 $SDK_PATH/$ANDROID update sdk --no-ui --filter platform,tool
86 cat <<EOF
87 * All done!
89 Please set the following environment variables before running tools/configure:
90 export ANDROID_SDK_PATH=$SDK_PATH
91 export ANDROID_NDK_PATH=$NDK_PATH
93 EOF