2015-06-12 23:03:31 +00:00
#!/bin/bash
2018-08-27 20:27:42 +00:00
# shellcheck disable=SC1117
2015-06-12 23:03:31 +00:00
set -e -o pipefail -u
2017-01-06 01:37:45 +00:00
# Utility function to log an error message and exit with an error code.
2019-02-26 20:25:56 +00:00
source scripts/build/termux_error_exit.sh
2017-12-07 02:19:46 +00:00
2018-08-20 22:35:50 +00:00
# Utility function to download a resource with an expected checksum.
2019-02-26 20:29:01 +00:00
source scripts/build/termux_download.sh
2017-01-06 01:37:45 +00:00
# Utility function for golang-using packages to setup a go toolchain.
2019-02-26 20:30:03 +00:00
source scripts/build/setup/termux_setup_golang.sh
2017-01-06 01:37:45 +00:00
2018-09-03 21:57:26 +00:00
# Utility function for rust-using packages to setup a rust toolchain.
2019-02-26 20:33:42 +00:00
source scripts/build/setup/termux_setup_rust.sh
2018-09-03 21:57:26 +00:00
2017-11-07 01:26:49 +00:00
# Utility function to setup a current ninja build system.
2019-02-26 20:34:02 +00:00
source scripts/build/setup/termux_setup_ninja.sh
2017-07-29 00:11:04 +00:00
2017-11-07 01:26:49 +00:00
# Utility function to setup a current meson build system.
2019-02-26 20:34:34 +00:00
source scripts/build/setup/termux_setup_meson.sh
2017-07-29 00:11:04 +00:00
2017-11-07 01:26:49 +00:00
# Utility function to setup a current cmake build system
2019-02-26 20:35:27 +00:00
source scripts/build/setup/termux_setup_cmake.sh
2017-01-11 17:21:58 +00:00
2017-01-06 01:37:45 +00:00
# First step is to handle command-line arguments. Not to be overridden by packages.
2019-02-26 20:36:00 +00:00
source scripts/build/termux_step_handle_arguments.sh
2017-01-06 01:37:45 +00:00
# Setup variables used by the build. Not to be overridden by packages.
2019-02-26 20:36:42 +00:00
source scripts/build/termux_step_setup_variables.sh
2017-01-06 01:37:45 +00:00
# Save away and restore build setups which may change between builds.
2019-02-26 20:37:26 +00:00
source scripts/build/termux_step_handle_buildarch.sh
2016-05-30 23:25:12 +00:00
2018-12-29 10:56:40 +00:00
# Function to get TERMUX_PKG_VERSION from build.sh
2019-02-26 20:39:17 +00:00
source scripts/build/termux_extract_dep_info.sh
2018-12-29 10:56:40 +00:00
2019-02-26 20:39:58 +00:00
# Function that downloads a .deb (using the termux_download function)
source scripts/build/termux_download_deb.sh
2018-12-29 13:50:27 +00:00
2019-01-01 20:56:42 +00:00
# Script to download InRelease, verify it's signature and then download Packages.xz by hash
2019-02-26 20:40:40 +00:00
source scripts/build/termux_step_get_repo_files.sh
2019-01-01 20:56:42 +00:00
# Source the package build script and start building. No to be overridden by packages.
2019-02-26 20:41:19 +00:00
source scripts/build/termux_step_start_build.sh
2017-01-06 01:37:45 +00:00
# Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. May be overridden by packages.
2019-02-26 20:42:19 +00:00
source scripts/build/termux_step_extract_package.sh
2015-06-12 23:03:31 +00:00
2017-01-06 01:37:45 +00:00
# Hook for packages to act just after the package has been extracted.
2017-01-10 08:14:35 +00:00
# Invoked in $TERMUX_PKG_SRCDIR.
2017-01-10 11:35:05 +00:00
termux_step_post_extract_package( ) {
2019-02-12 08:23:21 +00:00
return
2015-06-12 23:03:31 +00:00
}
2017-01-06 01:37:45 +00:00
# Optional host build. Not to be overridden by packages.
2019-02-26 20:27:00 +00:00
source scripts/build/termux_step_handle_hostbuild.sh
2017-01-06 01:37:45 +00:00
2015-06-12 23:03:31 +00: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()
2019-02-26 20:28:04 +00:00
source scripts/build/termux_step_host_build.sh
2015-06-12 23:03:31 +00:00
2017-01-06 01:37:45 +00:00
# Setup a standalone Android NDK toolchain. Not to be overridden by packages.
2019-02-27 18:37:27 +00:00
source scripts/build/termux_step_setup_toolchain.sh
2017-01-06 01:37:45 +00:00
2017-01-07 05:38:04 +00:00
# Apply all *.patch files for the package. Not to be overridden by packages.
2019-02-27 18:38:58 +00:00
source scripts/build/termux_step_patch_package.sh
2015-06-12 23:03:31 +00:00
2017-03-05 10:40:50 +00:00
# Replace autotools build-aux/config.{sub,guess} with ours to add android targets.
2019-02-27 18:39:41 +00:00
source scripts/build/termux_step_replace_guess_scripts.sh
2015-06-12 23:03:31 +00:00
2017-01-06 01:37:45 +00:00
# For package scripts to override. Called in $TERMUX_PKG_BUILDDIR.
2017-01-10 11:35:05 +00:00
termux_step_pre_configure( ) {
2017-01-06 01:37:45 +00:00
return
2015-06-12 23:03:31 +00:00
}
2019-02-27 18:40:34 +00:00
# Setup configure args and run $TERMUX_PKG_SRCDIR/configure. This function is called from termux_step_configure
source scripts/build/configure/termux_step_configure_autotools.sh
2015-06-12 23:03:31 +00:00
2019-02-27 18:47:03 +00:00
# Setup configure args and run cmake. This function is called from termux_step_configure
source scripts/build/configure/termux_step_configure_cmake.sh
2017-01-15 12:48:05 +00:00
2019-02-27 18:48:46 +00:00
# Setup configure args and run meson. This function is called from termux_step_configure
source scripts/build/configure/termux_step_configure_meson.sh
2017-07-29 00:11:04 +00:00
2019-02-27 18:49:12 +00:00
# Configure the package
source scripts/build/configure/termux_step_configure.sh
2017-01-15 12:48:05 +00:00
2019-02-08 09:37:29 +00:00
termux_step_post_configure( ) {
2017-01-06 01:37:45 +00:00
return
2015-06-12 23:03:31 +00:00
}
2019-02-27 18:49:39 +00:00
# Make package, either with ninja or make
source scripts/build/termux_step_make.sh
2015-06-12 23:03:31 +00:00
2019-02-27 18:50:20 +00:00
# Make install, either with ninja, make of cargo
source scripts/build/termux_step_make_install.sh
2015-06-12 23:03:31 +00:00
2017-01-06 01:37:45 +00:00
# Hook function for package scripts to override.
2017-01-10 11:35:05 +00:00
termux_step_post_make_install( ) {
2017-01-06 01:37:45 +00:00
return
2015-06-12 23:03:31 +00:00
}
2019-02-27 18:53:53 +00:00
# Function to cp (through tar) installed files to massage dir
source scripts/build/termux_step_extract_into_massagedir.sh
2015-06-12 23:03:31 +00:00
2019-02-27 18:58:17 +00:00
# Function to run various cleanup/fixes
source scripts/build/termux_step_massage.sh
2015-06-12 23:03:31 +00:00
2017-01-10 11:35:05 +00:00
termux_step_post_massage( ) {
2017-01-06 01:37:45 +00:00
return
2015-06-12 23:03:31 +00:00
}
2017-01-06 01:37:45 +00:00
# Create data.tar.gz with files to package. Not to be overridden by package scripts.
2019-02-27 18:58:49 +00:00
source scripts/build/termux_step_create_datatar.sh
2016-01-11 00:45:41 +00:00
2017-01-10 11:35:05 +00:00
termux_step_create_debscripts( ) {
2017-01-06 01:37:45 +00:00
return
2015-12-20 17:02:59 +00:00
}
2017-01-06 01:37:45 +00: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 20:23:15 +00:00
Package: $TERMUX_PKG_NAME
2017-01-06 01:37:45 +00:00
Architecture: ${ TERMUX_ARCH }
Installed-Size: ${ TERMUX_PKG_INSTALLSIZE }
Maintainer: $TERMUX_PKG_MAINTAINER
Version: $TERMUX_PKG_FULLVERSION
Homepage: $TERMUX_PKG_HOMEPAGE
HERE
2017-07-31 20:31:05 +00:00
test ! -z " $TERMUX_PKG_BREAKS " && echo " Breaks: $TERMUX_PKG_BREAKS " >> DEBIAN/control
2017-01-06 01:37:45 +00: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 11:25:53 +00:00
test ! -z " $TERMUX_PKG_RECOMMENDS " && echo " Recommends: $TERMUX_PKG_RECOMMENDS " >> DEBIAN/control
2017-01-06 01:37:45 +00:00
test ! -z " $TERMUX_PKG_REPLACES " && echo " Replaces: $TERMUX_PKG_REPLACES " >> DEBIAN/control
2018-06-17 13:23:20 +00:00
test ! -z " $TERMUX_PKG_PROVIDES " && echo " Provides: $TERMUX_PKG_PROVIDES " >> DEBIAN/control
2018-06-03 23:35:38 +00:00
test ! -z " $TERMUX_PKG_SUGGESTS " && echo " Suggests: $TERMUX_PKG_SUGGESTS " >> DEBIAN/control
2019-01-22 17:22:28 +00:00
echo " Description: $TERMUX_PKG_DESCRIPTION " >> DEBIAN/control
2017-01-06 01:37:45 +00: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
2019-01-22 00:18:28 +00:00
# Create control.tar.gz
tar -czf " $TERMUX_PKG_PACKAGEDIR /control.tar.gz " .
2017-01-06 01:37:45 +00:00
test ! -f " $TERMUX_COMMON_CACHEDIR /debian-binary " && echo "2.0" > " $TERMUX_COMMON_CACHEDIR /debian-binary "
2018-03-04 19:05:40 +00:00
TERMUX_PKG_DEBFILE = $TERMUX_DEBDIR /${ TERMUX_PKG_NAME } ${ DEBUG } _${ TERMUX_PKG_FULLVERSION } _${ TERMUX_ARCH } .deb
2017-01-06 01:37:45 +00:00
# Create the actual .deb file:
ar cr " $TERMUX_PKG_DEBFILE " \
" $TERMUX_COMMON_CACHEDIR /debian-binary " \
2019-01-22 00:18:28 +00:00
" $TERMUX_PKG_PACKAGEDIR /control.tar.gz " \
2017-01-06 01:37:45 +00:00
" $TERMUX_PKG_PACKAGEDIR /data.tar.xz "
}
2015-06-12 23:03:31 +00:00
2018-12-30 23:31:44 +00:00
termux_step_compare_debs( ) {
2018-12-29 16:26:35 +00:00
if [ " ${ TERMUX_INSTALL_DEPS } " = true ] ; then
2018-12-30 23:31:44 +00:00
cd ${ TERMUX_SCRIPTDIR }
2019-01-01 20:56:42 +00:00
2019-02-24 08:09:22 +00:00
for DEB in $TERMUX_PKG_NAME $( basename $TERMUX_PKG_BUILDER_DIR /*.subpackage.sh | sed 's%\.subpackage\.sh%%g' ) $( basename $TERMUX_PKG_TMPDIR /*.subpackage.sh | sed 's%\.subpackage\.sh%%g' ) ; do
read DEB_ARCH DEB_VERSION <<< $( termux_extract_dep_info " $DEB " )
termux_download_deb $DEB $DEB_ARCH $DEB_VERSION \
&& (
DEB_FILE = ${ DEB } _${ DEB_VERSION } _${ DEB_ARCH } .deb
2018-12-29 16:26:35 +00:00
2019-02-24 08:09:22 +00:00
# `|| true` to prevent debdiff's exit code from stopping build
debdiff $TERMUX_DEBDIR /$DEB_FILE $TERMUX_COMMON_CACHEDIR -$TERMUX_ARCH /$DEB_FILE || true
) || echo " Download of ${ DEB } @ ${ DEB_VERSION } failed, not comparing debs "
echo ""
done
2018-12-29 16:26:35 +00:00
fi
}
2017-10-02 14:54:53 +00:00
2017-01-06 01:37:45 +00: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 11:39:25 +00:00
exit 0
2017-01-06 01:37:45 +00:00
}
2016-09-24 23:30:20 +00:00
2017-01-06 01:37:45 +00:00
termux_step_handle_arguments " $@ "
termux_step_setup_variables
termux_step_handle_buildarch
2019-01-01 20:56:42 +00:00
termux_step_get_repo_files
2017-01-06 01:37:45 +00:00
termux_step_start_build
2015-06-12 23:03:31 +00:00
termux_step_extract_package
2017-01-10 08:14:35 +00:00
cd " $TERMUX_PKG_SRCDIR "
2015-06-12 23:03:31 +00:00
termux_step_post_extract_package
2017-01-06 01:37:45 +00:00
termux_step_handle_hostbuild
termux_step_setup_toolchain
2015-06-12 23:03:31 +00:00
termux_step_patch_package
2017-03-05 10:40:50 +00:00
termux_step_replace_guess_scripts
2017-05-10 23:01:20 +00:00
cd " $TERMUX_PKG_SRCDIR "
2015-06-12 23:03:31 +00:00
termux_step_pre_configure
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_BUILDDIR "
2015-06-12 23:03:31 +00:00
termux_step_configure
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_BUILDDIR "
2015-06-12 23:03:31 +00:00
termux_step_post_configure
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_BUILDDIR "
2015-06-12 23:03:31 +00:00
termux_step_make
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_BUILDDIR "
2015-06-12 23:03:31 +00:00
termux_step_make_install
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_BUILDDIR "
2015-06-12 23:03:31 +00:00
termux_step_post_make_install
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_MASSAGEDIR "
2015-06-12 23:03:31 +00:00
termux_step_extract_into_massagedir
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_MASSAGEDIR "
2015-06-12 23:03:31 +00:00
termux_step_massage
2017-01-06 01:37:45 +00:00
cd " $TERMUX_PKG_MASSAGEDIR / $TERMUX_PREFIX "
2015-06-12 23:03:31 +00:00
termux_step_post_massage
2017-01-06 01:37:45 +00:00
termux_step_create_datatar
termux_step_create_debfile
2018-12-30 23:31:44 +00:00
termux_step_compare_debs
2017-01-06 01:37:45 +00:00
termux_step_finish_build