From a665e04eafec9bef1774e94ae733e3db6a53afe9 Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Sun, 1 Mar 2020 09:06:36 +0100 Subject: [PATCH] build-package,termux_step_make_install: build .deb also on device Do this using the termux-build-chroot script. Some tools are necessary during `make install`. For an autoconf program these are typically mkdir, sed, grep, install, and their paths are hardcoded into the Makefil. Therefore symlink these into the new $PREFIX before running `make install`, so that they can be found if necessary, --- build-package.sh | 33 ++++++++++++++--------- scripts/build/termux_step_make_install.sh | 27 +++++++++++++++---- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/build-package.sh b/build-package.sh index 905b54450..140e22325 100755 --- a/build-package.sh +++ b/build-package.sh @@ -6,12 +6,26 @@ set -e -o pipefail -u : "${TMPDIR:=/tmp}" export TMPDIR +cd "$(realpath "$(dirname "$0")")" +TERMUX_SCRIPTDIR=$(pwd) +export TERMUX_SCRIPTDIR + +# Lock file to prevent parallel running in the same environment. +TERMUX_BUILD_LOCK_FILE="${TMPDIR}/.termux-build.lck" +if [ ! -e "$TERMUX_BUILD_LOCK_FILE" ]; then + touch "$TERMUX_BUILD_LOCK_FILE" +fi + if [ "$(uname -o)" = "Android" ] || [ -e "/system/bin/app_process" ]; then if [ "$(id -u)" = "0" ]; then echo "On-device execution of this script as root is disabled." exit 1 fi + # termux-build-chroot sets up a new PREFIX with proot to which + # the built package can be installed without modifying $PREFIX + source "$TERMUX_SCRIPTDIR/scripts/termux-build-chroot.sh" + # This variable tells all parts of build system that build # is performed on device. export TERMUX_ON_DEVICE_BUILD=true @@ -19,16 +33,6 @@ else export TERMUX_ON_DEVICE_BUILD=false fi -cd "$(realpath "$(dirname "$0")")" -TERMUX_SCRIPTDIR=$(pwd) -export TERMUX_SCRIPTDIR - -# Lock file to prevent parallel running in the same environment. -TERMUX_BUILD_LOCK_FILE="${TMPDIR}/.termux-build.lck" -if [ ! -e "$TERMUX_BUILD_LOCK_FILE" ]; then - touch "$TERMUX_BUILD_LOCK_FILE" -fi - # Special variable for internal use. It forces script to ignore # lock file. : "${TERMUX_BUILD_IGNORE_LOCK:=false}" @@ -328,13 +332,16 @@ while (($# > 0)); do cd "$TERMUX_PKG_BUILDDIR" termux_step_make cd "$TERMUX_PKG_BUILDDIR" + mkdir -p "$TERMUX_PKG_MASSAGEDIR/data" termux_step_make_install cd "$TERMUX_PKG_BUILDDIR" termux_step_post_make_install - termux_step_install_service_scripts + termux_step_install_service_scripts termux_step_install_license - cd "$TERMUX_PKG_MASSAGEDIR" - termux_step_extract_into_massagedir + if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then + cd "$TERMUX_PKG_MASSAGEDIR" + termux_step_extract_into_massagedir + fi cd "$TERMUX_PKG_MASSAGEDIR" termux_step_massage cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" diff --git a/scripts/build/termux_step_make_install.sh b/scripts/build/termux_step_make_install.sh index 188e2e9d1..f2b3d9c0a 100644 --- a/scripts/build/termux_step_make_install.sh +++ b/scripts/build/termux_step_make_install.sh @@ -1,19 +1,31 @@ termux_step_make_install() { + if [ $TERMUX_ON_DEVICE_BUILD = "true" ]; then + CHROOT="termux-build-chroot" + MAKE_INSTALL_TOOLS="sed grep mkdir install" + # We need to symlink some tools into our new prefix + for tool in $MAKE_INSTALL_TOOLS; do + mkdir -p $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/bin + ln -s /usr/bin/$tool $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/bin/ + done + else + CHROOT="" + fi [ "$TERMUX_PKG_METAPACKAGE" = "true" ] && return if test -f build.ninja; then - ninja -w dupbuild=warn -j $TERMUX_MAKE_PROCESSES install + $CHROOT ninja -w dupbuild=warn -j $TERMUX_MAKE_PROCESSES install elif ls ./*akefile &> /dev/null || [ -n "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then : "${TERMUX_PKG_MAKE_INSTALL_TARGET:="install"}" # Some packages have problem with parallell install, and it does not buy much, so use -j 1. + echo "Running $CHROOT make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET}" if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then - make -j 1 ${TERMUX_PKG_MAKE_INSTALL_TARGET} + $CHROOT make -j 1 ${TERMUX_PKG_MAKE_INSTALL_TARGET} else - make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET} + $CHROOT make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET} fi elif test -f Cargo.toml; then termux_setup_rust - cargo install \ + $CHROOT cargo install \ --jobs $TERMUX_MAKE_PROCESSES \ --path . \ --force \ @@ -21,6 +33,11 @@ termux_step_make_install() { --root $TERMUX_PREFIX \ $TERMUX_PKG_EXTRA_CONFIGURE_ARGS # https://github.com/rust-lang/cargo/issues/3316: - rm $TERMUX_PREFIX/.crates.toml + $CHROOT rm $TERMUX_PREFIX/.crates.toml + fi + if [ $TERMUX_ON_DEVICE_BUILD = "true" ]; then + for tool in $MAKE_INSTALL_TOOLS; do + unlink $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX/bin/$tool + done fi }