### Setup VirtualBox VM for Termux Packages Source: https://github.com/termux/termux-packages/wiki/Build-environment Commands to set up and manage a VirtualBox Ubuntu virtual machine for building Termux packages using Vagrant. This includes installing necessary Vagrant plugins, starting the VM, and SSHing into it. ```shell vagrant plugin install vagrant-disksize ``` ```shell cd scripts && vagrant up ``` ```shell vagrant ssh ``` -------------------------------- ### Setup Android SDK and NDK Source: https://github.com/termux/termux-packages/wiki/Build-environment This script assists in setting up the Android SDK and NDK, which are prerequisites for building Termux packages. It assumes the default installation path of $HOME/lib and ensures they are correctly configured for the build process. ```shell ./scripts/setup-android-sdk.sh ``` -------------------------------- ### Setup Build Utility Functions Source: https://context7.com/termux/termux-packages/llms.txt Shows how to utilize built-in setup functions within the pre-configure step to initialize toolchains like Rust, CMake, or Go for cross-compilation. ```bash termux_step_pre_configure() { termux_setup_rust } termux_step_make() { cargo build --release --target $CARGO_TARGET_NAME } termux_step_make_install() { install -Dm755 target/${CARGO_TARGET_NAME}/release/mybin $TERMUX_PREFIX/bin/mybin } ``` -------------------------------- ### Setup Host OS for Termux Packages (Ubuntu) Source: https://github.com/termux/termux-packages/wiki/Build-environment This script automates the installation of necessary build tools on an Ubuntu host system for compiling Termux packages. It requires sudo privileges to install packages system-wide. ```shell ./scripts/setup-ubuntu.sh ``` -------------------------------- ### Termux Build Steps: Compilation and Installation Source: https://github.com/termux/termux-packages/wiki/Building-packages Steps involved in compiling the source code, including multilib support, and installing the compiled artifacts into the package structure. ```shell termux_step_make termux_step_make_multilib termux_step_make_install termux_step_make_install_multilib ``` -------------------------------- ### Setup Host OS for Termux Packages (Arch Linux) Source: https://github.com/termux/termux-packages/wiki/Build-environment This script automates the installation of necessary build tools on an Arch Linux host system for compiling Termux packages. It requires sudo privileges to install packages system-wide. ```shell ./scripts/setup-archlinux.sh ``` -------------------------------- ### Setup Termux Build Environment Scripts (Bash) Source: https://context7.com/termux/termux-packages/llms.txt Scripts to set up the build environment on different platforms. Includes setup for Ubuntu, Arch Linux, Android SDK/NDK, on-device Termux builds, and creating offline bundles for air-gapped environments. ```bash # Setup on Ubuntu host ./scripts/setup-ubuntu.sh # Setup on Arch Linux host ./scripts/setup-archlinux.sh # Setup Android SDK and NDK (installs to $HOME/lib) ./scripts/setup-android-sdk.sh # Setup for on-device building in Termux app ./scripts/setup-termux.sh # Create offline bundle for air-gapped builds ./scripts/setup-offline-bundle.sh ``` -------------------------------- ### Termux Package Build Script Example (Bash) Source: https://github.com/termux/termux-packages/wiki/Creating-new-package A minimal example of a 'build.sh' script for a Termux package. It defines essential metadata such as homepage, description, license, maintainer, version, and the source URL for the package. ```bash # http(s) link to package home page. TERMUX_PKG_HOMEPAGE=https://www.gnu.org/software/ed/ # One-line, short package description. TERMUX_PKG_DESCRIPTION="Classic UNIX line editor" # License. # Use SPDX identifier: https://spdx.org/licenses/ TERMUX_PKG_LICENSE="GPL-2.0" # Who maintains the package. # Specify yourself (Github nick, or name + email) if you wish to maintain the # package, fix its bugs, etc. Otherwise specify "@termux". # Please note that unofficial repositories are not allowed to reference @termux # as their maintainer. # See also: # - https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-maintainer # - https://www.debian.org/doc/debian-policy/ch-binary.html#s-maintainer TERMUX_PKG_MAINTAINER="@termux" # Version. TERMUX_PKG_VERSION=1.15 # URL to archive with source code. TERMUX_PKG_SRCURL=https://mirrors.kernel.org/gnu/ed/ed-${TERMUX_PKG_VERSION}.tar.lz ``` -------------------------------- ### Termux Build Steps: Post-Configuration and Post-Installation Hooks Source: https://github.com/termux/termux-packages/wiki/Building-packages Hooks that allow custom commands to be executed immediately after the configuration or installation steps are completed. ```shell termux_step_post_configure termux_step_post_make_install ``` -------------------------------- ### Termux Build Steps: Package Installation and Scripting Source: https://github.com/termux/termux-packages/wiki/Building-packages Functions for installing package-specific components like pacman hooks, service scripts, and licenses, ensuring proper integration with the Termux environment. ```shell termux_step_install_pacman_hooks termux_step_install_service_scripts termux_step_install_license ``` -------------------------------- ### Setup Termux App for On-Device Builds Source: https://github.com/termux/termux-packages/wiki/Build-environment This command sets up the Termux app environment on an Android device to build Termux packages directly. It installs necessary tools and configures paths. Note that not all packages are supported for on-device builds, and termux-exec must be functional. ```shell ./scripts/setup-termux.sh ``` -------------------------------- ### Termux Package Build Script Example Source: https://github.com/termux/termux-packages/blob/master/CONTRIBUTING.md An example of a `build.sh` script used in the Termux packages repository. This script defines essential package metadata such as homepage, description, license, version, source URL, and checksums, along with optional build-related variables. ```bash TERMUX_PKG_HOMEPAGE=https://example.com TERMUX_PKG_DESCRIPTION="Termux package" TERMUX_PKG_LICENSE="GPL-3.0" TERMUX_PKG_MAINTAINER="@github" TERMUX_PKG_VERSION=1.0 TERMUX_PKG_SRCURL=https://example.com/sources-${TERMUX_PKG_VERSION}.tar.gz TERMUX_PKG_SHA256=0000000000000000000000000000000000000000000000000000000000000000 ``` -------------------------------- ### Configure apt-mirror for Termux Source: https://github.com/termux/termux-packages/wiki/How-to-mirror-the-official-repositories Example configuration for the apt-mirror Perl script to synchronize multiple Termux repository architectures. It defines paths, threads, and specific repository URLs to mirror. ```text set base_path /data/data/com.termux/files/home/termux set mirror_path $base_path/mirror set skel_path $base_path/skel set var_path $base_path/var set postmirror_script $var_path/postmirror.sh set defaultarch aarch64 set run_postmirror 0 set nthreads 20 set limit_rate 100m set _tilde 0 set unlink 0 set use_proxy off set http_proxy 127.0.0.1:3128 set proxy_user user set proxy_password password deb-aarch64 https://packages.termux.dev/apt/termux-main stable main deb-arm https://packages.termux.dev/apt/termux-main stable main deb-i686 https://packages.termux.dev/apt/termux-main stable main deb-x86_64 https://packages.termux.dev/apt/termux-main stable main clean https://packages.termux.dev/apt/termux-main deb-aarch64 https://packages.termux.dev/apt/termux-root root stable deb-arm https://packages.termux.dev/apt/termux-root root stable deb-i686 https://packages.termux.dev/apt/termux-root root stable deb-x86_64 https://packages.termux.dev/apt/termux-root root stable clean https://packages.termux.dev/apt/termux-root deb-aarch64 https://packages.termux.dev/apt/termux-x11 x11 main deb-arm https://packages.termux.dev/apt/termux-x11 x11 main deb-i686 https://packages.termux.dev/apt/termux-x11 x11 main deb-x86_64 https://packages.termux.dev/apt/termux-x11 x11 main clean https://packages.termux.dev/apt/termux-x11 ``` -------------------------------- ### Override Package Build Steps Source: https://context7.com/termux/termux-packages/llms.txt Demonstrates how to override standard build hooks such as post_get_source, pre_configure, configure, make, and install to handle complex package requirements. ```bash termux_step_post_get_source() { sed -i 's/old_value/new_value/' configure.ac } termux_step_pre_configure() { autoreconf -fi export CFLAGS="$CFLAGS -DCUSTOM_FLAG" } termux_step_configure() { $TERMUX_PKG_SRCDIR/configure --prefix=$TERMUX_PREFIX --host=$TERMUX_HOST_PLATFORM --with-ssl=$TERMUX_PREFIX } termux_step_make() { make -j $TERMUX_PKG_MAKE_PROCESSES CC=$CC CXX=$CXX LDFLAGS="$LDFLAGS" } termux_step_make_install() { make install DESTDIR= PREFIX=$TERMUX_PREFIX install -Dm644 extra.conf $TERMUX_PREFIX/etc/extra.conf } ``` -------------------------------- ### Build Packages from Local Source Source: https://context7.com/termux/termux-packages/llms.txt Provides instructions on configuring build.sh to use local file paths or git repositories instead of remote URLs for development and testing. ```bash TERMUX_PKG_SRCURL=file:///home/builder/termux-packages/sources/mypackage TERMUX_PKG_SHA256=SKIP_CHECKSUM # Build command ./scripts/run-docker.sh ./build-package.sh -f -I mypackage ``` -------------------------------- ### Execute System Binaries Safely in Termux Source: https://github.com/termux/termux-packages/wiki/Termux-execution-environment Demonstrates how to temporarily clear environment variables like LD_PRELOAD and set a clean PATH to execute system binaries without interference from Termux-provided wrappers. ```bash LD_LIBRARY_PATH= LD_PRELOAD= PATH=/system/bin /system/bin/pm path com.termux ``` ```bash out="$(LD_PRELOAD= /system/bin/pm path com.termux 2>&1