#!/bin/bash
ROOT_DIR=$(pwd)
API_VERSION=12
SDK_DIR=$OHOS_SDK_HOME/$API_VERSION
function prepare_tools()
{
local commands=("make" "cmake" "automake" "python3" "python3-pip" "python3-ply")
local local_premake5="$ROOT_DIR/library/src/main/cpp/tools/premake5"
apt update >> /dev/null
if [ -f "$local_premake5" ]; then
echo "Found local premake5 at $local_premake5"
chmod +x "$local_premake5"
else
which premake5 >> /dev/null
if [ $? -ne 0 ]; then
echo "install premake5"
apt install premake5 -y >> /dev/null
fi
fi
for cmd in ${commands[@]}
do
which $cmd >> /dev/null
if [ $? -ne 0 ]
then
echo "install $cmd"
apt install $cmd -y >> /dev/null
fi
done
}
function check_sdk()
{
if [ ! -d $SDK_DIR ]
then
echo "Can not find ${SDK_DIR}"
return 1
fi
export OHOS_SDK=$SDK_DIR
export OHOS_NDK=$SDK_DIR/native
return 0
}
function prebuild()
{
check_sdk
if [ $? -ne 0 ]
then
echo "ERROR: check_sdk failed!!!"
return 1
fi
prepare_tools
if [ $? -ne 0 ]
then
echo "ERROR: prepare_tools failed!!!"
return 1
fi
cd $ROOT_DIR
git submodule update --init --recursive
cd $OLDPWD
return 0
}
prebuild $*
ret=$?
echo "ret = $ret"
exit $ret