imxtools/sbtoelf: use new method to get default xor key
[maemo-rb.git] / android / installToolchain.sh
blob05d3d82ae8cd7ff159e3a588f740ff7975872980
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 SDK_DOWNLOAD_URL="http://developer.android.com/sdk/index.html"
10 NDK_DOWNLOAD_URL="http://developer.android.com/sdk/ndk/index.html"
12 find_url() {
13 base_url="$1"
14 os="$2"
15 wget -q -O - $base_url | grep dl.google.com | sed 's/.*"\(http:\/\/.*\)".*/\1/' | grep $os | grep -v .exe # Windows hack
18 OS=`uname`
19 case $OS in
20 Linux)
21 SDK_URL=$(find_url $SDK_DOWNLOAD_URL linux)
22 NDK_URL=$(find_url $NDK_DOWNLOAD_URL linux)
23 ANDROID=tools/android
26 Darwin)
27 SDK_URL=$(find_url $SDK_DOWNLOAD_URL mac)
28 NDK_URL=$(find_url $NDK_DOWNLOAD_URL darwin)
29 ANDROID=tools/android
32 CYGWIN*)
33 SDK_URL=$(find_url $SDK_DOWNLOAD_URL windows)
34 NDK_URL=$(find_url $NDK_DOWNLOAD_URL windows)
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,platform-tool,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