+# Read settings from .termuxrc if existing:
+test -f $HOME/.termuxrc && . $HOME/.termuxrc
+
+# Configurable settings:
+: ${ANDROID_HOME:="${HOME}/lib/android-sdk"}
+: ${NDK:="${HOME}/lib/android-ndk"}
+: ${TERMUX_MAKE_PROCESSES:='4'}
+: ${TERMUX_TOPDIR:="$HOME/.termux-build"}
+: ${TERMUX_ARCH:="aarch64"} # (arm|aarch64|i686|x86_64) - the x86_64 arch is not yet used or tested.
+: ${TERMUX_CLANG:=""} # Set to non-empty to use clang.
+: ${TERMUX_PREFIX:='/data/data/com.termux/files/usr'}
+: ${TERMUX_ANDROID_HOME:='/data/data/com.termux/files/home'}
+: ${TERMUX_DEBUG:=""}
+: ${TERMUX_PROCESS_DEB:=""}
+: ${TERMUX_API_LEVEL:="21"}
+: ${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="23.0.3"}
+: ${TERMUX_NDK_VERSION:="11"}
+
+# Handle command-line arguments:
+show_usage () {
+ echo "Usage: ./build-package.sh [-a ARCH] PACKAGE"
+ echo "Build a package."
+ echo ""
+ exit 1
+}
+while getopts :a:h option
+do
+ case "$option" in
+ a) TERMUX_ARCH="$OPTARG";;
+ h) show_usage;;
+ ?) echo "./build-package.sh: illegal option -$OPTARG"; exit 1;;
+ esac
+done
+shift $(($OPTIND-1))
+if [ "$#" -ne 1 ]; then show_usage; fi
+
+# Check the NDK:
+if [ ! -d "$NDK" ]; then
+ echo 'ERROR: $NDK not defined as pointing at a directory - define it pointing at a android NDK installation!'
+ exit 1
+fi
+if grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION" $NDK/source.properties; then
+ :
+else
+ echo "Wrong NDK version - we need $TERMUX_NDK_VERSION"
+ exit 1
+fi
+
+# Compute standalone toolchain dir, bitness of arch and name of host platform:
+TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/android-standalone-toolchain-${TERMUX_ARCH}-api${TERMUX_API_LEVEL}-"
+if [ "$TERMUX_CLANG" = "" ]; then
+ TERMUX_STANDALONE_TOOLCHAIN+="gcc4.9"
+else
+ TERMUX_STANDALONE_TOOLCHAIN+="clang38"
+fi
+if [ "x86_64" = $TERMUX_ARCH -o "aarch64" = $TERMUX_ARCH ]; then
+ TERMUX_ARCH_BITS=64
+else
+ TERMUX_ARCH_BITS=32
+fi
+TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android"
+if [ $TERMUX_ARCH = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi"; fi