Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 1 | #!/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 |
| 7 | set -e |
| 8 | |
Maurus Cuelenaere | 82fa47d | 2011-08-20 11:11:49 +0000 | [diff] [blame] | 9 | SDK_DOWNLOAD_URL="http://developer.android.com/sdk/index.html" |
| 10 | NDK_DOWNLOAD_URL="http://developer.android.com/sdk/ndk/index.html" |
| 11 | |
| 12 | find_url() { |
| 13 | base_url="$1" |
| 14 | os="$2" |
Thomas Martitz | 4262e64 | 2014-03-10 07:33:18 +0100 | [diff] [blame] | 15 | wget -q -O - $base_url | grep dl.google.com | sed 's/.*"\(http:\/\/.*\)".*/\1/' | grep $os | grep -v bundle | grep -v .exe # Windows hack |
Maurus Cuelenaere | 82fa47d | 2011-08-20 11:11:49 +0000 | [diff] [blame] | 16 | } |
Dominik Riebeling | a3ed2c1 | 2011-06-11 20:22:14 +0000 | [diff] [blame] | 17 | |
| 18 | OS=`uname` |
| 19 | case $OS in |
| 20 | Linux) |
Maurus Cuelenaere | 82fa47d | 2011-08-20 11:11:49 +0000 | [diff] [blame] | 21 | SDK_URL=$(find_url $SDK_DOWNLOAD_URL linux) |
| 22 | NDK_URL=$(find_url $NDK_DOWNLOAD_URL linux) |
Dominik Riebeling | a3ed2c1 | 2011-06-11 20:22:14 +0000 | [diff] [blame] | 23 | ANDROID=tools/android |
| 24 | ;; |
| 25 | |
| 26 | Darwin) |
Maurus Cuelenaere | 82fa47d | 2011-08-20 11:11:49 +0000 | [diff] [blame] | 27 | SDK_URL=$(find_url $SDK_DOWNLOAD_URL mac) |
| 28 | NDK_URL=$(find_url $NDK_DOWNLOAD_URL darwin) |
Dominik Riebeling | a3ed2c1 | 2011-06-11 20:22:14 +0000 | [diff] [blame] | 29 | ANDROID=tools/android |
| 30 | ;; |
| 31 | |
| 32 | CYGWIN*) |
Maurus Cuelenaere | 82fa47d | 2011-08-20 11:11:49 +0000 | [diff] [blame] | 33 | SDK_URL=$(find_url $SDK_DOWNLOAD_URL windows) |
| 34 | NDK_URL=$(find_url $NDK_DOWNLOAD_URL windows) |
Dominik Riebeling | a3ed2c1 | 2011-06-11 20:22:14 +0000 | [diff] [blame] | 35 | ANDROID=tools/android.bat |
| 36 | ;; |
| 37 | esac |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 38 | |
| 39 | prefix="${INSTALL_PREFIX:-$HOME}" |
| 40 | dldir="${DOWNLOAD_DIR:-/tmp}" |
| 41 | |
| 42 | SDK_PATH=$(find $prefix -maxdepth 1 -name "android-sdk-*") |
| 43 | NDK_PATH=$(find $prefix -maxdepth 1 -name "android-ndk-*") |
| 44 | |
| 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 |
| 52 | fi |
| 53 | |
| 54 | echo " * Extracting $name..." |
Thomas Martitz | 4262e64 | 2014-03-10 07:33:18 +0100 | [diff] [blame] | 55 | case ${local_file} in |
| 56 | *.zip) |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 57 | unzip -qo -d "$prefix" "$local_file" |
| 58 | ;; |
Thomas Martitz | 4262e64 | 2014-03-10 07:33:18 +0100 | [diff] [blame] | 59 | *.tgz|*.tar.gz) |
| 60 | (cd $prefix; tar -xzf "$local_file") |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 61 | ;; |
Thomas Martitz | 4262e64 | 2014-03-10 07:33:18 +0100 | [diff] [blame] | 62 | *.tar.bz2) |
Jonathan Gordon | f51d6e6 | 2010-12-08 05:05:43 +0000 | [diff] [blame] | 63 | (cd $prefix; tar -xjf "$local_file") |
| 64 | ;; |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 65 | *) |
| 66 | echo "Couldn't figure out how to extract $local_file" ! 1>&2 |
| 67 | ;; |
| 68 | esac |
| 69 | } |
| 70 | |
| 71 | if [ -z "$SDK_PATH" ]; then |
| 72 | download_and_extract $SDK_URL |
Dominik Riebeling | a3ed2c1 | 2011-06-11 20:22:14 +0000 | [diff] [blame] | 73 | # OS X doesn't know about realname, use basename instead. |
| 74 | SDK_PATH=$prefix/$(basename $prefix/android-sdk-*) |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 75 | fi |
| 76 | if [ -z "$NDK_PATH" ]; then |
| 77 | download_and_extract $NDK_URL |
Dominik Riebeling | a3ed2c1 | 2011-06-11 20:22:14 +0000 | [diff] [blame] | 78 | NDK_PATH=$prefix/$(basename $prefix/android-ndk-*) |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 79 | fi |
| 80 | |
| 81 | if [ -z "$(find $SDK_PATH/platforms -type d -name 'android-*')" ]; then |
| 82 | echo " * Installing Android platforms..." |
Dominik Riebeling | 385af79 | 2011-09-08 17:37:01 +0000 | [diff] [blame] | 83 | $SDK_PATH/$ANDROID update sdk --no-ui --filter platform,platform-tool,tool |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 84 | fi |
| 85 | |
| 86 | cat <<EOF |
| 87 | * All done! |
| 88 | |
| 89 | Please set the following environment variables before running tools/configure: |
Michael Stummvoll | 9ef9904 | 2011-01-12 12:36:52 +0000 | [diff] [blame] | 90 | export ANDROID_SDK_PATH=$SDK_PATH |
| 91 | export ANDROID_NDK_PATH=$NDK_PATH |
Maurus Cuelenaere | ab9caea | 2010-11-06 17:32:52 +0000 | [diff] [blame] | 92 | |
| 93 | EOF |