| 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 17 matching lines...) Expand all Loading... |
| 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 TOOLCHAINS=${SCRIPT_DIR}/../toolchains | 35 TOOLCHAINS=${SCRIPT_DIR}/../toolchains |
| 36 | 36 |
| 37 ANDROID_ARCH=${ANDROID_ARCH-arm} | 37 ANDROID_ARCH=${ANDROID_ARCH-arm} |
| 38 LLVM=3.6 | 38 NDK=r11 |
| 39 NDK=r10e | |
| 40 | 39 |
| 41 if [[ $ANDROID_ARCH == *64* ]]; then | 40 if [[ $ANDROID_ARCH == *64* ]]; then |
| 42 API=21 # Android 5.0 | 41 API=21 # Android 5.0 |
| 43 else | 42 else |
| 44 API=14 # Android 4.0 | 43 API=14 # Android 4.0 |
| 45 fi | 44 fi |
| 46 | 45 |
| 47 TOOLCHAIN=$ANDROID_ARCH-$NDK-$API | 46 TOOLCHAIN=$ANDROID_ARCH-$NDK-$API |
| 48 HOST=`uname | tr '[A-Z]' '[a-z]'` | 47 HOST=`uname | tr '[A-Z]' '[a-z]'` |
| 49 | 48 |
| 50 exportVar ANDROID_TOOLCHAIN "${TOOLCHAINS}/${TOOLCHAIN}/bin" | 49 exportVar ANDROID_TOOLCHAIN "${TOOLCHAINS}/${TOOLCHAIN}/bin" |
| 51 | 50 |
| 52 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then | 51 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then |
| 53 mkdir -p $TOOLCHAINS | 52 mkdir -p $TOOLCHAINS |
| 54 pushd $TOOLCHAINS | 53 pushd $TOOLCHAINS |
| 55 curl -o $NDK.bin https://dl.google.com/android/ndk/android-ndk-$NDK-$HOST-x8
6_64.bin | 54 curl -o $NDK.zip https://dl.google.com/android/repository/android-ndk-$NDK-$
HOST-x86_64.zip |
| 56 chmod +x $NDK.bin | 55 unzip $NDK.zip |
| 57 ./$NDK.bin -y | 56 UNZIPPED=android-ndk-$NDK-$HOST-x86_64.tar.bz2 |
| 58 ./android-ndk-$NDK/build/tools/make-standalone-toolchain.sh \ | 57 ./$UNZIPPED/build/tools/make-standalone-toolchain.sh \ |
| 58 --use-llvm \ |
| 59 --arch=$ANDROID_ARCH \ | 59 --arch=$ANDROID_ARCH \ |
| 60 --llvm-version=$LLVM \ | |
| 61 --platform=android-$API \ | 60 --platform=android-$API \ |
| 62 --install_dir=$TOOLCHAIN | 61 --install_dir=$TOOLCHAIN |
| 63 cp android-ndk-$NDK/prebuilt/android-$ANDROID_ARCH/gdbserver/gdbserver $TOOL
CHAIN | 62 cp $UNZIPPED/prebuilt/android-$ANDROID_ARCH/gdbserver/gdbserver $TOOLCHAIN |
| 64 rm $NDK.bin | 63 rm $NDK.zip |
| 65 rm -rf android-ndk-$NDK | 64 rm -rf $UNZIPPED |
| 66 popd | 65 popd |
| 67 fi | 66 fi |
| 68 | 67 |
| 69 verbose "Targeting NDK API $API (NDK Revision $NDK)" | 68 verbose "Targeting NDK API $API (NDK Revision $NDK)" |
| 70 } | 69 } |
| 71 | 70 |
| 72 #check to see if the toolchain has been defined and if not setup the default too
lchain | 71 #check to see if the toolchain has been defined and if not setup the default too
lchain |
| 73 if [ -z "$ANDROID_TOOLCHAIN" ]; then | 72 if [ -z "$ANDROID_TOOLCHAIN" ]; then |
| 74 default_toolchain | 73 default_toolchain |
| 75 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then | 74 if [ ! -d "$ANDROID_TOOLCHAIN" ]; then |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 141 |
| 143 # Create symlinks for nm & readelf and add them to the path so that the ninja | 142 # Create symlinks for nm & readelf and add them to the path so that the ninja |
| 144 # build uses them instead of attempting to use the one on the system. | 143 # build uses them instead of attempting to use the one on the system. |
| 145 # This is required to build using ninja on a Mac. | 144 # This is required to build using ninja on a Mac. |
| 146 if [ $(uname) == "Darwin" ]; then | 145 if [ $(uname) == "Darwin" ]; then |
| 147 ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm | 146 ln -sf $ANDROID_TOOLCHAIN_PREFIX-nm $ANDROID_TOOLCHAIN/nm |
| 148 ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf | 147 ln -sf $ANDROID_TOOLCHAIN_PREFIX-readelf $ANDROID_TOOLCHAIN/readelf |
| 149 ln -sf $ANDROID_TOOLCHAIN_PREFIX-as $ANDROID_TOOLCHAIN/as | 148 ln -sf $ANDROID_TOOLCHAIN_PREFIX-as $ANDROID_TOOLCHAIN/as |
| 150 fi | 149 fi |
| 151 | 150 |
| 152 # fix bug in the toolchain in order to enable ccache to work with clang | |
| 153 if [ $(head -c 2 $ANDROID_TOOLCHAIN_PREFIX-clang) != "#!" ]; then | |
| 154 echo -e "#!/bin/bash\n$(cat $ANDROID_TOOLCHAIN_PREFIX-clang)" > $ANDROID_TOOL
CHAIN_PREFIX-clang | |
| 155 fi | |
| 156 if [ $(head -c 2 $ANDROID_TOOLCHAIN_PREFIX-clang++) != "#!" ]; then | |
| 157 echo -e "#!/bin/bash\n$(cat $ANDROID_TOOLCHAIN_PREFIX-clang++)" > $ANDROID_TO
OLCHAIN_PREFIX-clang++ | |
| 158 fi | |
| 159 | |
| 160 exportVar PATH $ANDROID_TOOLCHAIN:$PATH | 151 exportVar PATH $ANDROID_TOOLCHAIN:$PATH |
| OLD | NEW |