|
1 | | -#!/bin/sh |
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +if [[ "$1" == "-f" ]]; then |
| 4 | + if command -v trash &>/dev/null; then |
| 5 | + trash "$NDK/ndk-build-toolchain" |
| 6 | + else |
| 7 | + rm -rf "$NDK/ndk-build-toolchain" |
| 8 | + fi |
| 9 | + |
| 10 | + unset NDK_STANDALONE_TOOLCHAIN |
| 11 | +fi |
2 | 12 |
|
3 | 13 | if [[ "$NDK_STANDALONE_TOOLCHAIN" == "" ]]; then |
4 | 14 |
|
5 | 15 | if [[ "$NDK" == "" ]]; then |
6 | 16 | echo "You should set the NDK variable to your ndk-dir!" |
7 | | - exit |
| 17 | + exit 1 |
8 | 18 | fi |
9 | 19 |
|
10 | 20 | export NDK_STANDALONE_TOOLCHAIN=$NDK/ndk-build-toolchain |
11 | 21 |
|
12 | 22 | if [[ ! -d "$NDK_STANDALONE_TOOLCHAIN" ]]; then |
13 | 23 |
|
14 | | - $NDK/build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-android-clang3.6 --arch=arm --platform=android-19 --install-dir=$NDK_STANDALONE_TOOLCHAIN --stl=libc++ |
| 24 | + NDK_VER=$(grep -i revision "$NDK/source.properties") |
15 | 25 |
|
16 | | - fi |
| 26 | + NDK_VER="${NDK_VER/* /}" |
| 27 | + echo "NDK_VER=$NDK_VER" |
| 28 | + |
| 29 | + NDK_MAJOR_VER="${NDK_VER/.*/}" |
| 30 | + echo "NDK_MAJOR_VER=$NDK_MAJOR_VER" |
17 | 31 |
|
| 32 | + if [[ "$NDK_MAJOR_VER" -ge 23 ]]; then |
| 33 | + # NDK23 and later does not support 'standardalone-toolchain' |
| 34 | + # according to <https://developer.android.com/ndk/guides/other_build_systems > export directly |
| 35 | + echo "NDK23 and later does not support 'standardalone-toolchain', export directly" |
| 36 | + if [[ $(uname -s) == "Darwin" ]]; then |
| 37 | + export NDK_STANDALONE_TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/darwin-x86_64" |
| 38 | + elif [[ $(uname -s) == "Linux" ]]; then |
| 39 | + export NDK_STANDALONE_TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64" |
| 40 | + else # windows (没啥意义) |
| 41 | + export NDK_STANDALONE_TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/windows-x86_64" |
| 42 | + fi |
| 43 | + pushd . |
| 44 | + cd $NDK && ln -snf "$NDK_STANDALONE_TOOLCHAIN" ndk-build-toolchain |
| 45 | + popd |
| 46 | + else |
| 47 | + $NDK/build/tools/make-standalone-toolchain.sh --toolchain=arm-linux-android-clang3.6 --arch=arm --platform=android-26 --install-dir=$NDK_STANDALONE_TOOLCHAIN --stl=libc++ |
| 48 | + fi |
| 49 | + fi |
18 | 50 | fi |
| 51 | + |
19 | 52 | echo "NDK_STANDALONE_TOOLCHAIN=$NDK_STANDALONE_TOOLCHAIN" |
0 commit comments