| OLD | NEW |
| 1 # Copyright 2015 Google Inc. | 1 # Copyright 2015 Google Inc. |
| 2 # | 2 # |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 #!/bin/bash | 6 #!/bin/bash |
| 7 # | 7 # |
| 8 # setup_toolchain.sh: Sets toolchain environment variables used by other scripts
. | 8 # setup_toolchain.sh: Sets toolchain environment variables used by other scripts
. |
| 9 | 9 |
| 10 # Fail-fast if anything in the script fails. | 10 # Fail-fast if anything in the script fails. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 echo "ERROR: The absPath function is expected to be defined" | 25 echo "ERROR: The absPath function is expected to be defined" |
| 26 return 1 | 26 return 1 |
| 27 fi | 27 fi |
| 28 | 28 |
| 29 if [ -z "$SCRIPT_DIR" ]; then | 29 if [ -z "$SCRIPT_DIR" ]; then |
| 30 echo "ERROR: The SCRIPT_DIR variable is expected to be defined" | 30 echo "ERROR: The SCRIPT_DIR variable is expected to be defined" |
| 31 return 1 | 31 return 1 |
| 32 fi | 32 fi |
| 33 | 33 |
| 34 function default_toolchain() { | 34 function default_toolchain() { |
| 35 NDK_REV=${NDK_REV-10c} | 35 TOOLCHAINS=${SCRIPT_DIR}/../toolchains |
| 36 |
| 36 ANDROID_ARCH=${ANDROID_ARCH-arm} | 37 ANDROID_ARCH=${ANDROID_ARCH-arm} |
| 37 | 38 LLVM=3.6 |
| 39 NDK=r10e |
| 40 |
| 38 if [[ $ANDROID_ARCH == *64* ]]; then | 41 if [[ $ANDROID_ARCH == *64* ]]; then |
| 39 API_LEVEL=21 # Official Android 5.0 (Lollipop) system images | 42 API=21 # Android 5.0 |
| 40 else | 43 else |
| 41 API_LEVEL=14 # Official Android 4.0 system images | 44 API=14 # Android 4.0 |
| 42 fi | 45 fi |
| 43 | 46 |
| 44 TOOLCHAIN_DIR=${SCRIPT_DIR}/../toolchains | 47 TOOLCHAIN=$ANDROID_ARCH-$NDK-$API |
| 45 if [ $(uname) == "Darwin" ]; then | 48 HOST=`uname | tr '[A-Z]' '[a-z]'` |
| 46 verbose "Using Mac toolchain." | |
| 47 TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-darwin_v$API_LEVEL | |
| 48 else | |
| 49 verbose "Using Linux toolchain." | |
| 50 TOOLCHAIN_TYPE=ndk-r$NDK_REV-$ANDROID_ARCH-linux_v$API_LEVEL | |
| 51 fi | |
| 52 exportVar ANDROID_TOOLCHAIN "${TOOLCHAIN_DIR}/${TOOLCHAIN_TYPE}/bin" | |
| 53 | 49 |
| 54 # Hack for NDK_REV == 10c to ensure that clang is present as it was | 50 exportVar ANDROID_TOOLCHAIN "${TOOLCHAINS}/${TOOLCHAIN}/bin" |
| 55 # added to the tarball after it was initially distributed. | |
| 56 if [ ! -x ${ANDROID_TOOLCHAIN}/clang ]; then | |
| 57 rm -rf ${TOOLCHAIN_DIR}/${TOOLCHAIN_TYPE} | |
| 58 fi | |
| 59 | 51 |
| 60 # if the toolchain doesn't exist on your machine then we need to fetch it | |
| 61 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then | 52 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then |
| 62 mkdir -p $TOOLCHAIN_DIR | 53 mkdir -p $TOOLCHAINS |
| 63 # enter the toolchain directory then download, unpack, and remove the tarbal
l | 54 pushd $TOOLCHAINS |
| 64 pushd $TOOLCHAIN_DIR | 55 curl -o $NDK.bin https://dl.google.com/android/ndk/android-ndk-$NDK-$HOST-x8
6_64.bin |
| 65 TARBALL=ndk-r$NDK_REV-v$API_LEVEL.tgz | 56 chmod +x $NDK.bin |
| 66 | 57 ./$NDK.bin -y |
| 67 ${SCRIPT_DIR}/download_toolchains.py \ | 58 ./android-ndk-$NDK/build/tools/make-standalone-toolchain.sh \ |
| 68 http://storage.googleapis.com/chromium-skia-gm/android-toolchains/$TARBA
LL \ | 59 --arch=$ANDROID_ARCH \ |
| 69 $TOOLCHAIN_DIR/$TARBALL | 60 --llvm-version=$LLVM \ |
| 70 tar -xzf $TARBALL $TOOLCHAIN_TYPE | 61 --platform=android-$API \ |
| 71 rm $TARBALL | 62 --install_dir=$TOOLCHAIN |
| 63 cp android-ndk-$NDK/prebuilt/android-$ANDROID_ARCH/gdbserver/gdbserver $TOOL
CHAIN |
| 64 rm $NDK.bin |
| 65 rm -rf android-ndk-$NDK |
| 72 popd | 66 popd |
| 73 fi | 67 fi |
| 74 | 68 |
| 75 verbose "Targeting NDK API $API_LEVEL (NDK Revision $NDK_REV)" | 69 verbose "Targeting NDK API $API (NDK Revision $NDK)" |
| 76 } | 70 } |
| 77 | 71 |
| 78 #check to see if the toolchain has been defined and if not setup the default too
lchain | 72 #check to see if the toolchain has been defined and if not setup the default too
lchain |
| 79 if [ -z "$ANDROID_TOOLCHAIN" ]; then | 73 if [ -z "$ANDROID_TOOLCHAIN" ]; then |
| 80 default_toolchain | 74 default_toolchain |
| 81 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then | 75 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then |
| 82 echo "ERROR: unable to download/setup the required toolchain (${ANDROID_TOOL
CHAIN})" | 76 echo "ERROR: unable to download/setup the required toolchain (${ANDROID_TOOL
CHAIN})" |
| 83 return 1; | 77 return 1; |
| 84 fi | 78 fi |
| 85 fi | 79 fi |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 # Create symlinks for nm & readelf and add them to the path so that the ninja | 147 # Create symlinks for nm & readelf and add them to the path so that the ninja |
| 154 # build uses them instead of attempting to use the one on the system. | 148 # build uses them instead of attempting to use the one on the system. |
| 155 # This is required to build using ninja on a Mac. | 149 # This is required to build using ninja on a Mac. |
| 156 if [ $(uname) == "Darwin" ]; then | 150 if [ $(uname) == "Darwin" ]; then |
| 157 ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm | 151 ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm |
| 158 ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf | 152 ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf |
| 159 ln -sf $ANDROID_TOOLCHAIN_PREFIX-as $ANDROID_TOOLCHAIN/as | 153 ln -sf $ANDROID_TOOLCHAIN_PREFIX-as $ANDROID_TOOLCHAIN/as |
| 160 fi | 154 fi |
| 161 | 155 |
| 162 exportVar PATH $ANDROID_TOOLCHAIN:$PATH | 156 exportVar PATH $ANDROID_TOOLCHAIN:$PATH |
| OLD | NEW |