blob: 3cdf27b9cd36029374c906348b6fa26ecf613e8c [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
Maurus Cuelenaere82fa47d2011-08-20 11:11:49 +00009SDK_DOWNLOAD_URL="http://developer.android.com/sdk/index.html"
10NDK_DOWNLOAD_URL="http://developer.android.com/sdk/ndk/index.html"
11
12find_url() {
13 base_url="$1"
14 os="$2"
Thomas Martitz4262e642014-03-10 07:33:18 +010015 wget -q -O - $base_url | grep dl.google.com | sed 's/.*"\(http:\/\/.*\)".*/\1/' | grep $os | grep -v bundle | grep -v .exe # Windows hack
Maurus Cuelenaere82fa47d2011-08-20 11:11:49 +000016}
Dominik Riebelinga3ed2c12011-06-11 20:22:14 +000017
18OS=`uname`
19case $OS in
20 Linux)
Maurus Cuelenaere82fa47d2011-08-20 11:11:49 +000021 SDK_URL=$(find_url $SDK_DOWNLOAD_URL linux)
22 NDK_URL=$(find_url $NDK_DOWNLOAD_URL linux)
Dominik Riebelinga3ed2c12011-06-11 20:22:14 +000023 ANDROID=tools/android
24 ;;
25
26 Darwin)
Maurus Cuelenaere82fa47d2011-08-20 11:11:49 +000027 SDK_URL=$(find_url $SDK_DOWNLOAD_URL mac)
28 NDK_URL=$(find_url $NDK_DOWNLOAD_URL darwin)
Dominik Riebelinga3ed2c12011-06-11 20:22:14 +000029 ANDROID=tools/android
30 ;;
31
32 CYGWIN*)
Maurus Cuelenaere82fa47d2011-08-20 11:11:49 +000033 SDK_URL=$(find_url $SDK_DOWNLOAD_URL windows)
34 NDK_URL=$(find_url $NDK_DOWNLOAD_URL windows)
Dominik Riebelinga3ed2c12011-06-11 20:22:14 +000035 ANDROID=tools/android.bat
36 ;;
37esac
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000038
39prefix="${INSTALL_PREFIX:-$HOME}"
40dldir="${DOWNLOAD_DIR:-/tmp}"
41
42SDK_PATH=$(find $prefix -maxdepth 1 -name "android-sdk-*")
43NDK_PATH=$(find $prefix -maxdepth 1 -name "android-ndk-*")
44
45download_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
52 fi
53
54 echo " * Extracting $name..."
Thomas Martitz4262e642014-03-10 07:33:18 +010055 case ${local_file} in
56 *.zip)
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000057 unzip -qo -d "$prefix" "$local_file"
58 ;;
Thomas Martitz4262e642014-03-10 07:33:18 +010059 *.tgz|*.tar.gz)
60 (cd $prefix; tar -xzf "$local_file")
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000061 ;;
Thomas Martitz4262e642014-03-10 07:33:18 +010062 *.tar.bz2)
Jonathan Gordonf51d6e62010-12-08 05:05:43 +000063 (cd $prefix; tar -xjf "$local_file")
64 ;;
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000065 *)
66 echo "Couldn't figure out how to extract $local_file" ! 1>&2
67 ;;
68 esac
69}
70
71if [ -z "$SDK_PATH" ]; then
72 download_and_extract $SDK_URL
Dominik Riebelinga3ed2c12011-06-11 20:22:14 +000073 # OS X doesn't know about realname, use basename instead.
74 SDK_PATH=$prefix/$(basename $prefix/android-sdk-*)
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000075fi
76if [ -z "$NDK_PATH" ]; then
77 download_and_extract $NDK_URL
Dominik Riebelinga3ed2c12011-06-11 20:22:14 +000078 NDK_PATH=$prefix/$(basename $prefix/android-ndk-*)
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000079fi
80
81if [ -z "$(find $SDK_PATH/platforms -type d -name 'android-*')" ]; then
82 echo " * Installing Android platforms..."
Dominik Riebeling385af792011-09-08 17:37:01 +000083 $SDK_PATH/$ANDROID update sdk --no-ui --filter platform,platform-tool,tool
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000084fi
85
86cat <<EOF
87 * All done!
88
89Please set the following environment variables before running tools/configure:
Michael Stummvoll9ef99042011-01-12 12:36:52 +000090export ANDROID_SDK_PATH=$SDK_PATH
91export ANDROID_NDK_PATH=$NDK_PATH
Maurus Cuelenaereab9caea2010-11-06 17:32:52 +000092
93EOF