#!/usr/bin/env bash
# Build the Android toolchain (run first)
#set -e
if [ -z "$O3" ]; then
    echo O3 var must point to ovpn3 tree ; exit 1
fi
export DEP_DIR=${DEP_DIR:-$HOME/src/android}
export NO_MOD_PATH=1
. $O3/core/vars/android-sdk-path

# 64 bit
cd $DEP_DIR
DEST=$(pwd)/tc-arm64
rm -rf $DEST
ABI=aarch64-linux-android
$NDK/build/tools/make-standalone-toolchain.sh \
    --verbose \
    --ndk-dir=$NDK \
    --toolchain=$ABI-4.9 \
    --stl=gnustl \
    --arch=arm64 \
    --platform=android-21 \
    --install-dir=$DEST
cd $DEST/$ABI/bin
ln -s ../../bin/$ABI-gcc cc
ln -s ../../bin/$ABI-gcc gcc
ln -s ../../bin/$ABI-g++ g++

# 32 bit
cd $DEP_DIR
DEST=$(pwd)/tc-arm
rm -rf $DEST
ABI=arm-linux-androideabi
$NDK/build/tools/make-standalone-toolchain.sh \
    --verbose \
    --ndk-dir=$NDK \
    --toolchain=$ABI-4.8 \
    --stl=gnustl \
    --arch=arm \
    --platform=android-14 \
    --install-dir=$DEST
cd $DEST/$ABI/bin
ln -s ../../bin/$ABI-gcc cc
