#!/bin/sh

source android-env @TRIPLE@

PATH="${ANDROID_PREFIX_BIN}:$PATH" cmake \
    -DCMAKE_INSTALL_PREFIX="${ANDROID_PREFIX}" \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DINCLUDE_INSTALL_DIR="${ANDROID_PREFIX_INCLUDE}" \
    -DLIB_INSTALL_DIR="${ANDROID_PREFIX_LIB}" \
    -DSYSCONF_INSTALL_DIR="${ANDROID_PREFIX_ETC}" \
    -DSHARE_INSTALL_DIR="${ANDROID_PREFIX_SHARE}" \
    -DCMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES="${ANDROID_PREFIX_INCLUDE}" \
    -DCMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES="${ANDROID_PREFIX_INCLUDE}" \
    -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake" \
    -DBUILD_SHARED_LIBS=ON \
    -DCMAKE_BUILD_TYPE=Release \
    -DANDROID_ABI="${ANDROID_ABI}" \
    -DANDROID_NDK="${ANDROID_NDK_HOME}" \
    -DANDROID_NATIVE_API_LEVEL="${ANDROID_MINIMUM_PLATFORM}" \
    -DANDROID_TOOLCHAIN=clang \
    -DCMAKE_C_FLAGS="$CFLAGS" \
    -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
    -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
    -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
    -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
    "$@"
