2015-06-13 01:03:31 +02:00
|
|
|
#!/bin/bash
|
2018-08-27 22:27:42 +02:00
|
|
|
# shellcheck disable=SC1117
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
set -e -o pipefail -u
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Utility function to log an error message and exit with an error code.
|
|
|
|
termux_error_exit() {
|
|
|
|
echo "ERROR: $*" 1>&2
|
2016-06-04 00:41:30 +02:00
|
|
|
exit 1
|
2017-01-06 02:37:45 +01:00
|
|
|
}
|
2015-12-21 02:47:48 +01:00
|
|
|
|
2018-08-27 22:27:42 +02:00
|
|
|
if [ "$(uname -o)" = Android ]; then
|
2017-12-07 03:19:46 +01:00
|
|
|
termux_error_exit "On-device builds are not supported - see README.md"
|
|
|
|
fi
|
|
|
|
|
2018-08-21 00:35:50 +02:00
|
|
|
# Utility function to download a resource with an expected checksum.
|
2016-05-31 01:25:12 +02:00
|
|
|
termux_download() {
|
2018-08-21 00:35:50 +02:00
|
|
|
if [ $# != 3 ]; then
|
|
|
|
termux_error_exit "termux_download(): Invalid arguments - expected \$URL \$DESTINATION \$CHECKSUM"
|
|
|
|
fi
|
2017-01-06 02:37:45 +01:00
|
|
|
local URL="$1"
|
|
|
|
local DESTINATION="$2"
|
2018-08-21 00:35:50 +02:00
|
|
|
local CHECKSUM="$3"
|
2017-02-02 22:24:13 +01:00
|
|
|
|
2018-08-21 00:35:50 +02:00
|
|
|
if [ -f "$DESTINATION" ] && [ "$CHECKSUM" != "SKIP_CHECKSUM" ]; then
|
2017-02-02 22:24:13 +01:00
|
|
|
# Keep existing file if checksum matches.
|
|
|
|
local EXISTING_CHECKSUM
|
|
|
|
EXISTING_CHECKSUM=$(sha256sum "$DESTINATION" | cut -f 1 -d ' ')
|
2018-08-21 00:35:50 +02:00
|
|
|
if [ "$EXISTING_CHECKSUM" = "$CHECKSUM" ]; then return; fi
|
2017-02-02 22:24:13 +01:00
|
|
|
fi
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
local TMPFILE
|
|
|
|
TMPFILE=$(mktemp "$TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX")
|
2016-08-24 12:34:43 +02:00
|
|
|
echo "Downloading ${URL}"
|
2017-01-06 02:37:45 +01:00
|
|
|
local TRYMAX=6
|
2016-09-15 21:50:29 +02:00
|
|
|
for try in $(seq 1 $TRYMAX); do
|
2016-08-24 12:34:43 +02:00
|
|
|
if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then
|
2017-01-06 02:37:45 +01:00
|
|
|
local ACTUAL_CHECKSUM
|
|
|
|
ACTUAL_CHECKSUM=$(sha256sum "$TMPFILE" | cut -f 1 -d ' ')
|
2018-08-21 00:35:50 +02:00
|
|
|
if [ "$CHECKSUM" != "SKIP_CHECKSUM" ]; then
|
|
|
|
if [ "$CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
|
2016-10-29 21:44:51 +02:00
|
|
|
>&2 printf "Wrong checksum for %s:\nExpected: %s\nActual: %s\n" \
|
2018-08-21 00:35:50 +02:00
|
|
|
"$URL" "$CHECKSUM" "$ACTUAL_CHECKSUM"
|
2016-10-23 13:47:52 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-24 12:34:43 +02:00
|
|
|
else
|
2018-08-21 00:35:50 +02:00
|
|
|
printf "WARNING: No checksum check for %s:\nActual: %s\n" \
|
2016-10-29 21:44:51 +02:00
|
|
|
"$URL" "$ACTUAL_CHECKSUM"
|
2016-08-24 12:34:43 +02:00
|
|
|
fi
|
|
|
|
mv "$TMPFILE" "$DESTINATION"
|
|
|
|
return
|
|
|
|
else
|
2017-01-06 02:37:45 +01:00
|
|
|
echo "Download of $URL failed (attempt $try/$TRYMAX)" 1>&2
|
2016-08-24 12:34:43 +02:00
|
|
|
sleep 45
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
termux_error_exit "Failed to download $URL"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Utility function for golang-using packages to setup a go toolchain.
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_setup_golang() {
|
2017-01-06 02:37:45 +01:00
|
|
|
export GOOS=android
|
|
|
|
export CGO_ENABLED=1
|
|
|
|
export GO_LDFLAGS="-extldflags=-pie"
|
|
|
|
if [ "$TERMUX_ARCH" = "arm" ]; then
|
|
|
|
export GOARCH=arm
|
|
|
|
export GOARM=7
|
|
|
|
elif [ "$TERMUX_ARCH" = "i686" ]; then
|
|
|
|
export GOARCH=386
|
|
|
|
export GO386=sse2
|
|
|
|
elif [ "$TERMUX_ARCH" = "aarch64" ]; then
|
|
|
|
export GOARCH=arm64
|
|
|
|
elif [ "$TERMUX_ARCH" = "x86_64" ]; then
|
|
|
|
export GOARCH=amd64
|
|
|
|
else
|
|
|
|
termux_error_exit "Unsupported arch: $TERMUX_ARCH"
|
|
|
|
fi
|
|
|
|
|
2018-11-05 21:38:26 +01:00
|
|
|
local TERMUX_GO_VERSION=go1.11.2
|
2017-01-06 02:37:45 +01:00
|
|
|
local TERMUX_GO_PLATFORM=linux-amd64
|
|
|
|
|
2017-01-31 13:07:48 +01:00
|
|
|
local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}
|
2017-01-06 02:37:45 +01:00
|
|
|
export GOROOT=$TERMUX_BUILDGO_FOLDER
|
|
|
|
export PATH=$GOROOT/bin:$PATH
|
|
|
|
|
|
|
|
if [ -d "$TERMUX_BUILDGO_FOLDER" ]; then return; fi
|
|
|
|
|
|
|
|
local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz
|
|
|
|
rm -Rf "$TERMUX_COMMON_CACHEDIR/go" "$TERMUX_BUILDGO_FOLDER"
|
|
|
|
termux_download https://storage.googleapis.com/golang/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz \
|
2018-02-08 21:48:28 +01:00
|
|
|
"$TERMUX_BUILDGO_TAR" \
|
2018-11-05 23:00:20 +01:00
|
|
|
1dfe664fa3d8ad714bbd15a36627992effd150ddabd7523931f077b3926d736d
|
2017-04-10 00:19:20 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
( cd "$TERMUX_COMMON_CACHEDIR"; tar xf "$TERMUX_BUILDGO_TAR"; mv go "$TERMUX_BUILDGO_FOLDER"; rm "$TERMUX_BUILDGO_TAR" )
|
|
|
|
}
|
|
|
|
|
2018-09-03 23:57:26 +02:00
|
|
|
# Utility function for rust-using packages to setup a rust toolchain.
|
|
|
|
termux_setup_rust() {
|
|
|
|
if [ $TERMUX_ARCH = "arm" ]; then
|
|
|
|
CARGO_TARGET_NAME=armv7-linux-androideabi
|
|
|
|
else
|
|
|
|
CARGO_TARGET_NAME=$TERMUX_ARCH-linux-android
|
|
|
|
fi
|
|
|
|
|
|
|
|
local ENV_NAME=CARGO_TARGET_${CARGO_TARGET_NAME^^}_LINKER
|
|
|
|
ENV_NAME=${ENV_NAME//-/_}
|
|
|
|
export $ENV_NAME=$CC
|
|
|
|
|
|
|
|
curl https://sh.rustup.rs -sSf > $TERMUX_PKG_TMPDIR/rustup.sh
|
|
|
|
sh $TERMUX_PKG_TMPDIR/rustup.sh -y
|
|
|
|
export PATH=$HOME/.cargo/bin:$PATH
|
|
|
|
|
|
|
|
rustup target add $CARGO_TARGET_NAME
|
|
|
|
}
|
|
|
|
|
2017-11-07 02:26:49 +01:00
|
|
|
# Utility function to setup a current ninja build system.
|
2017-07-29 02:11:04 +02:00
|
|
|
termux_setup_ninja() {
|
2017-09-15 18:41:26 +02:00
|
|
|
local NINJA_VERSION=1.8.2
|
2017-07-29 02:11:04 +02:00
|
|
|
local NINJA_FOLDER=$TERMUX_COMMON_CACHEDIR/ninja-$NINJA_VERSION
|
2018-08-27 22:27:42 +02:00
|
|
|
if [ ! -x "$NINJA_FOLDER/ninja" ]; then
|
|
|
|
mkdir -p "$NINJA_FOLDER"
|
2017-07-29 02:11:04 +02:00
|
|
|
local NINJA_ZIP_FILE=$TERMUX_PKG_TMPDIR/ninja-$NINJA_VERSION.zip
|
|
|
|
termux_download https://github.com/ninja-build/ninja/releases/download/v$NINJA_VERSION/ninja-linux.zip \
|
2018-08-27 22:27:42 +02:00
|
|
|
"$NINJA_ZIP_FILE" \
|
2017-09-15 18:41:26 +02:00
|
|
|
d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07
|
2018-08-27 22:27:42 +02:00
|
|
|
unzip "$NINJA_ZIP_FILE" -d "$NINJA_FOLDER"
|
2017-07-29 02:11:04 +02:00
|
|
|
fi
|
|
|
|
export PATH=$NINJA_FOLDER:$PATH
|
|
|
|
}
|
|
|
|
|
2017-11-07 02:26:49 +01:00
|
|
|
# Utility function to setup a current meson build system.
|
2017-07-29 02:11:04 +02:00
|
|
|
termux_setup_meson() {
|
|
|
|
termux_setup_ninja
|
2018-09-26 07:16:50 +02:00
|
|
|
local MESON_VERSION=0.48.0
|
2018-01-21 20:45:35 +01:00
|
|
|
local MESON_FOLDER=$TERMUX_COMMON_CACHEDIR/meson-$MESON_VERSION-v1
|
2017-07-29 02:11:04 +02:00
|
|
|
if [ ! -d "$MESON_FOLDER" ]; then
|
|
|
|
local MESON_TAR_NAME=meson-$MESON_VERSION.tar.gz
|
|
|
|
local MESON_TAR_FILE=$TERMUX_PKG_TMPDIR/$MESON_TAR_NAME
|
2018-01-21 20:45:35 +01:00
|
|
|
local MESON_TMP_FOLDER=$TERMUX_PKG_TMPDIR/meson-$MESON_VERSION
|
2017-07-29 02:11:04 +02:00
|
|
|
termux_download \
|
2018-08-27 22:27:42 +02:00
|
|
|
"https://github.com/mesonbuild/meson/releases/download/$MESON_VERSION/meson-$MESON_VERSION.tar.gz" \
|
|
|
|
"$MESON_TAR_FILE" \
|
2018-09-26 07:16:50 +02:00
|
|
|
982937ba5b380abe13f3a0c4dff944dd19d08b72870e3b039f5037c91f82835f
|
2018-01-21 20:45:35 +01:00
|
|
|
tar xf "$MESON_TAR_FILE" -C "$TERMUX_PKG_TMPDIR"
|
2018-08-27 22:27:42 +02:00
|
|
|
mv "$MESON_TMP_FOLDER" "$MESON_FOLDER"
|
2017-07-29 02:11:04 +02:00
|
|
|
fi
|
|
|
|
TERMUX_MESON="$MESON_FOLDER/meson.py"
|
2017-10-14 23:02:24 +02:00
|
|
|
TERMUX_MESON_CROSSFILE=$TERMUX_COMMON_CACHEDIR/meson-crossfile-$TERMUX_ARCH-v2.txt
|
2018-08-27 22:27:42 +02:00
|
|
|
if [ ! -f "$TERMUX_MESON_CROSSFILE" ]; then
|
2017-07-29 02:11:04 +02:00
|
|
|
local MESON_CPU MESON_CPU_FAMILY
|
2018-08-27 22:27:42 +02:00
|
|
|
if [ "$TERMUX_ARCH" = "arm" ]; then
|
2017-07-29 02:11:04 +02:00
|
|
|
MESON_CPU_FAMILY="arm"
|
|
|
|
MESON_CPU="armv7"
|
2018-08-27 22:27:42 +02:00
|
|
|
elif [ "$TERMUX_ARCH" = "i686" ]; then
|
2017-07-29 02:11:04 +02:00
|
|
|
MESON_CPU_FAMILY="x86"
|
|
|
|
MESON_CPU="i686"
|
2018-08-27 22:27:42 +02:00
|
|
|
elif [ "$TERMUX_ARCH" = "x86_64" ]; then
|
2017-07-29 02:11:04 +02:00
|
|
|
MESON_CPU_FAMILY="x86_64"
|
|
|
|
MESON_CPU="x86_64"
|
2018-08-27 22:27:42 +02:00
|
|
|
elif [ "$TERMUX_ARCH" = "aarch64" ]; then
|
2017-07-29 02:11:04 +02:00
|
|
|
MESON_CPU_FAMILY="arm"
|
|
|
|
MESON_CPU="aarch64"
|
|
|
|
else
|
|
|
|
termux_error_exit "Unsupported arch: $TERMUX_ARCH"
|
|
|
|
fi
|
|
|
|
|
2018-08-27 22:27:42 +02:00
|
|
|
cat > "$TERMUX_MESON_CROSSFILE" <<-HERE
|
2017-07-29 02:11:04 +02:00
|
|
|
[binaries]
|
|
|
|
ar = '$AR'
|
|
|
|
c = '$CC'
|
|
|
|
cpp = '$CXX'
|
|
|
|
ld = '$LD'
|
2017-10-14 23:02:24 +02:00
|
|
|
pkgconfig = '$PKG_CONFIG'
|
2017-07-29 02:11:04 +02:00
|
|
|
strip = '$STRIP'
|
|
|
|
[properties]
|
|
|
|
needs_exe_wrapper = true
|
|
|
|
[host_machine]
|
|
|
|
cpu_family = '$MESON_CPU_FAMILY'
|
|
|
|
cpu = '$MESON_CPU'
|
|
|
|
endian = 'little'
|
|
|
|
system = 'android'
|
|
|
|
HERE
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-11-07 02:26:49 +01:00
|
|
|
# Utility function to setup a current cmake build system
|
2017-01-11 18:21:58 +01:00
|
|
|
termux_setup_cmake() {
|
2018-08-10 13:01:05 +02:00
|
|
|
local TERMUX_CMAKE_MAJORVESION=3.12
|
2018-11-05 23:00:20 +01:00
|
|
|
local TERMUX_CMAKE_MINORVERSION=4
|
2017-01-11 18:21:58 +01:00
|
|
|
local TERMUX_CMAKE_VERSION=$TERMUX_CMAKE_MAJORVESION.$TERMUX_CMAKE_MINORVERSION
|
|
|
|
local TERMUX_CMAKE_TARNAME=cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64.tar.gz
|
|
|
|
local TERMUX_CMAKE_TARFILE=$TERMUX_PKG_TMPDIR/$TERMUX_CMAKE_TARNAME
|
|
|
|
local TERMUX_CMAKE_FOLDER=$TERMUX_COMMON_CACHEDIR/cmake-$TERMUX_CMAKE_VERSION
|
2017-02-02 00:40:11 +01:00
|
|
|
if [ ! -d "$TERMUX_CMAKE_FOLDER" ]; then
|
2017-01-11 18:21:58 +01:00
|
|
|
termux_download https://cmake.org/files/v$TERMUX_CMAKE_MAJORVESION/$TERMUX_CMAKE_TARNAME \
|
2017-02-02 00:40:11 +01:00
|
|
|
"$TERMUX_CMAKE_TARFILE" \
|
2018-11-05 23:00:20 +01:00
|
|
|
486edd6710b5250946b4b199406ccbf8f567ef0e23cfe38f7938b8c78a2ffa5f
|
2017-02-02 00:40:11 +01:00
|
|
|
rm -Rf "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64"
|
|
|
|
tar xf "$TERMUX_CMAKE_TARFILE" -C "$TERMUX_PKG_TMPDIR"
|
|
|
|
mv "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64" \
|
|
|
|
"$TERMUX_CMAKE_FOLDER"
|
2017-01-11 18:21:58 +01:00
|
|
|
fi
|
|
|
|
export PATH=$TERMUX_CMAKE_FOLDER/bin:$PATH
|
2017-01-27 23:59:17 +01:00
|
|
|
export CMAKE_INSTALL_ALWAYS=1
|
2017-01-11 18:21:58 +01:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# First step is to handle command-line arguments. Not to be overridden by packages.
|
|
|
|
termux_step_handle_arguments() {
|
|
|
|
_show_usage () {
|
2018-08-23 22:18:10 +02:00
|
|
|
echo "Usage: ./build-package.sh [-a ARCH] [-d] [-D] [-f] [-q] [-s] [-o DIR] PACKAGE"
|
2017-01-06 02:37:45 +01:00
|
|
|
echo "Build a package by creating a .deb file in the debs/ folder."
|
|
|
|
echo " -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all."
|
|
|
|
echo " -d Build with debug symbols."
|
|
|
|
echo " -D Build a disabled package in disabled-packages/."
|
2017-02-02 22:14:29 +01:00
|
|
|
echo " -f Force build even if package has already been built."
|
2018-08-23 22:18:10 +02:00
|
|
|
echo " -q Quiet build."
|
2017-01-06 02:37:45 +01:00
|
|
|
echo " -s Skip dependency check."
|
2018-08-23 22:18:10 +02:00
|
|
|
echo " -o Specify deb directory. Default: debs/."
|
2017-01-06 02:37:45 +01:00
|
|
|
exit 1
|
|
|
|
}
|
2018-08-23 22:18:10 +02:00
|
|
|
while getopts :a:hdDfqso: option; do
|
2017-01-06 02:37:45 +01:00
|
|
|
case "$option" in
|
|
|
|
a) TERMUX_ARCH="$OPTARG";;
|
|
|
|
h) _show_usage;;
|
2018-09-12 10:14:06 +02:00
|
|
|
d) export TERMUX_DEBUG=true;;
|
2017-01-06 02:37:45 +01:00
|
|
|
D) local TERMUX_IS_DISABLED=true;;
|
2017-02-02 22:14:29 +01:00
|
|
|
f) TERMUX_FORCE_BUILD=true;;
|
2017-10-08 22:04:49 +02:00
|
|
|
q) export TERMUX_QUIET_BUILD=true;;
|
2017-01-06 02:37:45 +01:00
|
|
|
s) export TERMUX_SKIP_DEPCHECK=true;;
|
2018-08-23 22:18:10 +02:00
|
|
|
o) TERMUX_DEBDIR="$(realpath -m $OPTARG)";;
|
2017-01-06 02:37:45 +01:00
|
|
|
?) termux_error_exit "./build-package.sh: illegal option -$OPTARG";;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
if [ "$#" -ne 1 ]; then _show_usage; fi
|
|
|
|
unset -f _show_usage
|
|
|
|
|
|
|
|
# Handle 'all' arch:
|
|
|
|
if [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then
|
2017-01-17 16:07:15 +01:00
|
|
|
for arch in 'aarch64' 'arm' 'i686' 'x86_64'; do
|
2018-09-12 10:14:06 +02:00
|
|
|
./build-package.sh ${TERMUX_FORCE_BUILD+-f} -a $arch \
|
|
|
|
${TERMUX_DEBUG+-d} ${TERMUX_DEBDIR+-o $TERMUX_DEBDIR} "$1"
|
2017-01-06 02:37:45 +01:00
|
|
|
done
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check the package to build:
|
|
|
|
TERMUX_PKG_NAME=$(basename "$1")
|
|
|
|
export TERMUX_SCRIPTDIR
|
|
|
|
TERMUX_SCRIPTDIR=$(cd "$(dirname "$0")"; pwd)
|
|
|
|
if [[ $1 == *"/"* ]]; then
|
|
|
|
# Path to directory which may be outside this repo:
|
|
|
|
if [ ! -d "$1" ]; then termux_error_exit "'$1' seems to be a path but is not a directory"; fi
|
|
|
|
export TERMUX_PKG_BUILDER_DIR
|
|
|
|
TERMUX_PKG_BUILDER_DIR=$(realpath "$1")
|
|
|
|
else
|
|
|
|
# Package name:
|
|
|
|
if [ -n "${TERMUX_IS_DISABLED=""}" ]; then
|
|
|
|
export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/disabled-packages/$TERMUX_PKG_NAME
|
|
|
|
else
|
|
|
|
export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/packages/$TERMUX_PKG_NAME
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
TERMUX_PKG_BUILDER_SCRIPT=$TERMUX_PKG_BUILDER_DIR/build.sh
|
|
|
|
if test ! -f "$TERMUX_PKG_BUILDER_SCRIPT"; then
|
|
|
|
termux_error_exit "No build.sh script at package dir $TERMUX_PKG_BUILDER_DIR!"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Setup variables used by the build. Not to be overridden by packages.
|
|
|
|
termux_step_setup_variables() {
|
2018-08-27 22:27:42 +02:00
|
|
|
# shellcheck source=scripts/properties.sh
|
|
|
|
. "$TERMUX_SCRIPTDIR/scripts/properties.sh"
|
2017-05-04 22:21:52 +02:00
|
|
|
: "${TERMUX_MAKE_PROCESSES:="$(nproc)"}"
|
2017-01-06 02:37:45 +01:00
|
|
|
: "${TERMUX_TOPDIR:="$HOME/.termux-build"}"
|
|
|
|
: "${TERMUX_ARCH:="aarch64"}" # arm, aarch64, i686 or x86_64.
|
|
|
|
: "${TERMUX_PREFIX:="/data/data/com.termux/files/usr"}"
|
|
|
|
: "${TERMUX_ANDROID_HOME:="/data/data/com.termux/files/home"}"
|
|
|
|
: "${TERMUX_DEBUG:=""}"
|
2017-07-09 21:22:49 +02:00
|
|
|
: "${TERMUX_PKG_API_LEVEL:="21"}"
|
2018-08-23 00:10:00 +02:00
|
|
|
: "${TERMUX_DEBDIR:="${TERMUX_SCRIPTDIR}/debs"}"
|
2017-01-06 02:37:45 +01:00
|
|
|
|
2017-01-07 07:14:06 +01:00
|
|
|
if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then
|
2017-01-06 02:37:45 +01:00
|
|
|
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
|
|
|
|
|
|
|
|
if [ ! -d "$NDK" ]; then
|
|
|
|
termux_error_exit 'NDK not pointing at a directory!'
|
|
|
|
fi
|
|
|
|
if ! grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION" "$NDK/source.properties"; then
|
|
|
|
termux_error_exit "Wrong NDK version - we need $TERMUX_NDK_VERSION"
|
|
|
|
fi
|
|
|
|
|
2017-01-07 06:38:04 +01:00
|
|
|
# The build tuple that may be given to --build configure flag:
|
|
|
|
TERMUX_BUILD_TUPLE=$(sh "$TERMUX_SCRIPTDIR/scripts/config.guess")
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# We do not put all of build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/ into PATH
|
|
|
|
# to avoid stuff like arm-linux-androideabi-ld there to conflict with ones from
|
|
|
|
# the standalone toolchain.
|
2018-07-26 12:21:43 +02:00
|
|
|
TERMUX_D8=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/d8
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
TERMUX_COMMON_CACHEDIR="$TERMUX_TOPDIR/_cache"
|
|
|
|
TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner
|
|
|
|
|
|
|
|
export prefix=${TERMUX_PREFIX}
|
|
|
|
export PREFIX=${TERMUX_PREFIX}
|
|
|
|
|
|
|
|
TERMUX_PKG_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/build
|
|
|
|
TERMUX_PKG_CACHEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/cache
|
|
|
|
TERMUX_PKG_MASSAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/massage
|
|
|
|
TERMUX_PKG_PACKAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/package
|
|
|
|
TERMUX_PKG_SRCDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/src
|
|
|
|
TERMUX_PKG_SHA256=""
|
|
|
|
TERMUX_PKG_TMPDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/tmp
|
|
|
|
TERMUX_PKG_HOSTBUILD_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/host-build
|
|
|
|
TERMUX_PKG_PLATFORM_INDEPENDENT=""
|
|
|
|
TERMUX_PKG_NO_DEVELSPLIT=""
|
2017-01-11 07:21:42 +01:00
|
|
|
TERMUX_PKG_REVISION="0" # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
|
2017-01-06 02:37:45 +01:00
|
|
|
TERMUX_PKG_EXTRA_CONFIGURE_ARGS=""
|
|
|
|
TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS=""
|
|
|
|
TERMUX_PKG_EXTRA_MAKE_ARGS=""
|
|
|
|
TERMUX_PKG_BUILD_IN_SRC=""
|
|
|
|
TERMUX_PKG_RM_AFTER_INSTALL=""
|
2017-07-31 22:31:05 +02:00
|
|
|
TERMUX_PKG_BREAKS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
|
2017-01-06 02:37:45 +01:00
|
|
|
TERMUX_PKG_DEPENDS=""
|
2017-08-08 13:28:52 +02:00
|
|
|
TERMUX_PKG_BUILD_DEPENDS=""
|
2017-01-06 02:37:45 +01:00
|
|
|
TERMUX_PKG_HOMEPAGE=""
|
|
|
|
TERMUX_PKG_DESCRIPTION="FIXME:Add description"
|
|
|
|
TERMUX_PKG_KEEP_STATIC_LIBRARIES="false"
|
|
|
|
TERMUX_PKG_ESSENTIAL=""
|
|
|
|
TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts
|
2017-07-31 13:25:53 +02:00
|
|
|
TERMUX_PKG_RECOMMENDS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps
|
2018-06-04 01:35:38 +02:00
|
|
|
TERMUX_PKG_SUGGESTS=""
|
2017-01-06 02:37:45 +01:00
|
|
|
TERMUX_PKG_REPLACES=""
|
2018-06-17 15:23:20 +02:00
|
|
|
TERMUX_PKG_PROVIDES="" #https://www.debian.org/doc/debian-policy/#virtual-packages-provides
|
2017-01-06 02:37:45 +01:00
|
|
|
TERMUX_PKG_CONFFILES=""
|
|
|
|
TERMUX_PKG_INCLUDE_IN_DEVPACKAGE=""
|
|
|
|
TERMUX_PKG_DEVPACKAGE_DEPENDS=""
|
|
|
|
# Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR:
|
|
|
|
TERMUX_PKG_HOSTBUILD=""
|
|
|
|
TERMUX_PKG_MAINTAINER="Fredrik Fornwall @fornwall"
|
2017-01-15 13:48:05 +01:00
|
|
|
TERMUX_PKG_FORCE_CMAKE=no # if the package has autotools as well as cmake, then set this to prefer cmake
|
2018-08-23 17:52:08 +02:00
|
|
|
TERMUX_CMAKE_BUILD=Ninja # Which cmake generator to use
|
2018-06-13 02:12:36 +02:00
|
|
|
TERMUX_PKG_HAS_DEBUG=yes # set to no if debug build doesn't exist or doesn't work, for example for python based packages
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
unset CFLAGS CPPFLAGS LDFLAGS CXXFLAGS
|
|
|
|
}
|
|
|
|
|
|
|
|
# Save away and restore build setups which may change between builds.
|
|
|
|
termux_step_handle_buildarch() {
|
|
|
|
# If $TERMUX_PREFIX already exists, it may have been built for a different arch
|
|
|
|
local TERMUX_ARCH_FILE=/data/TERMUX_ARCH
|
|
|
|
if [ -f "${TERMUX_ARCH_FILE}" ]; then
|
|
|
|
local TERMUX_PREVIOUS_ARCH
|
|
|
|
TERMUX_PREVIOUS_ARCH=$(cat $TERMUX_ARCH_FILE)
|
|
|
|
if [ "$TERMUX_PREVIOUS_ARCH" != "$TERMUX_ARCH" ]; then
|
|
|
|
local TERMUX_DATA_BACKUPDIRS=$TERMUX_TOPDIR/_databackups
|
|
|
|
mkdir -p "$TERMUX_DATA_BACKUPDIRS"
|
|
|
|
local TERMUX_DATA_PREVIOUS_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_PREVIOUS_ARCH
|
|
|
|
local TERMUX_DATA_CURRENT_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_ARCH
|
|
|
|
# Save current /data (removing old backup if any)
|
|
|
|
if test -e "$TERMUX_DATA_PREVIOUS_BACKUPDIR"; then
|
|
|
|
termux_error_exit "Directory already exists"
|
|
|
|
fi
|
2017-06-16 23:27:05 +02:00
|
|
|
if [ -d /data/data ]; then
|
|
|
|
mv /data/data "$TERMUX_DATA_PREVIOUS_BACKUPDIR"
|
|
|
|
fi
|
2017-01-06 02:37:45 +01:00
|
|
|
# Restore new one (if any)
|
|
|
|
if [ -d "$TERMUX_DATA_CURRENT_BACKUPDIR" ]; then
|
|
|
|
mv "$TERMUX_DATA_CURRENT_BACKUPDIR" /data/data
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Keep track of current arch we are building for.
|
|
|
|
echo "$TERMUX_ARCH" > $TERMUX_ARCH_FILE
|
2016-05-31 01:25:12 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Source the package build script and start building. No to be overridden by packages.
|
|
|
|
termux_step_start_build() {
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "$TERMUX_PKG_BUILDER_SCRIPT"
|
2016-05-31 01:25:12 +02:00
|
|
|
|
2018-05-27 15:06:06 +02:00
|
|
|
TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_COMMON_CACHEDIR/${TERMUX_NDK_VERSION}-${TERMUX_ARCH}-${TERMUX_PKG_API_LEVEL}"
|
2017-07-12 11:22:07 +02:00
|
|
|
# Bump the below version if a change is made in toolchain setup to ensure
|
|
|
|
# that everyone gets an updated toolchain:
|
2018-05-27 14:55:20 +02:00
|
|
|
TERMUX_STANDALONE_TOOLCHAIN+="-v1"
|
2017-07-12 11:22:07 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ -n "${TERMUX_PKG_BLACKLISTED_ARCHES:=""}" ] && [ "$TERMUX_PKG_BLACKLISTED_ARCHES" != "${TERMUX_PKG_BLACKLISTED_ARCHES/$TERMUX_ARCH/}" ]; then
|
|
|
|
echo "Skipping building $TERMUX_PKG_NAME for arch $TERMUX_ARCH"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${TERMUX_SKIP_DEPCHECK:=""}" ]; then
|
2017-01-08 14:01:22 +01:00
|
|
|
local p TERMUX_ALL_DEPS
|
2017-11-04 01:18:32 +01:00
|
|
|
TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_BUILDER_DIR")
|
2017-01-08 14:01:22 +01:00
|
|
|
for p in $TERMUX_ALL_DEPS; do
|
2017-11-04 01:18:32 +01:00
|
|
|
echo "Building dependency $p if necessary..."
|
2018-08-23 22:18:10 +02:00
|
|
|
# Built dependencies are put in the default TERMUX_DEBDIR instead of the specified one
|
2017-11-04 01:18:32 +01:00
|
|
|
./build-package.sh -a $TERMUX_ARCH -s "$p"
|
2017-01-06 02:37:45 +01:00
|
|
|
done
|
|
|
|
fi
|
2015-12-21 02:47:48 +01:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
TERMUX_PKG_FULLVERSION=$TERMUX_PKG_VERSION
|
2017-01-11 07:21:42 +01:00
|
|
|
if [ "$TERMUX_PKG_REVISION" != "0" ] || [ "$TERMUX_PKG_FULLVERSION" != "${TERMUX_PKG_FULLVERSION/-/}" ]; then
|
2017-01-06 02:37:45 +01:00
|
|
|
# "0" is the default revision, so only include it if the upstream versions contains "-" itself
|
2017-01-11 07:21:42 +01:00
|
|
|
TERMUX_PKG_FULLVERSION+="-$TERMUX_PKG_REVISION"
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2018-03-04 20:05:40 +01:00
|
|
|
if [ "$TERMUX_DEBUG" == "true" ]; then
|
2018-06-13 02:12:36 +02:00
|
|
|
if [ "$TERMUX_PKG_HAS_DEBUG" == "yes" ]; then
|
|
|
|
DEBUG="-dbg"
|
|
|
|
else
|
|
|
|
echo "Skipping building debug build for $TERMUX_PKG_NAME"
|
|
|
|
exit 0
|
|
|
|
fi
|
2018-03-04 20:05:40 +01:00
|
|
|
else
|
|
|
|
DEBUG=""
|
|
|
|
fi
|
|
|
|
|
2017-02-02 22:14:29 +01:00
|
|
|
if [ -z "$TERMUX_DEBUG" ] &&
|
|
|
|
[ -z "${TERMUX_FORCE_BUILD+x}" ] &&
|
|
|
|
[ -e "/data/data/.built-packages/$TERMUX_PKG_NAME" ]; then
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ "$(cat "/data/data/.built-packages/$TERMUX_PKG_NAME")" = "$TERMUX_PKG_FULLVERSION" ]; then
|
|
|
|
echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION built - skipping (rm /data/data/.built-packages/$TERMUX_PKG_NAME to force rebuild)"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Cleanup old state:
|
|
|
|
rm -Rf "$TERMUX_PKG_BUILDDIR" \
|
|
|
|
"$TERMUX_PKG_PACKAGEDIR" \
|
|
|
|
"$TERMUX_PKG_SRCDIR" \
|
|
|
|
"$TERMUX_PKG_TMPDIR" \
|
|
|
|
"$TERMUX_PKG_MASSAGEDIR"
|
|
|
|
|
|
|
|
# Ensure folders present (but not $TERMUX_PKG_SRCDIR, it will be created in build)
|
|
|
|
mkdir -p "$TERMUX_COMMON_CACHEDIR" \
|
|
|
|
"$TERMUX_DEBDIR" \
|
|
|
|
"$TERMUX_PKG_BUILDDIR" \
|
|
|
|
"$TERMUX_PKG_PACKAGEDIR" \
|
|
|
|
"$TERMUX_PKG_TMPDIR" \
|
|
|
|
"$TERMUX_PKG_CACHEDIR" \
|
|
|
|
"$TERMUX_PKG_MASSAGEDIR" \
|
|
|
|
$TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp,include}
|
|
|
|
|
|
|
|
# Make $TERMUX_PREFIX/bin/sh executable on the builder, so that build
|
|
|
|
# scripts can assume that it works on both builder and host later on:
|
|
|
|
ln -f -s /bin/sh "$TERMUX_PREFIX/bin/sh"
|
|
|
|
|
2017-04-06 23:33:45 +02:00
|
|
|
local TERMUX_ELF_CLEANER_SRC=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner.cpp
|
2018-08-27 22:27:42 +02:00
|
|
|
local TERMUX_ELF_CLEANER_VERSION
|
|
|
|
TERMUX_ELF_CLEANER_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/build.sh; echo \$TERMUX_PKG_VERSION")
|
2017-04-06 23:33:45 +02:00
|
|
|
termux_download \
|
2018-08-27 22:27:42 +02:00
|
|
|
"https://raw.githubusercontent.com/termux/termux-elf-cleaner/v$TERMUX_ELF_CLEANER_VERSION/termux-elf-cleaner.cpp" \
|
|
|
|
"$TERMUX_ELF_CLEANER_SRC" \
|
2017-11-04 02:50:45 +01:00
|
|
|
62c3cf9813756a1b262108fbc39684c5cfd3f9a69b376276bb1ac6af138f5fa2
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ "$TERMUX_ELF_CLEANER_SRC" -nt "$TERMUX_ELF_CLEANER" ]; then
|
|
|
|
g++ -std=c++11 -Wall -Wextra -pedantic -Os "$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$TERMUX_PKG_BUILD_IN_SRC" ]; then
|
|
|
|
echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set" > "$TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt"
|
|
|
|
TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..."
|
|
|
|
test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME"
|
|
|
|
|
2017-07-02 11:37:35 +02:00
|
|
|
# Avoid exporting PKG_CONFIG_LIBDIR until after termux_step_host_build.
|
|
|
|
export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig
|
|
|
|
# Add a pkg-config file for the system zlib.
|
2017-07-02 11:56:40 +02:00
|
|
|
mkdir -p "$TERMUX_PKG_CONFIG_LIBDIR"
|
2017-07-02 11:37:35 +02:00
|
|
|
cat > "$TERMUX_PKG_CONFIG_LIBDIR/zlib.pc" <<-HERE
|
2017-01-06 02:37:45 +01:00
|
|
|
Name: zlib
|
|
|
|
Description: zlib compression library
|
|
|
|
Version: 1.2.8
|
|
|
|
Requires:
|
|
|
|
Libs: -lz
|
|
|
|
HERE
|
|
|
|
|
|
|
|
# Keep track of when build started so we can see what files have been created.
|
|
|
|
# We start by sleeping so that any generated files above (such as zlib.pc) get
|
|
|
|
# an older timestamp than the TERMUX_BUILD_TS_FILE.
|
|
|
|
sleep 1
|
|
|
|
TERMUX_BUILD_TS_FILE=$TERMUX_PKG_TMPDIR/timestamp_$TERMUX_PKG_NAME
|
|
|
|
touch "$TERMUX_BUILD_TS_FILE"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. May be overridden by packages.
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_extract_package() {
|
2018-06-22 01:12:41 +02:00
|
|
|
if [ -z "${TERMUX_PKG_SRCURL:=""}" ] || [ -n "${TERMUX_PKG_SKIP_SRC_EXTRACT:=""}" ]; then
|
2017-01-06 02:37:45 +01:00
|
|
|
mkdir -p "$TERMUX_PKG_SRCDIR"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
cd "$TERMUX_PKG_TMPDIR"
|
2018-06-13 02:15:26 +02:00
|
|
|
local PKG_SRCURL=(${TERMUX_PKG_SRCURL[@]})
|
|
|
|
local PKG_SHA256=(${TERMUX_PKG_SHA256[@]})
|
|
|
|
if [ ! ${#PKG_SRCURL[@]} == ${#PKG_SHA256[@]} ] && [ ! ${#PKG_SHA256[@]} == 0 ]; then
|
|
|
|
termux_error_exit "Error: length of TERMUX_PKG_SRCURL isn't equal to length of TERMUX_PKG_SHA256."
|
2015-06-13 01:03:31 +02:00
|
|
|
fi
|
2018-06-13 02:15:26 +02:00
|
|
|
# STRIP=1 extracts archives straight into TERMUX_PKG_SRCDIR while STRIP=0 puts them in subfolders. zip has same behaviour per default
|
2018-06-26 04:53:02 +02:00
|
|
|
# If this isn't desired then this can be fixed in termux_step_post_extract_package.
|
2018-06-13 02:15:26 +02:00
|
|
|
local STRIP=1
|
|
|
|
for i in $(seq 0 $(( ${#PKG_SRCURL[@]}-1 ))); do
|
2018-08-27 22:27:42 +02:00
|
|
|
test "$i" -gt 0 && STRIP=0
|
|
|
|
local filename
|
|
|
|
filename=$(basename "${PKG_SRCURL[$i]}")
|
2018-06-13 02:15:26 +02:00
|
|
|
local file="$TERMUX_PKG_CACHEDIR/$filename"
|
|
|
|
# Allow TERMUX_PKG_SHA256 to be empty:
|
|
|
|
set +u
|
|
|
|
termux_download "${PKG_SRCURL[$i]}" "$file" "${PKG_SHA256[$i]}"
|
|
|
|
set -u
|
|
|
|
|
|
|
|
local folder
|
|
|
|
set +o pipefail
|
|
|
|
if [ "${file##*.}" = zip ]; then
|
|
|
|
folder=`unzip -qql "$file" | head -n1 | tr -s ' ' | cut -d' ' -f5-`
|
|
|
|
rm -Rf $folder
|
|
|
|
unzip -q "$file"
|
|
|
|
mv $folder "$TERMUX_PKG_SRCDIR"
|
|
|
|
else
|
|
|
|
mkdir -p "$TERMUX_PKG_SRCDIR"
|
|
|
|
tar xf "$file" -C "$TERMUX_PKG_SRCDIR" --strip-components=$STRIP
|
|
|
|
fi
|
|
|
|
set -o pipefail
|
|
|
|
done
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Hook for packages to act just after the package has been extracted.
|
2017-01-10 09:14:35 +01:00
|
|
|
# Invoked in $TERMUX_PKG_SRCDIR.
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_post_extract_package() {
|
2015-06-13 01:03:31 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Optional host build. Not to be overridden by packages.
|
|
|
|
termux_step_handle_hostbuild() {
|
|
|
|
if [ "x$TERMUX_PKG_HOSTBUILD" = "x" ]; then return; fi
|
2017-01-08 14:01:22 +01:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_SRCDIR"
|
|
|
|
for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do
|
|
|
|
test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | patch --silent -p1
|
|
|
|
done
|
2017-01-08 14:01:22 +01:00
|
|
|
|
|
|
|
local TERMUX_HOSTBUILD_MARKER="$TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION"
|
|
|
|
if [ ! -f "$TERMUX_HOSTBUILD_MARKER" ]; then
|
|
|
|
rm -Rf "$TERMUX_PKG_HOSTBUILD_DIR"
|
|
|
|
mkdir -p "$TERMUX_PKG_HOSTBUILD_DIR"
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_HOSTBUILD_DIR"
|
|
|
|
termux_step_host_build
|
2017-01-08 14:01:22 +01:00
|
|
|
touch "$TERMUX_HOSTBUILD_MARKER"
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-06-13 01:03:31 +02:00
|
|
|
# Perform a host build. Will be called in $TERMUX_PKG_HOSTBUILD_DIR.
|
|
|
|
# After termux_step_post_extract_package() and before termux_step_patch_package()
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_host_build() {
|
2017-01-06 02:37:45 +01:00
|
|
|
"$TERMUX_PKG_SRCDIR/configure" ${TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS}
|
2018-08-27 22:27:42 +02:00
|
|
|
make -j "$TERMUX_MAKE_PROCESSES"
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Setup a standalone Android NDK toolchain. Not to be overridden by packages.
|
|
|
|
termux_step_setup_toolchain() {
|
|
|
|
# We put this after system PATH to avoid picking up toolchain stripped python
|
|
|
|
export PATH=$PATH:$TERMUX_STANDALONE_TOOLCHAIN/bin
|
|
|
|
|
2017-07-09 21:22:49 +02:00
|
|
|
export CFLAGS=""
|
2017-01-17 15:51:59 +01:00
|
|
|
export LDFLAGS="-L${TERMUX_PREFIX}/lib"
|
|
|
|
|
2018-09-11 22:43:19 +02:00
|
|
|
export AS=${TERMUX_HOST_PLATFORM}-clang
|
|
|
|
export CC=$TERMUX_HOST_PLATFORM-clang
|
|
|
|
export CXX=$TERMUX_HOST_PLATFORM-clang++
|
2017-01-17 15:51:59 +01:00
|
|
|
|
|
|
|
export AR=$TERMUX_HOST_PLATFORM-ar
|
2017-01-06 02:37:45 +01:00
|
|
|
export CPP=${TERMUX_HOST_PLATFORM}-cpp
|
|
|
|
export CC_FOR_BUILD=gcc
|
|
|
|
export LD=$TERMUX_HOST_PLATFORM-ld
|
|
|
|
export OBJDUMP=$TERMUX_HOST_PLATFORM-objdump
|
|
|
|
# Setup pkg-config for cross-compiling:
|
|
|
|
export PKG_CONFIG=$TERMUX_STANDALONE_TOOLCHAIN/bin/${TERMUX_HOST_PLATFORM}-pkg-config
|
|
|
|
export RANLIB=$TERMUX_HOST_PLATFORM-ranlib
|
|
|
|
export READELF=$TERMUX_HOST_PLATFORM-readelf
|
|
|
|
export STRIP=$TERMUX_HOST_PLATFORM-strip
|
|
|
|
|
|
|
|
# Android 7 started to support DT_RUNPATH (but not DT_RPATH), so we may want
|
|
|
|
# LDFLAGS+="-Wl,-rpath=$TERMUX_PREFIX/lib -Wl,--enable-new-dtags"
|
|
|
|
# and no longer remove DT_RUNPATH in termux-elf-cleaner.
|
|
|
|
|
|
|
|
if [ "$TERMUX_ARCH" = "arm" ]; then
|
2017-01-19 03:58:44 +01:00
|
|
|
# https://developer.android.com/ndk/guides/standalone_toolchain.html#abi_compatibility:
|
|
|
|
# "We recommend using the -mthumb compiler flag to force the generation of 16-bit Thumb-2 instructions".
|
|
|
|
# With r13 of the ndk ruby 2.4.0 segfaults when built on arm with clang without -mthumb.
|
|
|
|
CFLAGS+=" -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb"
|
2017-07-15 09:59:30 +02:00
|
|
|
LDFLAGS+=" -march=armv7-a"
|
2017-01-06 02:37:45 +01:00
|
|
|
elif [ "$TERMUX_ARCH" = "i686" ]; then
|
|
|
|
# From $NDK/docs/CPU-ARCH-ABIS.html:
|
|
|
|
CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse"
|
|
|
|
elif [ "$TERMUX_ARCH" = "aarch64" ]; then
|
2017-01-18 04:03:55 +01:00
|
|
|
:
|
2017-01-06 02:37:45 +01:00
|
|
|
elif [ "$TERMUX_ARCH" = "x86_64" ]; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
termux_error_exit "Invalid arch '$TERMUX_ARCH' - support arches are 'arm', 'i686', 'aarch64', 'x86_64'"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$TERMUX_DEBUG" ]; then
|
|
|
|
CFLAGS+=" -g3 -O1 -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
|
|
|
|
else
|
2018-09-20 02:43:14 +02:00
|
|
|
if [ $TERMUX_ARCH = arm ]; then
|
|
|
|
CFLAGS+=" -Os"
|
|
|
|
else
|
|
|
|
CFLAGS+=" -Oz"
|
|
|
|
fi
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
export CXXFLAGS="$CFLAGS"
|
|
|
|
export CPPFLAGS="-I${TERMUX_PREFIX}/include"
|
|
|
|
|
|
|
|
if [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libandroid-support/}" ]; then
|
|
|
|
# If using the android support library, link to it and include its headers as system headers:
|
|
|
|
CPPFLAGS+=" -isystem $TERMUX_PREFIX/include/libandroid-support"
|
|
|
|
LDFLAGS+=" -landroid-support"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export ac_cv_func_getpwent=no
|
|
|
|
export ac_cv_func_getpwnam=no
|
|
|
|
export ac_cv_func_getpwuid=no
|
2017-07-07 03:52:46 +02:00
|
|
|
export ac_cv_func_sigsetmask=no
|
2018-09-22 01:05:16 +02:00
|
|
|
export ac_cv_c_bigendian=no
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then
|
|
|
|
# Do not put toolchain in place until we are done with setup, to avoid having a half setup
|
|
|
|
# toolchain left in place if something goes wrong (or process is just aborted):
|
2017-01-15 21:13:22 +01:00
|
|
|
local _TERMUX_TOOLCHAIN_TMPDIR=${TERMUX_STANDALONE_TOOLCHAIN}-tmp
|
2017-01-06 02:37:45 +01:00
|
|
|
rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR
|
|
|
|
|
|
|
|
local _NDK_ARCHNAME=$TERMUX_ARCH
|
|
|
|
if [ "$TERMUX_ARCH" = "aarch64" ]; then
|
|
|
|
_NDK_ARCHNAME=arm64
|
|
|
|
elif [ "$TERMUX_ARCH" = "i686" ]; then
|
|
|
|
_NDK_ARCHNAME=x86
|
|
|
|
fi
|
2017-01-15 21:13:22 +01:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
"$NDK/build/tools/make_standalone_toolchain.py" \
|
2017-07-09 21:22:49 +02:00
|
|
|
--api "$TERMUX_PKG_API_LEVEL" \
|
2017-01-06 02:37:45 +01:00
|
|
|
--arch $_NDK_ARCHNAME \
|
2017-07-14 00:23:37 +02:00
|
|
|
--stl=libc++ \
|
2017-01-06 02:37:45 +01:00
|
|
|
--install-dir $_TERMUX_TOOLCHAIN_TMPDIR
|
|
|
|
|
2017-07-14 00:23:37 +02:00
|
|
|
# Remove android-support header wrapping not needed on android-21:
|
|
|
|
rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/local
|
|
|
|
|
|
|
|
if [ "$TERMUX_ARCH" = "aarch64" ]; then
|
2017-01-18 04:03:55 +01:00
|
|
|
# Use gold by default to work around https://github.com/android-ndk/ndk/issues/148
|
|
|
|
cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld.gold \
|
2018-05-27 14:55:20 +02:00
|
|
|
$_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld
|
2017-01-19 02:51:17 +01:00
|
|
|
cp $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld.gold \
|
2018-05-27 14:55:20 +02:00
|
|
|
$_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
|
|
|
|
2017-07-27 02:06:37 +02:00
|
|
|
if [ "$TERMUX_ARCH" = "arm" ]; then
|
|
|
|
# Linker wrapper script to add '--exclude-libs libgcc.a', see
|
|
|
|
# https://github.com/android-ndk/ndk/issues/379
|
|
|
|
# https://android-review.googlesource.com/#/c/389852/
|
|
|
|
local linker
|
|
|
|
for linker in ld ld.bfd ld.gold; do
|
|
|
|
local wrap_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker
|
|
|
|
local real_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker.real
|
|
|
|
cp $wrap_linker $real_linker
|
|
|
|
echo '#!/bin/bash' > $wrap_linker
|
|
|
|
echo -n '`dirname $0`/' >> $wrap_linker
|
|
|
|
echo -n $linker.real >> $wrap_linker
|
|
|
|
echo ' --exclude-libs libgcc.a "$@"' >> $wrap_linker
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2018-09-19 23:29:39 +02:00
|
|
|
# Setup the cpp preprocessor:
|
|
|
|
cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/$TERMUX_HOST_PLATFORM-clang \
|
|
|
|
$_TERMUX_TOOLCHAIN_TMPDIR/bin/$TERMUX_HOST_PLATFORM-cpp
|
|
|
|
sed -i 's/clang70/clang70 -E/' \
|
|
|
|
$_TERMUX_TOOLCHAIN_TMPDIR/bin/$TERMUX_HOST_PLATFORM-cpp
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot
|
|
|
|
|
2017-07-01 00:04:02 +02:00
|
|
|
for f in $TERMUX_SCRIPTDIR/ndk-patches/*.patch; do
|
2017-01-06 02:37:45 +01:00
|
|
|
sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$f" | \
|
|
|
|
sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \
|
|
|
|
patch --silent -p1;
|
|
|
|
done
|
2017-02-17 22:33:57 +01:00
|
|
|
# elf.h: Taken from glibc since the elf.h in the NDK is lacking.
|
|
|
|
# ifaddrs.h: Added in android-24 unified headers, use a inline implementation for now.
|
2018-05-27 14:55:20 +02:00
|
|
|
cp "$TERMUX_SCRIPTDIR"/ndk-patches/{ifaddrs.h,libintl.h} usr/include
|
2017-01-06 02:37:45 +01:00
|
|
|
|
2017-03-05 14:22:31 +01:00
|
|
|
# Remove <sys/shm.h> from the NDK in favour of that from the libandroid-shmem.
|
2017-11-15 16:48:35 +01:00
|
|
|
# Remove <sys/sem.h> as it doesn't work for non-root.
|
|
|
|
# Remove <iconv.h> as we currently provide it from libandroid-support.
|
|
|
|
# Remove <glob.h> as we currently provide it from libandroid-glob.
|
2017-11-15 19:35:34 +01:00
|
|
|
# Remove <spawn.h> as it's only for future (later than android-27).
|
|
|
|
rm usr/include/sys/{shm.h,sem.h} usr/include/{iconv.h,glob.h,spawn.h}
|
2017-07-01 02:25:36 +02:00
|
|
|
|
2017-07-09 21:22:49 +02:00
|
|
|
sed -i "s/define __ANDROID_API__ __ANDROID_API_FUTURE__/define __ANDROID_API__ $TERMUX_PKG_API_LEVEL/" \
|
2017-07-01 02:25:36 +02:00
|
|
|
usr/include/android/api-level.h
|
2017-03-05 11:42:26 +01:00
|
|
|
|
2017-03-04 22:03:54 +01:00
|
|
|
local _LIBDIR=usr/lib
|
|
|
|
if [ $TERMUX_ARCH = x86_64 ]; then _LIBDIR+=64; fi
|
|
|
|
$TERMUX_ELF_CLEANER $_LIBDIR/*.so
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
# zlib is really version 1.2.8 in the Android platform (at least
|
|
|
|
# starting from Android 5), not older as the NDK headers claim.
|
|
|
|
for file in zconf.h zlib.h; do
|
2017-07-01 02:25:36 +02:00
|
|
|
curl -o usr/include/$file \
|
2017-01-06 02:37:45 +01:00
|
|
|
https://raw.githubusercontent.com/madler/zlib/v1.2.8/$file
|
|
|
|
done
|
|
|
|
unset file
|
2017-07-16 07:43:56 +02:00
|
|
|
cd $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x
|
|
|
|
sed "s%\@TERMUX_HOST_PLATFORM\@%${TERMUX_HOST_PLATFORM}%g" $TERMUX_SCRIPTDIR/ndk-patches/*.cpppatch | patch -p1
|
2018-09-19 23:29:39 +02:00
|
|
|
# Fix relative path in gcc/g++ script:
|
|
|
|
sed -i "s%\`dirname \$0\`/../../../../%$NDK/toolchains/%g" $_TERMUX_TOOLCHAIN_TMPDIR/bin/${TERMUX_HOST_PLATFORM}-gcc
|
|
|
|
sed -i "s%\`dirname \$0\`/../../../../%$NDK/toolchains/%g" $_TERMUX_TOOLCHAIN_TMPDIR/bin/${TERMUX_HOST_PLATFORM}-g++
|
2017-01-06 02:37:45 +01:00
|
|
|
mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN
|
|
|
|
fi
|
|
|
|
|
2017-07-14 00:23:37 +02:00
|
|
|
local _STL_LIBFILE_NAME=libc++_shared.so
|
2017-07-27 02:06:37 +02:00
|
|
|
if [ ! -f $TERMUX_PREFIX/lib/libstdc++.so ]; then
|
2017-11-19 14:38:48 +01:00
|
|
|
# Setup libc++_shared.so in $PREFIX/lib and libstdc++.so as a link to it,
|
2017-01-06 02:37:45 +01:00
|
|
|
# so that other C++ using packages links to it instead of the default android
|
|
|
|
# C++ library which does not support exceptions or STL:
|
|
|
|
# https://developer.android.com/ndk/guides/cpp-support.html
|
|
|
|
# We do however want to avoid installing this, to avoid problems where e.g.
|
|
|
|
# libm.so on some i686 devices links against libstdc++.so.
|
2017-11-19 14:38:48 +01:00
|
|
|
# The libc++_shared.so library will be packaged in the libc++ package
|
2017-01-06 02:37:45 +01:00
|
|
|
# which is part of the base Termux installation.
|
|
|
|
mkdir -p "$TERMUX_PREFIX/lib"
|
|
|
|
cd "$TERMUX_PREFIX/lib"
|
2017-07-14 00:23:37 +02:00
|
|
|
|
|
|
|
local _STL_LIBFILE=
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ "$TERMUX_ARCH" = arm ]; then
|
2017-07-14 00:23:37 +02:00
|
|
|
local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/armv7-a/$_STL_LIBFILE_NAME
|
2017-01-06 02:37:45 +01:00
|
|
|
elif [ "$TERMUX_ARCH" = x86_64 ]; then
|
2017-07-14 00:23:37 +02:00
|
|
|
local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/$_STL_LIBFILE_NAME
|
|
|
|
else
|
|
|
|
local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/$_STL_LIBFILE_NAME
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
2017-07-14 00:23:37 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
cp "$_STL_LIBFILE" .
|
2017-07-14 00:23:37 +02:00
|
|
|
$STRIP --strip-unneeded $_STL_LIBFILE_NAME
|
|
|
|
$TERMUX_ELF_CLEANER $_STL_LIBFILE_NAME
|
2017-07-27 02:06:37 +02:00
|
|
|
if [ $TERMUX_ARCH = "arm" ]; then
|
|
|
|
# Use a linker script to get libunwind.a.
|
|
|
|
echo 'INPUT(-lunwind -lc++_shared)' > libstdc++.so
|
|
|
|
else
|
|
|
|
ln -f $_STL_LIBFILE_NAME libstdc++.so
|
|
|
|
fi
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
|
|
|
|
2017-07-02 11:37:35 +02:00
|
|
|
export PKG_CONFIG_LIBDIR="$TERMUX_PKG_CONFIG_LIBDIR"
|
2017-01-06 02:37:45 +01:00
|
|
|
# Create a pkg-config wrapper. We use path to host pkg-config to
|
|
|
|
# avoid picking up a cross-compiled pkg-config later on.
|
|
|
|
local _HOST_PKGCONFIG
|
|
|
|
_HOST_PKGCONFIG=$(which pkg-config)
|
|
|
|
mkdir -p $TERMUX_STANDALONE_TOOLCHAIN/bin "$PKG_CONFIG_LIBDIR"
|
|
|
|
cat > "$PKG_CONFIG" <<-HERE
|
|
|
|
#!/bin/sh
|
|
|
|
export PKG_CONFIG_DIR=
|
|
|
|
export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR
|
|
|
|
exec $_HOST_PKGCONFIG "\$@"
|
|
|
|
HERE
|
|
|
|
chmod +x "$PKG_CONFIG"
|
|
|
|
}
|
|
|
|
|
2017-01-07 06:38:04 +01:00
|
|
|
# Apply all *.patch files for the package. Not to be overridden by packages.
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_patch_package() {
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_SRCDIR"
|
2018-06-13 02:12:36 +02:00
|
|
|
local DEBUG_PATCHES=""
|
|
|
|
if [ "$TERMUX_DEBUG" == "true" ] && [ -f $TERMUX_PKG_BUILDER_DIR/*.patch.debug ] ; then
|
|
|
|
DEBUG_PATCHES="$(ls $TERMUX_PKG_BUILDER_DIR/*.patch.debug)"
|
|
|
|
fi
|
2015-06-25 12:36:03 +02:00
|
|
|
# Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses:
|
2017-03-05 11:40:50 +01:00
|
|
|
shopt -s nullglob
|
2018-06-13 02:12:36 +02:00
|
|
|
for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,} $DEBUG_PATCHES; do
|
2017-01-06 02:37:45 +01:00
|
|
|
test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | \
|
2016-04-19 23:05:07 +02:00
|
|
|
sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \
|
2016-06-04 00:41:30 +02:00
|
|
|
patch --silent -p1
|
2015-06-13 01:03:31 +02:00
|
|
|
done
|
2017-03-05 11:49:01 +01:00
|
|
|
shopt -u nullglob
|
2017-03-05 11:40:50 +01:00
|
|
|
}
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2017-03-05 11:40:50 +01:00
|
|
|
# Replace autotools build-aux/config.{sub,guess} with ours to add android targets.
|
|
|
|
termux_step_replace_guess_scripts () {
|
|
|
|
cd "$TERMUX_PKG_SRCDIR"
|
2017-01-06 02:37:45 +01:00
|
|
|
find . -name config.sub -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.sub" '{}' \;
|
|
|
|
find . -name config.guess -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.guess" '{}' \;
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# For package scripts to override. Called in $TERMUX_PKG_BUILDDIR.
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_pre_configure() {
|
2017-01-06 02:37:45 +01:00
|
|
|
return
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-15 13:48:05 +01:00
|
|
|
termux_step_configure_autotools () {
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ ! -e "$TERMUX_PKG_SRCDIR/configure" ]; then return; fi
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2018-02-21 00:06:41 +01:00
|
|
|
local DISABLE_STATIC="--disable-static"
|
2015-06-13 01:03:31 +02:00
|
|
|
if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-static/}" ]; then
|
|
|
|
# Do not --disable-static if package explicitly enables it (e.g. gdb needs enable-static to build)
|
|
|
|
DISABLE_STATIC=""
|
|
|
|
fi
|
|
|
|
|
2018-02-21 00:06:41 +01:00
|
|
|
local DISABLE_NLS="--disable-nls"
|
2015-06-13 01:03:31 +02:00
|
|
|
if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-nls/}" ]; then
|
|
|
|
# Do not --disable-nls if package explicitly enables it (for gettext itself)
|
|
|
|
DISABLE_NLS=""
|
|
|
|
fi
|
|
|
|
|
2018-02-21 00:06:41 +01:00
|
|
|
local ENABLE_SHARED="--enable-shared"
|
2015-06-13 01:03:31 +02:00
|
|
|
if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--disable-shared/}" ]; then
|
|
|
|
ENABLE_SHARED=""
|
|
|
|
fi
|
2018-02-21 00:06:41 +01:00
|
|
|
|
|
|
|
local HOST_FLAG="--host=$TERMUX_HOST_PLATFORM"
|
2015-06-13 01:03:31 +02:00
|
|
|
if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--host=/}" ]; then
|
|
|
|
HOST_FLAG=""
|
|
|
|
fi
|
2018-02-21 00:06:41 +01:00
|
|
|
|
|
|
|
local LIBEXEC_FLAG="--libexecdir=$TERMUX_PREFIX/libexec"
|
|
|
|
if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--libexecdir=/}" ]; then
|
|
|
|
LIBEXEC_FLAG=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
local QUIET_BUILD=
|
2017-10-08 22:04:49 +02:00
|
|
|
if [ ! -z ${TERMUX_QUIET_BUILD+x} ]; then
|
2018-02-20 01:49:45 +01:00
|
|
|
QUIET_BUILD="--enable-silent-rules --silent --quiet"
|
2017-10-08 22:04:49 +02:00
|
|
|
fi
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
# Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config:
|
2017-01-06 02:37:45 +01:00
|
|
|
mkdir "$TERMUX_PKG_TMPDIR/config-scripts"
|
2015-06-13 01:03:31 +02:00
|
|
|
for f in $TERMUX_PREFIX/bin/*config; do
|
2017-01-06 02:37:45 +01:00
|
|
|
test -f "$f" && cp "$f" "$TERMUX_PKG_TMPDIR/config-scripts"
|
2015-06-13 01:03:31 +02:00
|
|
|
done
|
|
|
|
export PATH=$TERMUX_PKG_TMPDIR/config-scripts:$PATH
|
|
|
|
|
2017-02-04 01:15:26 +01:00
|
|
|
# Avoid gnulib wrapping of functions when cross compiling. See
|
|
|
|
# http://wiki.osdev.org/Cross-Porting_Software#Gnulib
|
|
|
|
# https://gitlab.com/sortix/sortix/wikis/Gnulib
|
|
|
|
# https://github.com/termux/termux-packages/issues/76
|
|
|
|
local AVOID_GNULIB=""
|
2017-07-02 11:37:35 +02:00
|
|
|
AVOID_GNULIB+=" ac_cv_func_calloc_0_nonnull=yes"
|
|
|
|
AVOID_GNULIB+=" ac_cv_func_chown_works=yes"
|
|
|
|
AVOID_GNULIB+=" ac_cv_func_getgroups_works=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
AVOID_GNULIB+=" ac_cv_func_malloc_0_nonnull=yes"
|
|
|
|
AVOID_GNULIB+=" ac_cv_func_realloc_0_nonnull=yes"
|
|
|
|
AVOID_GNULIB+=" am_cv_func_working_getline=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_dup2_works=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_cloexec=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_works=yes"
|
2017-04-02 12:38:18 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_fnmatch_posix=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_getcwd_abort_bug=no"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_getcwd_null=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_getcwd_path_max=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_getcwd_posix_signature=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_gettimeofday_clobber=no"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_gettimeofday_posix_signature=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_link_works=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_lstat_dereferences_slashed_symlink=yes"
|
2017-04-02 12:38:18 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_malloc_0_nonnull=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_memchr_works=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_dot_works=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_slash_works=yes"
|
2017-07-02 11:37:35 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_mkfifo_works=yes"
|
2017-12-29 00:07:39 +01:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_mknod_works=yes"
|
2017-06-30 21:41:25 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_realpath_works=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_select_detects_ebadf=yes"
|
2017-04-02 12:38:18 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_snprintf_posix=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_snprintf_retval_c99=yes"
|
2017-04-02 12:38:18 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_snprintf_truncation_c99=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_stat_dir_slash=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_stat_file_slash=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_strerror_0_works=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_symlink_works=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_tzset_clobber=no"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes"
|
2017-04-02 12:38:18 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_vsnprintf_posix=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_vsnprintf_zerosize_c99=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
AVOID_GNULIB+=" gl_cv_func_wcwidth_works=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_working_getdelim=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_working_mkstemp=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_working_mktime=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_func_working_strerror=yes"
|
|
|
|
AVOID_GNULIB+=" gl_cv_header_working_fcntl_h=yes"
|
2017-06-26 00:05:20 +02:00
|
|
|
AVOID_GNULIB+=" gl_cv_C_locale_sans_EILSEQ=yes"
|
2017-02-04 01:15:26 +01:00
|
|
|
|
|
|
|
# NOTE: We do not want to quote AVOID_GNULIB as we want word expansion.
|
2018-08-27 22:36:11 +02:00
|
|
|
# shellcheck disable=SC2086
|
|
|
|
env $AVOID_GNULIB "$TERMUX_PKG_SRCDIR/configure" \
|
2015-06-13 01:03:31 +02:00
|
|
|
--disable-dependency-tracking \
|
|
|
|
--prefix=$TERMUX_PREFIX \
|
2018-08-26 17:47:07 +02:00
|
|
|
--libdir=$TERMUX_PREFIX/lib \
|
2017-01-06 02:37:45 +01:00
|
|
|
--disable-rpath --disable-rpath-hack \
|
2015-06-13 01:03:31 +02:00
|
|
|
$HOST_FLAG \
|
|
|
|
$TERMUX_PKG_EXTRA_CONFIGURE_ARGS \
|
|
|
|
$DISABLE_NLS \
|
|
|
|
$ENABLE_SHARED \
|
|
|
|
$DISABLE_STATIC \
|
2017-10-08 22:04:49 +02:00
|
|
|
$LIBEXEC_FLAG \
|
|
|
|
$QUIET_BUILD
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-15 13:48:05 +01:00
|
|
|
termux_step_configure_cmake () {
|
|
|
|
termux_setup_cmake
|
|
|
|
|
|
|
|
local TOOLCHAIN_ARGS="-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=$TERMUX_STANDALONE_TOOLCHAIN"
|
|
|
|
local BUILD_TYPE=MinSizeRel
|
|
|
|
test -n "$TERMUX_DEBUG" && BUILD_TYPE=Debug
|
|
|
|
|
|
|
|
local CMAKE_PROC=$TERMUX_ARCH
|
|
|
|
test $CMAKE_PROC == "arm" && CMAKE_PROC='armv7-a'
|
2018-08-27 22:27:42 +02:00
|
|
|
local MAKE_PROGRAM_PATH
|
2018-08-21 01:00:59 +02:00
|
|
|
if [ $TERMUX_CMAKE_BUILD = Ninja ]; then
|
|
|
|
termux_setup_ninja
|
|
|
|
MAKE_PROGRAM_PATH=`which ninja`
|
2018-08-27 22:27:42 +02:00
|
|
|
else
|
|
|
|
MAKE_PROGRAM_PATH=`which make`
|
2018-08-21 01:00:59 +02:00
|
|
|
fi
|
2017-01-15 13:48:05 +01:00
|
|
|
|
2017-01-15 21:13:22 +01:00
|
|
|
# XXX: CMAKE_{AR,RANLIB} needed for at least jsoncpp build to not
|
|
|
|
# pick up cross compiled binutils tool in $PREFIX/bin:
|
2018-08-20 19:20:48 +02:00
|
|
|
cmake -G "$TERMUX_CMAKE_BUILD" "$TERMUX_PKG_SRCDIR" \
|
2017-02-02 00:40:11 +01:00
|
|
|
-DCMAKE_AR="$(which $AR)" \
|
2017-07-14 00:23:37 +02:00
|
|
|
-DCMAKE_UNAME="$(which uname)" \
|
2017-02-02 00:40:11 +01:00
|
|
|
-DCMAKE_RANLIB="$(which $RANLIB)" \
|
2017-01-15 13:48:05 +01:00
|
|
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
|
|
|
-DCMAKE_CROSSCOMPILING=True \
|
|
|
|
-DCMAKE_C_FLAGS="$CFLAGS $CPPFLAGS" \
|
2017-01-15 21:13:22 +01:00
|
|
|
-DCMAKE_CXX_FLAGS="$CXXFLAGS $CPPFLAGS" \
|
2017-01-15 13:48:05 +01:00
|
|
|
-DCMAKE_LINKER="$TERMUX_STANDALONE_TOOLCHAIN/bin/$LD $LDFLAGS" \
|
|
|
|
-DCMAKE_FIND_ROOT_PATH=$TERMUX_PREFIX \
|
|
|
|
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
|
|
|
|
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
|
|
|
|
-DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX \
|
2018-08-20 19:20:48 +02:00
|
|
|
-DCMAKE_MAKE_PROGRAM=$MAKE_PROGRAM_PATH \
|
2017-01-15 13:48:05 +01:00
|
|
|
-DCMAKE_SYSTEM_PROCESSOR=$CMAKE_PROC \
|
|
|
|
-DCMAKE_SYSTEM_NAME=Android \
|
2018-08-21 14:53:32 +02:00
|
|
|
-DCMAKE_SYSTEM_VERSION=$TERMUX_PKG_API_LEVEL \
|
2017-01-15 13:48:05 +01:00
|
|
|
-DCMAKE_SKIP_INSTALL_RPATH=ON \
|
|
|
|
-DCMAKE_USE_SYSTEM_LIBRARIES=True \
|
2018-09-06 06:36:42 +02:00
|
|
|
-DDOXYGEN_EXECUTABLE= \
|
2017-01-15 13:48:05 +01:00
|
|
|
-DBUILD_TESTING=OFF \
|
|
|
|
$TERMUX_PKG_EXTRA_CONFIGURE_ARGS $TOOLCHAIN_ARGS
|
|
|
|
}
|
|
|
|
|
2017-07-29 02:11:04 +02:00
|
|
|
termux_step_configure_meson () {
|
|
|
|
termux_setup_meson
|
|
|
|
CC=gcc CXX=g++ $TERMUX_MESON \
|
|
|
|
$TERMUX_PKG_SRCDIR \
|
|
|
|
$TERMUX_PKG_BUILDDIR \
|
|
|
|
--cross-file $TERMUX_MESON_CROSSFILE \
|
|
|
|
--prefix $TERMUX_PREFIX \
|
|
|
|
--libdir lib \
|
|
|
|
--buildtype minsize \
|
|
|
|
--strip \
|
|
|
|
$TERMUX_PKG_EXTRA_CONFIGURE_ARGS
|
|
|
|
}
|
|
|
|
|
2017-01-15 13:48:05 +01:00
|
|
|
termux_step_configure () {
|
2017-01-15 21:13:22 +01:00
|
|
|
if [ "$TERMUX_PKG_FORCE_CMAKE" == 'no' ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then
|
2017-01-15 13:48:05 +01:00
|
|
|
termux_step_configure_autotools
|
|
|
|
elif [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then
|
|
|
|
termux_step_configure_cmake
|
2017-07-29 02:11:04 +02:00
|
|
|
elif [ -f "$TERMUX_PKG_SRCDIR/meson.build" ]; then
|
|
|
|
termux_step_configure_meson
|
2017-01-15 13:48:05 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
termux_step_post_configure () {
|
2017-01-06 02:37:45 +01:00
|
|
|
return
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_make() {
|
2018-02-21 00:06:41 +01:00
|
|
|
local QUIET_BUILD=
|
2018-02-19 15:34:32 +01:00
|
|
|
if [ ! -z ${TERMUX_QUIET_BUILD+x} ]; then
|
|
|
|
QUIET_BUILD="-s"
|
|
|
|
fi
|
|
|
|
|
2018-08-23 17:52:08 +02:00
|
|
|
if test -f build.ninja; then
|
|
|
|
ninja -j $TERMUX_MAKE_PROCESSES
|
|
|
|
elif ls ./*akefile &> /dev/null || [ ! -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then
|
2018-02-19 15:34:32 +01:00
|
|
|
make -j $TERMUX_MAKE_PROCESSES $QUIET_BUILD
|
2017-01-06 02:37:45 +01:00
|
|
|
else
|
2018-02-19 15:34:32 +01:00
|
|
|
make -j $TERMUX_MAKE_PROCESSES $QUIET_BUILD ${TERMUX_PKG_EXTRA_MAKE_ARGS}
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
|
|
|
fi
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_make_install() {
|
2018-08-23 17:52:08 +02:00
|
|
|
if test -f build.ninja; then
|
|
|
|
ninja -j $TERMUX_MAKE_PROCESSES install
|
|
|
|
elif ls ./*akefile &> /dev/null || [ ! -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then
|
2017-01-10 08:05:28 +01:00
|
|
|
: "${TERMUX_PKG_MAKE_INSTALL_TARGET:="install"}"
|
2017-01-06 02:37:45 +01:00
|
|
|
# Some packages have problem with parallell install, and it does not buy much, so use -j 1.
|
|
|
|
if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then
|
|
|
|
make -j 1 ${TERMUX_PKG_MAKE_INSTALL_TARGET}
|
|
|
|
else
|
|
|
|
make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET}
|
|
|
|
fi
|
2018-09-03 23:57:26 +02:00
|
|
|
elif test -f Cargo.toml; then
|
|
|
|
termux_setup_rust
|
2018-10-18 06:12:27 +02:00
|
|
|
cargo install --force \
|
|
|
|
--target $CARGO_TARGET_NAME \
|
|
|
|
--root $TERMUX_PREFIX \
|
|
|
|
$TERMUX_PKG_EXTRA_CONFIGURE_ARGS
|
2018-09-14 20:40:34 +02:00
|
|
|
# https://github.com/rust-lang/cargo/issues/3316:
|
|
|
|
rm $TERMUX_PREFIX/.crates.toml
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Hook function for package scripts to override.
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_post_make_install() {
|
2017-01-06 02:37:45 +01:00
|
|
|
return
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_extract_into_massagedir() {
|
2017-01-06 02:37:45 +01:00
|
|
|
local TARBALL_ORIG=$TERMUX_PKG_PACKAGEDIR/${TERMUX_PKG_NAME}_orig.tar.gz
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
# Build diff tar with what has changed during the build:
|
|
|
|
cd $TERMUX_PREFIX
|
2017-07-15 02:44:13 +02:00
|
|
|
tar -N "$TERMUX_BUILD_TS_FILE" \
|
|
|
|
--exclude='lib/libc++_shared.so' --exclude='lib/libstdc++.so' \
|
|
|
|
-czf "$TARBALL_ORIG" .
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
# Extract tar in order to massage it
|
2017-01-06 02:37:45 +01:00
|
|
|
mkdir -p "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX"
|
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX"
|
2017-04-18 08:19:48 +02:00
|
|
|
tar xf "$TARBALL_ORIG"
|
2017-01-06 02:37:45 +01:00
|
|
|
rm "$TARBALL_ORIG"
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_massage() {
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX"
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
# Remove lib/charset.alias which is installed by gettext-using packages:
|
|
|
|
rm -f lib/charset.alias
|
2016-04-15 02:47:04 +02:00
|
|
|
|
2015-06-13 01:03:31 +02:00
|
|
|
# Remove non-english man pages:
|
|
|
|
test -d share/man && (cd share/man; for f in `ls | grep -v man`; do rm -Rf $f; done )
|
2016-04-15 02:47:04 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ -z "${TERMUX_PKG_KEEP_INFOPAGES+x}" ]; then
|
2016-04-15 02:47:04 +02:00
|
|
|
# Remove info pages:
|
|
|
|
rm -Rf share/info
|
|
|
|
fi
|
|
|
|
|
2016-09-20 01:07:44 +02:00
|
|
|
# Remove locale files we're not interested in::
|
|
|
|
rm -Rf share/locale
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ -z "${TERMUX_PKG_KEEP_SHARE_DOC+x}" ]; then
|
2016-09-20 01:07:44 +02:00
|
|
|
# Remove info pages:
|
|
|
|
rm -Rf share/doc
|
|
|
|
fi
|
2016-04-15 02:47:04 +02:00
|
|
|
|
2015-06-13 01:03:31 +02:00
|
|
|
# Remove old kept libraries (readline):
|
|
|
|
find . -name '*.old' -delete
|
2016-04-15 02:47:04 +02:00
|
|
|
|
|
|
|
# Remove static libraries:
|
2015-06-13 01:03:31 +02:00
|
|
|
if [ $TERMUX_PKG_KEEP_STATIC_LIBRARIES = "false" ]; then
|
|
|
|
find . -name '*.a' -delete
|
|
|
|
find . -name '*.la' -delete
|
|
|
|
fi
|
|
|
|
|
2016-10-06 23:21:04 +02:00
|
|
|
# Move over sbin to bin:
|
2017-01-06 02:37:45 +01:00
|
|
|
for file in sbin/*; do if test -f "$file"; then mv "$file" bin/; fi; done
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2017-04-17 22:23:21 +02:00
|
|
|
# Remove world permissions and add write permissions.
|
2016-08-19 15:25:48 +02:00
|
|
|
# The -f flag is used to suppress warnings about dangling symlinks (such
|
|
|
|
# as ones to /system/... which may not exist on the build machine):
|
2017-04-17 22:23:21 +02:00
|
|
|
find . -exec chmod -f u+w,g-rwx,o-rwx \{\} \;
|
|
|
|
|
2015-06-13 01:03:31 +02:00
|
|
|
if [ "$TERMUX_DEBUG" = "" ]; then
|
2016-08-16 12:53:19 +02:00
|
|
|
# Strip binaries. file(1) may fail for certain unusual files, so disable pipefail.
|
|
|
|
set +e +o pipefail
|
|
|
|
find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | \
|
2017-01-06 02:37:45 +01:00
|
|
|
xargs -r "$STRIP" --strip-unneeded --preserve-dates
|
2016-08-16 12:53:19 +02:00
|
|
|
set -e -o pipefail
|
2015-06-13 01:03:31 +02:00
|
|
|
fi
|
2016-10-06 23:21:04 +02:00
|
|
|
# Remove DT_ entries which the android 5.1 linker warns about:
|
2017-01-06 02:37:45 +01:00
|
|
|
find . -type f -print0 | xargs -r -0 "$TERMUX_ELF_CLEANER"
|
2016-10-06 23:21:04 +02:00
|
|
|
|
|
|
|
# Fix shebang paths:
|
2017-02-01 22:45:14 +01:00
|
|
|
while IFS= read -r -d '' file
|
|
|
|
do
|
|
|
|
head -c 100 "$file" | grep -E "^#\!.*\\/bin\\/.*" | grep -q -E -v "^#\! ?\\/system" && sed --follow-symlinks -i -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" "$file"
|
|
|
|
done < <(find -L . -type f -print0)
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL
|
|
|
|
|
|
|
|
find . -type d -empty -delete # Remove empty directories
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Sub packages:
|
|
|
|
if [ -d include ] && [ -z "${TERMUX_PKG_NO_DEVELSPLIT}" ]; then
|
|
|
|
# Add virtual -dev sub package if there are include files:
|
|
|
|
local _DEVEL_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-dev.subpackage.sh
|
2017-03-22 00:21:00 +01:00
|
|
|
echo TERMUX_SUBPKG_INCLUDE=\"include share/vala share/man/man3 lib/pkgconfig share/aclocal lib/cmake $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > "$_DEVEL_SUBPACKAGE_FILE"
|
2017-01-10 08:05:28 +01:00
|
|
|
echo "TERMUX_SUBPKG_DESCRIPTION=\"Development files for ${TERMUX_PKG_NAME}\"" >> "$_DEVEL_SUBPACKAGE_FILE"
|
2016-07-20 00:48:39 +02:00
|
|
|
if [ -n "$TERMUX_PKG_DEVPACKAGE_DEPENDS" ]; then
|
2017-02-01 22:45:14 +01:00
|
|
|
echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME,$TERMUX_PKG_DEVPACKAGE_DEPENDS\"" >> "$_DEVEL_SUBPACKAGE_FILE"
|
2016-07-20 00:48:39 +02:00
|
|
|
else
|
2017-01-10 12:35:05 +01:00
|
|
|
echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME\"" >> "$_DEVEL_SUBPACKAGE_FILE"
|
2016-07-20 00:48:39 +02:00
|
|
|
fi
|
2017-01-06 02:37:45 +01:00
|
|
|
fi
|
|
|
|
# Now build all sub packages
|
|
|
|
rm -Rf "$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages"
|
2015-06-13 01:03:31 +02:00
|
|
|
for subpackage in $TERMUX_PKG_BUILDER_DIR/*.subpackage.sh $TERMUX_PKG_TMPDIR/*subpackage.sh; do
|
2017-01-06 02:37:45 +01:00
|
|
|
test ! -f "$subpackage" && continue
|
|
|
|
local SUB_PKG_NAME
|
|
|
|
SUB_PKG_NAME=$(basename "$subpackage" .subpackage.sh)
|
|
|
|
# Default value is same as main package, but sub package may override:
|
|
|
|
local TERMUX_SUBPKG_PLATFORM_INDEPENDENT=$TERMUX_PKG_PLATFORM_INDEPENDENT
|
|
|
|
local SUB_PKG_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages/$SUB_PKG_NAME
|
|
|
|
local TERMUX_SUBPKG_DEPENDS=""
|
|
|
|
local TERMUX_SUBPKG_CONFLICTS=""
|
2017-08-01 18:49:46 +02:00
|
|
|
local TERMUX_SUBPKG_REPLACES=""
|
2017-03-26 00:51:46 +01:00
|
|
|
local TERMUX_SUBPKG_CONFFILES=""
|
2017-01-06 02:37:45 +01:00
|
|
|
local SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX
|
|
|
|
local SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package
|
|
|
|
mkdir -p "$SUB_PKG_MASSAGE_DIR" "$SUB_PKG_PACKAGE_DIR"
|
|
|
|
|
|
|
|
# shellcheck source=/dev/null
|
2018-08-27 22:27:42 +02:00
|
|
|
source "$subpackage"
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
for includeset in $TERMUX_SUBPKG_INCLUDE; do
|
|
|
|
local _INCLUDE_DIRSET
|
|
|
|
_INCLUDE_DIRSET=$(dirname "$includeset")
|
|
|
|
test "$_INCLUDE_DIRSET" = "." && _INCLUDE_DIRSET=""
|
|
|
|
if [ -e "$includeset" ] || [ -L "$includeset" ]; then
|
2016-03-18 21:39:23 +01:00
|
|
|
# Add the -L clause to handle relative symbolic links:
|
2017-01-06 02:37:45 +01:00
|
|
|
mkdir -p "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET"
|
|
|
|
mv "$includeset" "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET"
|
|
|
|
fi
|
|
|
|
done
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
local SUB_PKG_ARCH=$TERMUX_ARCH
|
|
|
|
test -n "$TERMUX_SUBPKG_PLATFORM_INDEPENDENT" && SUB_PKG_ARCH=all
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$SUB_PKG_DIR/massage"
|
|
|
|
local SUB_PKG_INSTALLSIZE
|
|
|
|
SUB_PKG_INSTALLSIZE=$(du -sk . | cut -f 1)
|
2017-04-18 08:19:48 +02:00
|
|
|
tar -cJf "$SUB_PKG_PACKAGE_DIR/data.tar.xz" .
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
mkdir -p DEBIAN
|
2015-06-13 01:03:31 +02:00
|
|
|
cd DEBIAN
|
2017-01-06 02:37:45 +01:00
|
|
|
cat > control <<-HERE
|
2018-06-07 22:23:15 +02:00
|
|
|
Package: $SUB_PKG_NAME
|
2017-01-06 02:37:45 +01:00
|
|
|
Architecture: ${SUB_PKG_ARCH}
|
|
|
|
Installed-Size: ${SUB_PKG_INSTALLSIZE}
|
|
|
|
Maintainer: $TERMUX_PKG_MAINTAINER
|
|
|
|
Version: $TERMUX_PKG_FULLVERSION
|
|
|
|
Description: $TERMUX_SUBPKG_DESCRIPTION
|
|
|
|
Homepage: $TERMUX_PKG_HOMEPAGE
|
|
|
|
HERE
|
|
|
|
test ! -z "$TERMUX_SUBPKG_DEPENDS" && echo "Depends: $TERMUX_SUBPKG_DEPENDS" >> control
|
|
|
|
test ! -z "$TERMUX_SUBPKG_CONFLICTS" && echo "Conflicts: $TERMUX_SUBPKG_CONFLICTS" >> control
|
2017-08-01 18:49:46 +02:00
|
|
|
test ! -z "$TERMUX_SUBPKG_REPLACES" && echo "Replaces: $TERMUX_SUBPKG_REPLACES" >> control
|
2017-04-18 08:19:48 +02:00
|
|
|
tar -cJf "$SUB_PKG_PACKAGE_DIR/control.tar.xz" .
|
2017-01-06 02:37:45 +01:00
|
|
|
|
2017-03-26 00:22:48 +01:00
|
|
|
for f in $TERMUX_SUBPKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> conffiles; done
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Create the actual .deb file:
|
2018-03-04 20:05:40 +01:00
|
|
|
TERMUX_SUBPKG_DEBFILE=$TERMUX_DEBDIR/${SUB_PKG_NAME}${DEBUG}_${TERMUX_PKG_FULLVERSION}_${SUB_PKG_ARCH}.deb
|
2017-01-06 02:37:45 +01:00
|
|
|
test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary"
|
|
|
|
ar cr "$TERMUX_SUBPKG_DEBFILE" \
|
|
|
|
"$TERMUX_COMMON_CACHEDIR/debian-binary" \
|
|
|
|
"$SUB_PKG_PACKAGE_DIR/control.tar.xz" \
|
|
|
|
"$SUB_PKG_PACKAGE_DIR/data.tar.xz"
|
|
|
|
|
|
|
|
# Go back to main package:
|
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX"
|
2015-06-13 01:03:31 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
# .. remove empty directories (NOTE: keep this last):
|
|
|
|
find . -type d -empty -delete
|
2017-01-06 02:37:45 +01:00
|
|
|
# Make sure user can read and write all files (problem with dpkg otherwise):
|
|
|
|
chmod -R u+rw .
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_post_massage() {
|
2017-01-06 02:37:45 +01:00
|
|
|
return
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Create data.tar.gz with files to package. Not to be overridden by package scripts.
|
|
|
|
termux_step_create_datatar() {
|
|
|
|
# Create data tarball containing files to package:
|
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR"
|
2017-03-07 01:44:53 +01:00
|
|
|
|
2018-08-27 22:27:42 +02:00
|
|
|
local HARDLINKS
|
|
|
|
HARDLINKS="$(find . -type f -links +1)"
|
2017-03-07 01:44:53 +01:00
|
|
|
if [ -n "$HARDLINKS" ]; then
|
|
|
|
termux_error_exit "Package contains hard links: $HARDLINKS"
|
|
|
|
fi
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
if [ -z "${TERMUX_PKG_METAPACKAGE+x}" ] && [ "$(find . -type f)" = "" ]; then
|
|
|
|
termux_error_exit "No files in package"
|
2016-01-11 01:45:41 +01:00
|
|
|
fi
|
2017-04-18 08:19:48 +02:00
|
|
|
tar -cJf "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" .
|
2017-01-06 02:37:45 +01:00
|
|
|
}
|
2016-01-11 01:45:41 +01:00
|
|
|
|
2017-01-10 12:35:05 +01:00
|
|
|
termux_step_create_debscripts() {
|
2017-01-06 02:37:45 +01:00
|
|
|
return
|
2015-12-20 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Create the build deb file. Not to be overridden by package scripts.
|
|
|
|
termux_step_create_debfile() {
|
|
|
|
# Get install size. This will be written as the "Installed-Size" deb field so is measured in 1024-byte blocks:
|
|
|
|
local TERMUX_PKG_INSTALLSIZE
|
|
|
|
TERMUX_PKG_INSTALLSIZE=$(du -sk . | cut -f 1)
|
|
|
|
|
|
|
|
# From here on TERMUX_ARCH is set to "all" if TERMUX_PKG_PLATFORM_INDEPENDENT is set by the package
|
|
|
|
test -n "$TERMUX_PKG_PLATFORM_INDEPENDENT" && TERMUX_ARCH=all
|
|
|
|
|
|
|
|
mkdir -p DEBIAN
|
|
|
|
cat > DEBIAN/control <<-HERE
|
2018-06-07 22:23:15 +02:00
|
|
|
Package: $TERMUX_PKG_NAME
|
2017-01-06 02:37:45 +01:00
|
|
|
Architecture: ${TERMUX_ARCH}
|
|
|
|
Installed-Size: ${TERMUX_PKG_INSTALLSIZE}
|
|
|
|
Maintainer: $TERMUX_PKG_MAINTAINER
|
|
|
|
Version: $TERMUX_PKG_FULLVERSION
|
|
|
|
Description: $TERMUX_PKG_DESCRIPTION
|
|
|
|
Homepage: $TERMUX_PKG_HOMEPAGE
|
|
|
|
HERE
|
2017-07-31 22:31:05 +02:00
|
|
|
test ! -z "$TERMUX_PKG_BREAKS" && echo "Breaks: $TERMUX_PKG_BREAKS" >> DEBIAN/control
|
2017-01-06 02:37:45 +01:00
|
|
|
test ! -z "$TERMUX_PKG_DEPENDS" && echo "Depends: $TERMUX_PKG_DEPENDS" >> DEBIAN/control
|
|
|
|
test ! -z "$TERMUX_PKG_ESSENTIAL" && echo "Essential: yes" >> DEBIAN/control
|
|
|
|
test ! -z "$TERMUX_PKG_CONFLICTS" && echo "Conflicts: $TERMUX_PKG_CONFLICTS" >> DEBIAN/control
|
2017-07-31 13:25:53 +02:00
|
|
|
test ! -z "$TERMUX_PKG_RECOMMENDS" && echo "Recommends: $TERMUX_PKG_RECOMMENDS" >> DEBIAN/control
|
2017-01-06 02:37:45 +01:00
|
|
|
test ! -z "$TERMUX_PKG_REPLACES" && echo "Replaces: $TERMUX_PKG_REPLACES" >> DEBIAN/control
|
2018-06-17 15:23:20 +02:00
|
|
|
test ! -z "$TERMUX_PKG_PROVIDES" && echo "Provides: $TERMUX_PKG_PROVIDES" >> DEBIAN/control
|
2018-06-04 01:35:38 +02:00
|
|
|
test ! -z "$TERMUX_PKG_SUGGESTS" && echo "Suggests: $TERMUX_PKG_SUGGESTS" >> DEBIAN/control
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
# Create DEBIAN/conffiles (see https://www.debian.org/doc/debian-policy/ap-pkg-conffiles.html):
|
|
|
|
for f in $TERMUX_PKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> DEBIAN/conffiles; done
|
|
|
|
|
|
|
|
# Allow packages to create arbitrary control files.
|
|
|
|
# XXX: Should be done in a better way without a function?
|
|
|
|
cd DEBIAN
|
|
|
|
termux_step_create_debscripts
|
|
|
|
|
|
|
|
# Create control.tar.xz
|
2017-04-18 08:19:48 +02:00
|
|
|
tar -cJf "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" .
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary"
|
2018-03-04 20:05:40 +01:00
|
|
|
TERMUX_PKG_DEBFILE=$TERMUX_DEBDIR/${TERMUX_PKG_NAME}${DEBUG}_${TERMUX_PKG_FULLVERSION}_${TERMUX_ARCH}.deb
|
2017-01-06 02:37:45 +01:00
|
|
|
# Create the actual .deb file:
|
|
|
|
ar cr "$TERMUX_PKG_DEBFILE" \
|
|
|
|
"$TERMUX_COMMON_CACHEDIR/debian-binary" \
|
|
|
|
"$TERMUX_PKG_PACKAGEDIR/control.tar.xz" \
|
|
|
|
"$TERMUX_PKG_PACKAGEDIR/data.tar.xz"
|
|
|
|
}
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Finish the build. Not to be overridden by package scripts.
|
|
|
|
termux_step_finish_build() {
|
|
|
|
echo "termux - build of '$TERMUX_PKG_NAME' done"
|
|
|
|
test -t 1 && printf "\033]0;%s - DONE\007" "$TERMUX_PKG_NAME"
|
|
|
|
mkdir -p /data/data/.built-packages
|
|
|
|
echo "$TERMUX_PKG_FULLVERSION" > "/data/data/.built-packages/$TERMUX_PKG_NAME"
|
2016-08-02 13:39:25 +02:00
|
|
|
exit 0
|
2017-01-06 02:37:45 +01:00
|
|
|
}
|
2016-09-25 01:30:20 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
termux_step_handle_arguments "$@"
|
|
|
|
termux_step_setup_variables
|
|
|
|
termux_step_handle_buildarch
|
|
|
|
termux_step_start_build
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_extract_package
|
2017-01-10 09:14:35 +01:00
|
|
|
cd "$TERMUX_PKG_SRCDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_post_extract_package
|
2017-01-06 02:37:45 +01:00
|
|
|
termux_step_handle_hostbuild
|
|
|
|
termux_step_setup_toolchain
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_patch_package
|
2017-03-05 11:40:50 +01:00
|
|
|
termux_step_replace_guess_scripts
|
2017-05-11 01:01:20 +02:00
|
|
|
cd "$TERMUX_PKG_SRCDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_pre_configure
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_configure
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_post_configure
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_make
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_make_install
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_post_make_install
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_extract_into_massagedir
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_massage
|
2017-01-06 02:37:45 +01:00
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX"
|
2015-06-13 01:03:31 +02:00
|
|
|
termux_step_post_massage
|
2017-01-06 02:37:45 +01:00
|
|
|
termux_step_create_datatar
|
|
|
|
termux_step_create_debfile
|
|
|
|
termux_step_finish_build
|