#!/bin/bash

export COMP_PATH_SECAPP=$(dirname $(readlink -f $0))/../../..
source ${COMP_PATH_SECAPP}/setupDrivers.sh

ROOT_PATH=$(dirname $(readlink -f $BASH_SOURCE))
export NDK_APP_ABI=arm64-v8a
###
### Android NDK path
###
NDK_BUILD=${COMP_PATH_AndroidNdkLinux}/ndk-build
PLATFORM=Generic
# Needs to change due to limitations in NDK build

#export COMP_PATH_MobiCoreDriverLib=MobiCoreDriverLib/Out
export COMP_PATH_TZ_COMMON_THIRD_PARTY=${COMP_PATH_SECAPP}/tz_common/third_party
export COMP_PATH_SPAY_PUBLIC=${COMP_PATH_SECAPP}/tz_spay_common/public
export COMP_PATH_TLC_SPAY=${COMP_PATH_SECAPP}/tz_spay_common/tlc/tlc_spay/Locals/Code
export COMP_PATH_TLC_TZ_COMMON=${COMP_PATH_SECAPP}/tz_common/tlc
export COMP_PATH_PUBLIC_TZ_COMMON=${COMP_PATH_SECAPP}/tz_common/public
export COMP_PATH_TLC_COMM_PUBLIC=${COMP_PATH_SECAPP}/tlc_comm/public
export COMP_PATH_TZ_PLATFORM=${COMP_PATH_SECAPP}/tz_platform
# Store the version in a temporary header file
VERSION_HEADER=$ROOT_PATH/Locals/Code/version.h
echo '#define VERSION 0.0.1"' > ${VERSION_HEADER}

# run NDK build
${NDK_BUILD} \
    -B \
    V=0 \
    NDK_DEBUG=1 \
    NDK_PROJECT_PATH=$ROOT_PATH/Locals/Code \
    NDK_APPLICATION_MK=$ROOT_PATH/Locals/Code/Application.mk \
    NDK_MODULE_PATH=$COMP_PATH_ROOT \
    NDK_APP_OUT=$ROOT_PATH/Out/_build \
    APP_BUILD_SCRIPT=$ROOT_PATH/Locals/Code/Android.mk \
    APP_OPTIM=$MODE
# Remove temporary version header file again
rm ${VERSION_HEADER}
