+termux_download() {
+ URL="$1"
+ DESTINATION="$2"
+
+ TMPFILE=`mktemp $TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX`
+ echo "Downloading ${URL}"
+ for i in 1 2 3 4 5 6; do
+ if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then
+ if [ $# = 3 ]; then
+ # Optional checksum argument:
+ echo $3 "$TMPFILE" | sha256sum --check --strict --quiet
+ else
+ echo "Note: No checksum of file"
+ sha256sum $TMPFILE
+ fi
+ mv "$TMPFILE" "$DESTINATION"
+ return
+ else
+ echo "Download of $1 failed (attempt $i/3)" 1>&2
+ sleep 45
+ fi
+ done
+
+ echo "Failed to download $1 - exiting" 1>&2
+ exit 1
+}
+
+# Get fresh versions of config.sub and config.guess
+for f in config.sub config.guess; do
+ if [ ! -f $TERMUX_COMMON_CACHEDIR/$f ]; then
+ termux_download "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=${f};hb=HEAD" $TERMUX_COMMON_CACHEDIR/$f
+ fi
+done
+
+# Have a debian-binary file ready for deb packaging:
+test ! -f $TERMUX_COMMON_CACHEDIR/debian-binary && echo "2.0" > $TERMUX_COMMON_CACHEDIR/debian-binary
+# The host tuple that may be given to --host configure flag, but normally autodetected so not needed explicitly
+TERMUX_HOST_TUPLE=`sh $TERMUX_COMMON_CACHEDIR/config.guess`
+