blob: e0c5d3a5f27921b7200d13622fa82fe636a2bf17 [file] [log] [blame]
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +00001#!/bin/bash
2
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
7set -e
8
9# http://developer.android.com/sdk/index.html
10SDK_URL="http://dl.google.com/android/android-sdk_r07-linux_x86.tgz"
11# http://developer.android.com/sdk/ndk/index.html
Jonathan Gordonf51d6e62010-12-08 05:05:43 +000012NDK_URL="http://dl.google.com/android/ndk/android-ndk-r5-linux-x86.tar.bz2"
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000013
14prefix="${INSTALL_PREFIX:-$HOME}"
15dldir="${DOWNLOAD_DIR:-/tmp}"
16
17SDK_PATH=$(find $prefix -maxdepth 1 -name "android-sdk-*")
18NDK_PATH=$(find $prefix -maxdepth 1 -name "android-ndk-*")
19
20download_and_extract() {
21 url="$1"
22 name=${url##*/}
23 local_file="$dldir/$name"
24 if [ \! -f "$local_file" ]; then
25 echo " * Downloading $name..."
26 wget -O "$local_file" $1
27 fi
28
29 echo " * Extracting $name..."
30 case ${local_file#*.} in
31 zip)
32 unzip -qo -d "$prefix" "$local_file"
33 ;;
34 tgz|tar.gz)
35 (cd $prefix; tar -xf "$local_file")
36 ;;
Jonathan Gordonf51d6e62010-12-08 05:05:43 +000037 tar.bz2)
38 (cd $prefix; tar -xjf "$local_file")
39 ;;
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000040 *)
41 echo "Couldn't figure out how to extract $local_file" ! 1>&2
42 ;;
43 esac
44}
45
46if [ -z "$SDK_PATH" ]; then
47 download_and_extract $SDK_URL
48 SDK_PATH=$(realpath $prefix/android-sdk-*)
49fi
50if [ -z "$NDK_PATH" ]; then
51 download_and_extract $NDK_URL
52 NDK_PATH=$(realpath $prefix/android-ndk-*)
53fi
54
55if [ -z "$(find $SDK_PATH/platforms -type d -name 'android-*')" ]; then
56 echo " * Installing Android platforms..."
57 $SDK_PATH/tools/android update sdk --no-ui --filter platform,tool
58fi
59
60cat <<EOF
61 * All done!
62
63Please set the following environment variables before running tools/configure:
64export \$ANDROID_SDK_PATH=$SDK_PATH
65export \$ANDROID_NDK_PATH=$NDK_PATH
66
67EOF