3 SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]}")
4 SCRIPT_PATH=$(realpath "$SCRIPT_PATH")
6 if [ -z $BUILD_ARCH ]; then
7 BUILD_ARCH="armeabi-v7a x86 x86_64 arm64-v8a"
10 if [ -z $NDK_TARGET ]; then
14 if [ -z $CMAKE_PROGRAM ]; then
15 CMAKE_PROGRAM=$(find $ANDROID_SDK/cmake -name cmake -type f -executable -print -quit)
18 if [ -z $CCACHE ]; then
19 CCACHE=$(which ccache)
22 if [ -z $ANDROID_NDK ]; then
26 if [ -z $ANDROID_SDK ]; then
30 if [ -z $BUILD_DST ]; then
34 if [ -z $BUILD_SRC ]; then
38 if [ -z $SCM_URL ]; then
42 if [ -z $SCM_TAG ]; then
48 function common_help {
49 echo "$(BASHSOURCE[0]) supports the following arguments:"
50 echo " --ndk The base directory of your android NDK defa"
51 echo " ANDROID_NDK=$ANDROID_NDK"
52 echo " --sdk The base directory of your android SDK defa"
53 echo " ANDROID_SDK=$ANDROID_SDK"
54 echo " --arch A list of architectures to build"
55 echo " BUILD_ARCH=$BUILD_ARCH"
56 echo " --dst The destination directory for include and library files"
57 echo " BUILD_DST=$BUILD_DST"
58 echo " --src The source directory for SCM checkout"
59 echo " BUILD_SRC=$BUILD_SRC"
60 echo " --url The SCM source url"
61 echo " SCM_URL=$SCM_URL"
62 echo " --tag The SCM branch or tag to check out"
63 echo " SCM_TAG=$SCM_TAG"
64 echo " --clean Clean the destination before build"
65 echo " --help Display this help"
75 echo "[ERROR] $@ retured $RES"
80 function common_parse_arguments {
102 CMAKE_PROGRAM=$(find $ANDROID_SDK/cmake -name cmake -type f -executable -print -quit)
148 function common_check_requirements {
149 if [[ ! -d $ANDROID_NDK ]];
151 echo "export ANDROID_NDK to point to your NDK location."
155 if [[ ! -d $ANDROID_SDK ]];
157 echo "export ANDROID_SDK to point to your SDK location."
160 if [[ -z $BUILD_DST ]];
162 echo "Destination directory not valid"
166 if [[ -z $BUILD_SRC ]];
168 echo "Source directory not valid"
172 if [[ -z $SCM_URL ]];
174 echo "Source URL not defined! Define SCM_URL"
178 if [[ -z $SCM_TAG ]];
180 echo "SCM TAG / BRANCH not defined! Define SCM_TAG"
184 if [[ -z $NDK_TARGET ]];
186 echo "Android platform NDK_TARGET not defined"
190 if [ -x $ANDROID_NDK/ndk-build ]; then
191 NDK_BUILD=$ANDROID_NDK/ndk-build
193 echo "ndk-build not found in NDK directory $ANDROID_NDK"
194 echo "assuming ndk-build is in path..."
198 if [ -z $CMAKE_PROGRAM ]; then
199 CMAKE_PROGRAM=$(find $ANDROID_SDK/cmake -name cmake -type f -executable -print -quit)
202 for CMD in make git $CMAKE_PROGRAM $NDK_BUILD
204 if ! type $CMD >/dev/null; then
205 echo "Command $CMD not found. Install and add it to the PATH."
210 if [ "${BUILD_SRC:0:1}" != "/" ];
212 BUILD_SRC=$(pwd)/$BUILD_SRC
214 if [ "${BUILD_DST:0:1}" != "/" ];
216 BUILD_DST=$(pwd)/$BUILD_DST
220 function common_update {
223 echo "Invalid arguments to update function $@"
230 echo "Preparing checkout..."
232 CACHE=$SCRIPT_PATH/../cache
233 common_run mkdir -p $CACHE
234 TARFILE="$CACHE/$SCM_TAG.tar.gz"
237 if [[ ! -f "$TARFILE" ]];
239 common_run wget -O "$TARFILE" "$SCM_URL/archive/$SCM_TAG.tar.gz"
242 if [[ -d $BUILD_SRC ]];
244 common_run rm -rf $BUILD_SRC
246 common_run mkdir -p $BUILD_SRC
247 common_run cd $BUILD_SRC
248 common_run tar zxf "$TARFILE" --strip 1
253 function common_clean {
254 if [ $CLEAN_BUILD_DIR -ne 1 ];
261 echo "Invalid arguments to clean function $@"
265 echo "Cleaning up $1..."
269 function common_copy {
272 echo "Invalid arguments to copy function $@"
275 if [ ! -d $1 ] || [ ! -d $1/include ] || [ ! -d $1/libs ];
277 echo "Invalid source $1"
282 echo "Invalid destination $2"
288 common_run mkdir -p $2
290 common_run cp -L -r $1/include $2
291 common_run cp -L -r $1/libs/* $2