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
|
|
|
|
|
2021-05-19 12:19:23 +02:00
|
|
|
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct 2>/dev/null || date "+%s")
|
2021-05-11 21:36:23 +02:00
|
|
|
export SOURCE_DATE_EPOCH
|
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
: "${TMPDIR:=/tmp}"
|
|
|
|
export TMPDIR
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# This variable tells all parts of build system that build
|
|
|
|
# is performed on device.
|
|
|
|
export TERMUX_ON_DEVICE_BUILD=true
|
|
|
|
else
|
2019-08-12 17:28:41 +02:00
|
|
|
export TERMUX_ON_DEVICE_BUILD=false
|
2019-03-26 00:27:09 +01:00
|
|
|
fi
|
|
|
|
|
2019-08-16 21:52:18 +02:00
|
|
|
cd "$(realpath "$(dirname "$0")")"
|
|
|
|
TERMUX_SCRIPTDIR=$(pwd)
|
|
|
|
export TERMUX_SCRIPTDIR
|
|
|
|
|
2020-10-23 00:57:33 +02:00
|
|
|
# Automatically enable offline set of sources and build tools.
|
|
|
|
# Offline termux-packages bundle can be created by executing
|
|
|
|
# script ./scripts/setup-offline-bundle.sh.
|
|
|
|
if [ -f "${TERMUX_SCRIPTDIR}/build-tools/.installed" ]; then
|
|
|
|
export TERMUX_PACKAGES_OFFLINE=true
|
|
|
|
fi
|
|
|
|
|
2019-03-06 15:46:53 +01:00
|
|
|
# Lock file to prevent parallel running in the same environment.
|
2019-08-06 14:39:42 +02:00
|
|
|
TERMUX_BUILD_LOCK_FILE="${TMPDIR}/.termux-build.lck"
|
2019-03-06 15:46:53 +01:00
|
|
|
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}"
|
|
|
|
|
2019-08-06 14:39:42 +02:00
|
|
|
# Utility function to log an error message and exit with an error code.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_error_exit.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_error_exit.sh"
|
2019-08-06 14:39:42 +02:00
|
|
|
|
2018-08-21 00:35:50 +02:00
|
|
|
# Utility function to download a resource with an expected checksum.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_download.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_download.sh"
|
2017-01-06 02:37:45 +01:00
|
|
|
|
2020-06-20 21:43:34 +02:00
|
|
|
# Utility function for setting up GHC toolchain.
|
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_ghc.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_ghc.sh"
|
|
|
|
|
2021-09-03 19:46:03 +02:00
|
|
|
# Utility function for setting up GN toolchain.
|
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_gn.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_gn.sh"
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Utility function for golang-using packages to setup a go toolchain.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_golang.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_golang.sh"
|
2017-01-06 02:37:45 +01:00
|
|
|
|
2018-09-03 23:57:26 +02:00
|
|
|
# Utility function for rust-using packages to setup a rust toolchain.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_rust.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_rust.sh"
|
2018-09-03 23:57:26 +02:00
|
|
|
|
2021-11-17 09:36:43 +01:00
|
|
|
# Utility function for zig-using packages to setup a zig toolchain.
|
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_zig.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_zig.sh"
|
|
|
|
|
2017-11-07 02:26:49 +01:00
|
|
|
# Utility function to setup a current ninja build system.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_ninja.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_ninja.sh"
|
2017-07-29 02:11:04 +02:00
|
|
|
|
2017-11-07 02:26:49 +01:00
|
|
|
# Utility function to setup a current meson build system.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_meson.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_meson.sh"
|
2017-07-29 02:11:04 +02:00
|
|
|
|
2017-11-07 02:26:49 +01:00
|
|
|
# Utility function to setup a current cmake build system
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_cmake.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_cmake.sh"
|
2017-01-11 18:21:58 +01:00
|
|
|
|
2019-05-12 00:08:10 +02:00
|
|
|
# Utility function to setup protobuf:
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/setup/termux_setup_protobuf.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_protobuf.sh"
|
2019-05-12 00:08:10 +02:00
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Setup variables used by the build. Not to be overridden by packages.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_setup_variables.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_setup_variables.sh"
|
2017-01-06 02:37:45 +01:00
|
|
|
|
|
|
|
# Save away and restore build setups which may change between builds.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_handle_buildarch.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_handle_buildarch.sh"
|
2016-05-31 01:25:12 +02:00
|
|
|
|
2018-12-29 11:56:40 +01:00
|
|
|
# Function to get TERMUX_PKG_VERSION from build.sh
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_extract_dep_info.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_extract_dep_info.sh"
|
2018-12-29 11:56:40 +01:00
|
|
|
|
2019-02-26 21:39:58 +01:00
|
|
|
# Function that downloads a .deb (using the termux_download function)
|
2022-01-14 14:16:37 +01:00
|
|
|
# shellcheck source=scripts/build/termux_download_deb_pac.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_download_deb_pac.sh"
|
2018-12-29 14:50:27 +01:00
|
|
|
|
2019-01-01 21:56:42 +01:00
|
|
|
# Script to download InRelease, verify it's signature and then download Packages.xz by hash
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_get_repo_files.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_get_repo_files.sh"
|
2019-01-01 21:56:42 +01:00
|
|
|
|
2021-08-21 18:02:31 +02:00
|
|
|
# Download or build dependencies. Not to be overridden by packages.
|
|
|
|
# shellcheck source=scripts/build/termux_step_get_dependencies.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_get_dependencies.sh"
|
|
|
|
|
2021-09-17 12:02:53 +02:00
|
|
|
# Handle config scripts that needs to be run during build. Not to be overridden by packages.
|
|
|
|
# shellcheck source=scripts/build/termux_step_override_config_scripts.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_override_config_scripts.sh"
|
|
|
|
|
2021-08-24 08:22:54 +02:00
|
|
|
# Remove old src and build folders and create new ones
|
|
|
|
# shellcheck source=scripts/build/termux_step_setup_build_folders.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_setup_build_folders.sh"
|
|
|
|
|
2021-08-21 22:25:26 +02:00
|
|
|
# Source the package build script and start building. Not to be overridden by packages.
|
|
|
|
# shellcheck source=scripts/build/termux_step_start_build.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_start_build.sh"
|
|
|
|
|
2021-08-21 22:25:30 +02:00
|
|
|
# Download or build dependencies. Not to be overridden by packages.
|
|
|
|
# shellcheck source=scripts/build/termux_step_create_timestamp_file.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_create_timestamp_file.sh"
|
|
|
|
|
2020-07-16 23:51:05 +02:00
|
|
|
# Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. Can be overridden by packages.
|
|
|
|
# shellcheck source=scripts/build/get_source/termux_step_get_source.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_step_get_source.sh"
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2020-07-16 23:51:05 +02:00
|
|
|
# Run from termux_step_get_source if TERMUX_PKG_SRCURL ends with .git.
|
|
|
|
# shellcheck source=scripts/build/get_source/termux_step_get_source.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_git_clone_src.sh"
|
|
|
|
|
|
|
|
# Run from termux_step_get_source if TERMUX_PKG_SRCURL does not ends with .git.
|
|
|
|
# shellcheck source=scripts/build/get_source/termux_download_src_archive.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_download_src_archive.sh"
|
|
|
|
|
|
|
|
# Run from termux_step_get_source after termux_download_src_archive.
|
2020-07-21 19:36:34 +02:00
|
|
|
# shellcheck source=scripts/build/get_source/termux_unpack_src_archive.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/get_source/termux_unpack_src_archive.sh"
|
2020-07-16 23:51:05 +02:00
|
|
|
|
|
|
|
# Hook for packages to act just after the package sources have been obtained.
|
|
|
|
# Invoked from $TERMUX_PKG_SRCDIR.
|
|
|
|
termux_step_post_get_source() {
|
2019-02-12 09:23:21 +01:00
|
|
|
return
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Optional host build. Not to be overridden by packages.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_handle_hostbuild.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_handle_hostbuild.sh"
|
2017-01-06 02:37:45 +01:00
|
|
|
|
2015-06-13 01:03:31 +02:00
|
|
|
# Perform a host build. Will be called in $TERMUX_PKG_HOSTBUILD_DIR.
|
2020-07-16 23:51:05 +02:00
|
|
|
# After termux_step_post_get_source() and before termux_step_patch_package()
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_host_build.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_host_build.sh"
|
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.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_setup_toolchain.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_setup_toolchain.sh"
|
2017-01-06 02:37:45 +01:00
|
|
|
|
2017-01-07 06:38:04 +01:00
|
|
|
# Apply all *.patch files for the package. Not to be overridden by packages.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_patch_package.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_patch_package.sh"
|
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.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_replace_guess_scripts.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_replace_guess_scripts.sh"
|
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
|
|
|
}
|
|
|
|
|
2019-02-27 19:40:34 +01:00
|
|
|
# Setup configure args and run $TERMUX_PKG_SRCDIR/configure. This function is called from termux_step_configure
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/configure/termux_step_configure_autotools.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/configure/termux_step_configure_autotools.sh"
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2019-02-27 19:47:03 +01:00
|
|
|
# Setup configure args and run cmake. This function is called from termux_step_configure
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/configure/termux_step_configure_cmake.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/configure/termux_step_configure_cmake.sh"
|
2017-01-15 13:48:05 +01:00
|
|
|
|
2019-02-27 19:48:46 +01:00
|
|
|
# Setup configure args and run meson. This function is called from termux_step_configure
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/configure/termux_step_configure_meson.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/configure/termux_step_configure_meson.sh"
|
2017-07-29 02:11:04 +02:00
|
|
|
|
2019-02-27 19:49:12 +01:00
|
|
|
# Configure the package
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/configure/termux_step_configure.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/configure/termux_step_configure.sh"
|
2017-01-15 13:48:05 +01:00
|
|
|
|
2019-02-27 20:01:08 +01:00
|
|
|
# Hook for packages after configure step
|
2019-02-08 10:37:29 +01:00
|
|
|
termux_step_post_configure() {
|
2017-01-06 02:37:45 +01:00
|
|
|
return
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2019-02-27 19:49:39 +01:00
|
|
|
# Make package, either with ninja or make
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_make.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_make.sh"
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2019-02-27 19:50:20 +01:00
|
|
|
# Make install, either with ninja, make of cargo
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_make_install.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_make_install.sh"
|
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
|
|
|
}
|
|
|
|
|
2020-01-05 15:00:15 +01:00
|
|
|
# Add service scripts from array TERMUX_PKG_SERVICE_SCRIPT, if it is set
|
|
|
|
# shellcheck source=scripts/build/termux_step_install_service_scripts.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_service_scripts.sh"
|
|
|
|
|
2019-04-28 22:07:07 +02:00
|
|
|
# Link/copy the LICENSE for the package to $TERMUX_PREFIX/share/$TERMUX_PKG_NAME/
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_install_license.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_install_license.sh"
|
2019-04-28 22:07:07 +02:00
|
|
|
|
2019-02-27 19:53:53 +01:00
|
|
|
# Function to cp (through tar) installed files to massage dir
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_extract_into_massagedir.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_extract_into_massagedir.sh"
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2020-02-23 21:30:44 +01:00
|
|
|
# Hook function to create {pre,post}install, {pre,post}rm-scripts for subpkgs
|
|
|
|
termux_step_create_subpkg_debscripts() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-03-07 20:35:32 +01:00
|
|
|
# Create all subpackages. Run from termux_step_massage
|
2021-09-10 18:10:02 +02:00
|
|
|
# shellcheck source=scripts/build/termux_create_debian_subpackages.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_create_debian_subpackages.sh"
|
|
|
|
|
|
|
|
# Create all subpackages. Run from termux_step_massage
|
|
|
|
# shellcheck source=scripts/build/termux_create_pacman_subpackages.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_create_pacman_subpackages.sh"
|
2019-03-07 20:35:32 +01:00
|
|
|
|
2019-02-27 19:58:17 +01:00
|
|
|
# Function to run various cleanup/fixes
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_massage.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_massage.sh"
|
2015-06-13 01:03:31 +02:00
|
|
|
|
2019-02-27 20:01:08 +01:00
|
|
|
# Hook for packages after massage step
|
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
|
|
|
}
|
|
|
|
|
2019-02-27 20:01:08 +01:00
|
|
|
# Hook function to create {pre,post}install, {pre,post}rm-scripts and similar
|
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
|
|
|
}
|
|
|
|
|
2021-09-10 18:10:02 +02:00
|
|
|
# Convert Debian maintainer scripts into pacman-compatible installation hooks.
|
|
|
|
# This is used only when creating pacman packages.
|
|
|
|
# shellcheck source=scripts/build/termux_step_create_pacman_install_hook.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_create_pacman_install_hook.sh"
|
|
|
|
|
2017-01-06 02:37:45 +01:00
|
|
|
# Create the build deb file. Not to be overridden by package scripts.
|
2021-09-10 18:10:02 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_create_debian_package.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_create_debian_package.sh"
|
|
|
|
|
|
|
|
# Create the build .pkg.tar.xz file. Not to be overridden by package scripts.
|
|
|
|
# shellcheck source=scripts/build/termux_step_create_pacman_package.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_create_pacman_package.sh"
|
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.
|
2019-08-16 22:19:11 +02:00
|
|
|
# shellcheck source=scripts/build/termux_step_finish_build.sh
|
|
|
|
source "$TERMUX_SCRIPTDIR/scripts/build/termux_step_finish_build.sh"
|
2016-09-25 01:30:20 +02:00
|
|
|
|
2019-07-20 14:32:54 +02:00
|
|
|
################################################################################
|
|
|
|
|
2019-08-09 23:56:55 +02:00
|
|
|
# shellcheck source=scripts/properties.sh
|
|
|
|
. "$TERMUX_SCRIPTDIR/scripts/properties.sh"
|
|
|
|
|
2019-08-12 23:16:07 +02:00
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
|
2019-08-10 00:11:26 +02:00
|
|
|
# For on device builds cross compiling is not supported.
|
|
|
|
# Target architecture must be same as for environment used currently.
|
2022-02-02 15:45:36 +01:00
|
|
|
case "$TERMUX_MAIN_PACKAGE_FORMAT" in
|
|
|
|
"debian") TERMUX_ARCH=$(dpkg --print-architecture);;
|
|
|
|
"pacman") TERMUX_ARCH=$(pacman-conf | grep Architecture | sed 's/Architecture = //g');;
|
|
|
|
esac
|
2019-08-16 21:52:18 +02:00
|
|
|
export TERMUX_ARCH
|
2019-08-10 00:11:26 +02:00
|
|
|
fi
|
|
|
|
|
2021-07-07 22:27:54 +02:00
|
|
|
# Special hook to prevent use of "sudo" inside package build scripts.
|
|
|
|
# build-package.sh shouldn't perform any privileged operations.
|
|
|
|
sudo() {
|
|
|
|
termux_error_exit "Do not use 'sudo' inside build scripts. Build environment should be configured through ./scripts/setup-ubuntu.sh."
|
|
|
|
}
|
|
|
|
|
2019-07-20 14:32:54 +02:00
|
|
|
_show_usage() {
|
2020-07-21 10:22:55 +02:00
|
|
|
echo "Usage: ./build-package.sh [options] PACKAGE_1 PACKAGE_2 ..."
|
|
|
|
echo
|
|
|
|
echo "Build a package by creating a .deb file in the debs/ folder."
|
|
|
|
echo
|
|
|
|
echo "Available options:"
|
|
|
|
[ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && 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/."
|
|
|
|
echo " -f Force build even if package has already been built."
|
|
|
|
[ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && echo " -i Download and extract dependencies instead of building them."
|
2020-10-30 21:48:55 +01:00
|
|
|
echo " -I Download and extract dependencies instead of building them, keep existing $TERMUX_BASE_DIR files."
|
2020-07-21 10:22:55 +02:00
|
|
|
echo " -q Quiet build."
|
|
|
|
echo " -s Skip dependency check."
|
2021-09-10 18:10:02 +02:00
|
|
|
echo " -o Specify directory where to put built packages. Default: output/."
|
|
|
|
echo " --format Specify package output format (debian, pacman)."
|
2020-07-21 10:22:55 +02:00
|
|
|
exit 1
|
2019-07-20 14:32:54 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 18:10:02 +02:00
|
|
|
declare -a PACKAGE_LIST=()
|
|
|
|
|
|
|
|
if [ "$#" -lt 1 ]; then _show_usage; fi
|
|
|
|
while (($# >= 1)); do
|
|
|
|
case "$1" in
|
|
|
|
--) shift 1; break;;
|
|
|
|
-h|--help) _show_usage;;
|
|
|
|
--format)
|
|
|
|
if [ $# -ge 2 ]; then
|
|
|
|
shift 1
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
termux_error_exit "./build-package.sh: argument to '--format' should not be empty"
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
debian|pacman) TERMUX_PACKAGE_FORMAT="$1";;
|
|
|
|
*) termux_error_exit "./build-package.sh: only 'debian' and 'pacman' formats are supported";;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
termux_error_exit "./build-package.sh: option '--format' requires an argument"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
-a)
|
|
|
|
if [ $# -ge 2 ]; then
|
|
|
|
shift 1
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
termux_error_exit "Argument to '-a' should not be empty."
|
|
|
|
fi
|
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
|
|
|
|
termux_error_exit "./build-package.sh: option '-a' is not available for on-device builds"
|
|
|
|
else
|
|
|
|
export TERMUX_ARCH="$1"
|
|
|
|
fi
|
2019-08-06 14:39:42 +02:00
|
|
|
else
|
2021-09-10 18:10:02 +02:00
|
|
|
termux_error_exit "./build-package.sh: option '-a' requires an argument"
|
2019-08-06 14:39:42 +02:00
|
|
|
fi
|
|
|
|
;;
|
2021-09-10 18:10:02 +02:00
|
|
|
-d) export TERMUX_DEBUG_BUILD=true;;
|
|
|
|
-D) TERMUX_IS_DISABLED=true;;
|
|
|
|
-f) TERMUX_FORCE_BUILD=true;;
|
|
|
|
-i)
|
2019-08-12 23:16:07 +02:00
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
|
2019-08-06 14:39:42 +02:00
|
|
|
termux_error_exit "./build-package.sh: option '-i' is not available for on-device builds"
|
|
|
|
else
|
|
|
|
export TERMUX_INSTALL_DEPS=true
|
|
|
|
fi
|
|
|
|
;;
|
2021-09-10 18:10:02 +02:00
|
|
|
-I) export TERMUX_INSTALL_DEPS=true && export TERMUX_NO_CLEAN=true;;
|
|
|
|
-q) export TERMUX_QUIET_BUILD=true;;
|
|
|
|
-s) export TERMUX_SKIP_DEPCHECK=true;;
|
|
|
|
-o)
|
|
|
|
if [ $# -ge 2 ]; then
|
|
|
|
shift 1
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
termux_error_exit "./build-package.sh: argument to '-o' should not be empty"
|
|
|
|
fi
|
|
|
|
TERMUX_OUTPUT_DIR=$(realpath -m "$1")
|
|
|
|
else
|
|
|
|
termux_error_exit "./build-package.sh: option '-o' requires an argument"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
-c) TERMUX_CONTINUE_BUILD=true;;
|
|
|
|
-*) termux_error_exit "./build-package.sh: illegal option '$1'";;
|
|
|
|
*) PACKAGE_LIST+=("$1");;
|
2019-07-20 14:32:54 +02:00
|
|
|
esac
|
2021-09-10 18:10:02 +02:00
|
|
|
shift 1
|
2019-07-20 14:32:54 +02:00
|
|
|
done
|
|
|
|
unset -f _show_usage
|
|
|
|
|
2020-03-23 22:45:11 +01:00
|
|
|
if [ "${TERMUX_INSTALL_DEPS-false}" = "true" ]; then
|
2020-03-21 15:30:02 +01:00
|
|
|
# Setup PGP keys for verifying integrity of dependencies.
|
|
|
|
# Keys are obtained from our keyring package.
|
2021-12-08 10:06:39 +01:00
|
|
|
gpg --list-keys 2C7F29AE97891F6419A9E2CDB0076E490B71616B > /dev/null 2>&1 || {
|
2020-03-21 15:30:02 +01:00
|
|
|
gpg --import "$TERMUX_SCRIPTDIR/packages/termux-keyring/grimler.gpg"
|
2021-12-08 10:06:39 +01:00
|
|
|
gpg --no-tty --command-file <(echo -e "trust\n5\ny") --edit-key 2C7F29AE97891F6419A9E2CDB0076E490B71616B
|
2020-03-21 15:30:02 +01:00
|
|
|
}
|
|
|
|
gpg --list-keys CC72CF8BA7DBFA0182877D045A897D96E57CF20C > /dev/null 2>&1 || {
|
|
|
|
gpg --import "$TERMUX_SCRIPTDIR/packages/termux-keyring/termux-autobuilds.gpg"
|
2020-03-21 22:03:43 +01:00
|
|
|
gpg --no-tty --command-file <(echo -e "trust\n5\ny") --edit-key CC72CF8BA7DBFA0182877D045A897D96E57CF20C
|
2020-03-21 15:30:02 +01:00
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2021-09-10 18:10:02 +02:00
|
|
|
for ((i=0; i<${#PACKAGE_LIST[@]}; i++)); do
|
2019-07-20 14:32:54 +02:00
|
|
|
# Following commands must be executed under lock to prevent running
|
|
|
|
# multiple instances of "./build-package.sh".
|
|
|
|
#
|
|
|
|
# To provide sane environment for each package, builds are done
|
|
|
|
# in subshell.
|
|
|
|
(
|
|
|
|
if ! $TERMUX_BUILD_IGNORE_LOCK; then
|
|
|
|
flock -n 5 || termux_error_exit "Another build is already running within same environment."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Handle 'all' arch:
|
2019-08-12 23:16:07 +02:00
|
|
|
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then
|
2019-07-20 14:32:54 +02:00
|
|
|
for arch in 'aarch64' 'arm' 'i686' 'x86_64'; do
|
2019-08-06 14:39:42 +02:00
|
|
|
env TERMUX_ARCH="$arch" TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh \
|
|
|
|
${TERMUX_FORCE_BUILD+-f} ${TERMUX_INSTALL_DEPS+-i} ${TERMUX_IS_DISABLED+-D} \
|
2021-09-10 18:10:02 +02:00
|
|
|
${TERMUX_DEBUG_BUILD+-d} ${TERMUX_OUTPUT_DIR+-o $TERMUX_OUTPUT_DIR} \
|
2021-10-22 09:26:34 +02:00
|
|
|
--format ${TERMUX_PACKAGE_FORMAT:=debian} "${PACKAGE_LIST[i]}"
|
2019-07-20 14:32:54 +02:00
|
|
|
done
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check the package to build:
|
2021-09-10 18:10:02 +02:00
|
|
|
TERMUX_PKG_NAME=$(basename "${PACKAGE_LIST[i]}")
|
|
|
|
if [[ ${PACKAGE_LIST[i]} == *"/"* ]]; then
|
2019-07-20 14:32:54 +02:00
|
|
|
# Path to directory which may be outside this repo:
|
2021-09-10 18:10:02 +02:00
|
|
|
if [ ! -d "${PACKAGE_LIST[i]}" ]; then termux_error_exit "'${PACKAGE_LIST[i]}' seems to be a path but is not a directory"; fi
|
2019-07-20 14:32:54 +02:00
|
|
|
export TERMUX_PKG_BUILDER_DIR
|
2021-09-10 18:10:02 +02:00
|
|
|
TERMUX_PKG_BUILDER_DIR=$(realpath "${PACKAGE_LIST[i]}")
|
2019-07-20 14:32:54 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
termux_step_setup_variables
|
|
|
|
termux_step_handle_buildarch
|
2021-08-24 08:22:54 +02:00
|
|
|
|
|
|
|
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
|
|
|
|
termux_step_setup_build_folders
|
|
|
|
fi
|
|
|
|
|
2021-08-21 22:25:26 +02:00
|
|
|
termux_step_start_build
|
2021-08-24 08:22:54 +02:00
|
|
|
|
2021-08-21 18:08:57 +02:00
|
|
|
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
|
|
|
|
termux_step_get_dependencies
|
2021-09-17 12:02:53 +02:00
|
|
|
termux_step_override_config_scripts
|
2021-08-21 18:08:57 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-21 22:25:30 +02:00
|
|
|
termux_step_create_timestamp_file
|
2021-08-21 18:08:57 +02:00
|
|
|
|
|
|
|
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
|
|
|
|
cd "$TERMUX_PKG_CACHEDIR"
|
|
|
|
termux_step_get_source
|
|
|
|
cd "$TERMUX_PKG_SRCDIR"
|
|
|
|
termux_step_post_get_source
|
|
|
|
termux_step_handle_hostbuild
|
|
|
|
fi
|
|
|
|
|
2019-07-20 14:32:54 +02:00
|
|
|
termux_step_setup_toolchain
|
2021-08-21 18:08:57 +02:00
|
|
|
|
|
|
|
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
|
|
|
|
termux_step_patch_package
|
|
|
|
termux_step_replace_guess_scripts
|
|
|
|
cd "$TERMUX_PKG_SRCDIR"
|
|
|
|
termux_step_pre_configure
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Even on continued build we might need to setup paths
|
|
|
|
# to tools so need to run part of configure step
|
2019-07-20 14:32:54 +02:00
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
|
|
|
termux_step_configure
|
2021-08-21 18:08:57 +02:00
|
|
|
|
|
|
|
if [ "$TERMUX_CONTINUE_BUILD" == "false" ]; then
|
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
|
|
|
termux_step_post_configure
|
|
|
|
fi
|
2019-07-20 14:32:54 +02:00
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
|
|
|
termux_step_make
|
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
|
|
|
termux_step_make_install
|
|
|
|
cd "$TERMUX_PKG_BUILDDIR"
|
|
|
|
termux_step_post_make_install
|
2020-07-21 10:22:55 +02:00
|
|
|
termux_step_install_service_scripts
|
2019-07-20 14:32:54 +02:00
|
|
|
termux_step_install_license
|
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR"
|
|
|
|
termux_step_extract_into_massagedir
|
|
|
|
termux_step_massage
|
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX"
|
|
|
|
termux_step_post_massage
|
2021-05-16 18:55:31 +02:00
|
|
|
cd "$TERMUX_PKG_MASSAGEDIR"
|
2021-09-10 18:10:02 +02:00
|
|
|
if [ "$TERMUX_PACKAGE_FORMAT" = "debian" ]; then
|
|
|
|
termux_step_create_debian_package
|
|
|
|
elif [ "$TERMUX_PACKAGE_FORMAT" = "pacman" ]; then
|
|
|
|
termux_step_create_pacman_package
|
|
|
|
else
|
|
|
|
termux_error_exit "Unknown packaging format '$TERMUX_PACKAGE_FORMAT'."
|
|
|
|
fi
|
2019-07-20 14:32:54 +02:00
|
|
|
termux_step_finish_build
|
|
|
|
) 5< "$TERMUX_BUILD_LOCK_FILE"
|
|
|
|
done
|