Browse Source

build-package.sh: use text-based comparsion in conditionals instead of exit-code based

emacs-27
Leonid Plyushch 5 years ago
parent
commit
6267a318aa
No known key found for this signature in database GPG Key ID: 45F2964132545795
  1. 12
      build-package.sh
  2. 2
      scripts/build/configure/termux_step_configure.sh
  3. 2
      scripts/build/configure/termux_step_configure_autotools.sh
  4. 2
      scripts/build/configure/termux_step_configure_cmake.sh
  5. 2
      scripts/build/setup/termux_setup_cmake.sh
  6. 2
      scripts/build/setup/termux_setup_golang.sh
  7. 2
      scripts/build/setup/termux_setup_ninja.sh
  8. 2
      scripts/build/setup/termux_setup_protobuf.sh
  9. 2
      scripts/build/setup/termux_setup_rust.sh
  10. 2
      scripts/build/termux_create_subpackages.sh
  11. 2
      scripts/build/termux_download_deb.sh
  12. 6
      scripts/build/termux_extract_dep_info.sh
  13. 2
      scripts/build/termux_step_handle_hostbuild.sh
  14. 2
      scripts/build/termux_step_massage.sh
  15. 2
      scripts/build/termux_step_patch_package.sh
  16. 8
      scripts/build/termux_step_setup_toolchain.sh
  17. 6
      scripts/build/termux_step_setup_variables.sh
  18. 14
      scripts/build/termux_step_start_build.sh

12
build-package.sh

@ -168,7 +168,7 @@ export TERMUX_SCRIPTDIR
# shellcheck source=scripts/properties.sh
. "$TERMUX_SCRIPTDIR/scripts/properties.sh"
if $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
# For on device builds cross compiling is not supported.
# Target architecture must be same as for environment used currently.
export TERMUX_ARCH=$(dpkg --print-architecture)
@ -180,11 +180,11 @@ _show_usage() {
echo "Build a package by creating a .deb file in the debs/ folder."
echo
echo "Available options:"
! $TERMUX_ON_DEVICE_BUILD && echo " -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all."
[ "$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 && echo " -i Download and extract dependencies instead of building them."
[ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && echo " -i Download and extract dependencies instead of building them."
echo " -I Download and extract dependencies instead of building them, keep existing /data/data/com.termux files."
echo " -q Quiet build."
echo " -s Skip dependency check."
@ -195,7 +195,7 @@ _show_usage() {
while getopts :a:hdDfiIqso: option; do
case "$option" in
a)
if $TERMUX_ON_DEVICE_BUILD; then
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="$OPTARG"
@ -206,7 +206,7 @@ while getopts :a:hdDfiIqso: option; do
D) local TERMUX_IS_DISABLED=true;;
f) TERMUX_FORCE_BUILD=true;;
i)
if $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
termux_error_exit "./build-package.sh: option '-i' is not available for on-device builds"
else
export TERMUX_INSTALL_DEPS=true
@ -236,7 +236,7 @@ while (($# > 0)); do
fi
# Handle 'all' arch:
if ! $TERMUX_ON_DEVICE_BUILD && [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then
for arch in 'aarch64' 'arm' 'i686' 'x86_64'; do
env TERMUX_ARCH="$arch" TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh \
${TERMUX_FORCE_BUILD+-f} ${TERMUX_INSTALL_DEPS+-i} ${TERMUX_IS_DISABLED+-D} \

2
scripts/build/configure/termux_step_configure.sh

@ -1,5 +1,5 @@
termux_step_configure() {
if ! ${TERMUX_PKG_FORCE_CMAKE-false} && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then
if [ "$TERMUX_PKG_FORCE_CMAKE" = "false" ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then
termux_step_configure_autotools
elif [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then
termux_step_configure_cmake

2
scripts/build/configure/termux_step_configure_autotools.sh

@ -32,7 +32,7 @@ termux_step_configure_autotools() {
QUIET_BUILD="--enable-silent-rules --silent --quiet"
fi
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
# Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config:
mkdir "$TERMUX_PKG_TMPDIR/config-scripts"
for f in $TERMUX_PREFIX/bin/*config; do

2
scripts/build/configure/termux_step_configure_cmake.sh

@ -18,7 +18,7 @@ termux_step_configure_cmake() {
CFLAGS+=" -fno-addrsig"
local CMAKE_ADDITIONAL_ARGS=()
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
CXXFLAGS+=" --target=$CCTERMUX_HOST_PLATFORM"
CFLAGS+=" --target=$CCTERMUX_HOST_PLATFORM"
LDFLAGS+=" --target=$CCTERMUX_HOST_PLATFORM"

2
scripts/build/setup/termux_setup_cmake.sh

@ -6,7 +6,7 @@ termux_setup_cmake() {
local TERMUX_CMAKE_TARFILE=$TERMUX_PKG_TMPDIR/$TERMUX_CMAKE_TARNAME
local TERMUX_CMAKE_FOLDER=$TERMUX_COMMON_CACHEDIR/cmake-$TERMUX_CMAKE_VERSION
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
if [ ! -d "$TERMUX_CMAKE_FOLDER" ]; then
termux_download https://cmake.org/files/v$TERMUX_CMAKE_MAJORVESION/$TERMUX_CMAKE_TARNAME \
"$TERMUX_CMAKE_TARFILE" \

2
scripts/build/setup/termux_setup_golang.sh

@ -19,7 +19,7 @@ termux_setup_golang() {
termux_error_exit "Unsupported arch: $TERMUX_ARCH"
fi
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
local TERMUX_GO_VERSION=go1.12.7
local TERMUX_GO_PLATFORM=linux-amd64

2
scripts/build/setup/termux_setup_ninja.sh

@ -2,7 +2,7 @@ termux_setup_ninja() {
local NINJA_VERSION=1.9.0
local NINJA_FOLDER=$TERMUX_COMMON_CACHEDIR/ninja-$NINJA_VERSION
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
if [ ! -x "$NINJA_FOLDER/ninja" ]; then
mkdir -p "$NINJA_FOLDER"
local NINJA_ZIP_FILE=$TERMUX_PKG_TMPDIR/ninja-$NINJA_VERSION.zip

2
scripts/build/setup/termux_setup_protobuf.sh

@ -3,7 +3,7 @@ termux_setup_protobuf() {
local _PROTOBUF_ZIP=protoc-$_PROTOBUF_VERSION-linux-x86_64.zip
local _PROTOBUF_FOLDER=$TERMUX_COMMON_CACHEDIR/protobuf-$_PROTOBUF_VERSION
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
if [ ! -d "$_PROTOBUF_FOLDER" ]; then
termux_download \
https://github.com/protocolbuffers/protobuf/releases/download/v$_PROTOBUF_VERSION/$_PROTOBUF_ZIP \

2
scripts/build/setup/termux_setup_rust.sh

@ -7,7 +7,7 @@ termux_setup_rust() {
export RUSTFLAGS="-C link-arg=-Wl,-rpath=$TERMUX_PREFIX/lib -C link-arg=-Wl,--enable-new-dtags"
if $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
if [ "$(dpkg-query -W -f '${db:Status-Status}\n' rust 2>/dev/null)" != "installed" ]; then
echo "Package 'rust' is not installed."
echo "You can install it with"

2
scripts/build/termux_create_subpackages.sh

@ -1,6 +1,6 @@
termux_create_subpackages() {
# Sub packages:
if ! ${TERMUX_PKG_NO_STATICSPLIT-false} && [[ -n $(shopt -s nullglob; echo lib/*.a) ]]; then
if [ "$TERMUX_PKG_NO_STATICSPLIT" = "false" ] && [[ -n $(shopt -s nullglob; echo lib/*.a) ]]; then
# Add virtual -static sub package if there are include files:
local _STATIC_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-static.subpackage.sh
echo TERMUX_SUBPKG_INCLUDE=\"lib/**/*.a lib/**/*.la\" > "$_STATIC_SUBPACKAGE_FILE"

2
scripts/build/termux_download_deb.sh

@ -3,7 +3,7 @@ termux_download_deb() {
local PACKAGE_ARCH=$2
local VERSION=$3
if $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
apt install -y "${PACKAGE}=${VERSION}"
return "$?"
fi

6
scripts/build/termux_extract_dep_info.sh

@ -8,10 +8,10 @@ termux_extract_dep_info() {
TERMUX_PKG_PLATFORM_INDEPENDENT=false
source ${PKG_DIR}/build.sh
TERMUX_SUBPKG_PLATFORM_INDEPENDENT=$TERMUX_PKG_PLATFORM_INDEPENDENT
if ! $TERMUX_INSTALL_DEPS || ${TERMUX_PKG_NO_STATICSPLIT-false} || [ "${PKG/-static/}-static" != "${PKG}" ]; then
if [ "$TERMUX_INSTALL_DEPS" = "false" ] || [ "$TERMUX_PKG_NO_STATICSPLIT" = "true" ] || [ "${PKG/-static/}-static" != "${PKG}" ]; then
source ${PKG_DIR}/${PKG}.subpackage.sh
fi
if ${TERMUX_SUBPKG_PLATFORM_INDEPENDENT-false}; then
if [ "$TERMUX_SUBPKG_PLATFORM_INDEPENDENT" = "true" ]; then
echo all
else
echo $TERMUX_ARCH
@ -29,7 +29,7 @@ termux_extract_dep_info() {
TERMUX_PKG_PLATFORM_INDEPENDENT=false
TERMUX_PKG_REVISION="0"
source ${PKG_DIR}/build.sh
${TERMUX_PKG_PLATFORM_INDEPENDENT-false} && TERMUX_ARCH=all
[ "$TERMUX_PKG_PLATFORM_INDEPENDENT" = "true" ] && TERMUX_ARCH=all
if [ "$TERMUX_PKG_REVISION" != "0" ] || [ "$TERMUX_PKG_VERSION" != "${TERMUX_PKG_VERSION/-/}" ]; then
TERMUX_PKG_VERSION+="-$TERMUX_PKG_REVISION"
fi

2
scripts/build/termux_step_handle_hostbuild.sh

@ -1,5 +1,5 @@
termux_step_handle_hostbuild() {
if ! ${TERMUX_PKG_HOSTBUILD-false}; then return; fi
if [ "$TERMUX_PKG_HOSTBUILD" = "false" ]; then return; fi
cd "$TERMUX_PKG_SRCDIR"
for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do

2
scripts/build/termux_step_massage.sh

@ -16,7 +16,7 @@ termux_step_massage() {
# Remove world permissions and make sure that user still have read-write permissions.
chmod -Rf u+rw,g-rwx,o-rwx . || true
if ! $TERMUX_DEBUG; then
if [ "$TERMUX_DEBUG" = "false" ]; then
# Strip binaries. file(1) may fail for certain unusual files, so disable pipefail.
set +e +o pipefail
find . \( -path "./bin/*" -o -path "./lib/*" -o -path "./libexec/*" \) -type f | \

2
scripts/build/termux_step_patch_package.sh

@ -1,7 +1,7 @@
termux_step_patch_package() {
cd "$TERMUX_PKG_SRCDIR"
local DEBUG_PATCHES=""
if $TERMUX_DEBUG && [ -f $TERMUX_PKG_BUILDER_DIR/*.patch.debug ] ; then
if [ "$TERMUX_DEBUG" = "true" ] && [ -f $TERMUX_PKG_BUILDER_DIR/*.patch.debug ] ; then
DEBUG_PATCHES="$(ls $TERMUX_PKG_BUILDER_DIR/*.patch.debug)"
fi
# Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses:

8
scripts/build/termux_step_setup_toolchain.sh

@ -14,7 +14,7 @@ termux_step_setup_toolchain() {
export READELF=$TERMUX_HOST_PLATFORM-readelf
export STRIP=$TERMUX_HOST_PLATFORM-strip
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
export PATH=$TERMUX_STANDALONE_TOOLCHAIN/bin:$PATH
export CC_FOR_BUILD=gcc
export PKG_CONFIG=$TERMUX_STANDALONE_TOOLCHAIN/bin/${TERMUX_HOST_PLATFORM}-pkg-config
@ -56,7 +56,7 @@ termux_step_setup_toolchain() {
CFLAGS+=" -fstack-protector-strong"
LDFLAGS+=" -Wl,-z,relro,-z,now"
if $TERMUX_DEBUG; then
if [ "$TERMUX_DEBUG" = "true" ]; then
CFLAGS+=" -g3 -O1 -D_FORTIFY_SOURCE=2"
else
CFLAGS+=" -Oz"
@ -76,7 +76,7 @@ termux_step_setup_toolchain() {
export ac_cv_func_sigsetmask=no
export ac_cv_c_bigendian=no
if ! $TERMUX_ON_DEVICE_BUILD && [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ ! -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):
local _TERMUX_TOOLCHAIN_TMPDIR=${TERMUX_STANDALONE_TOOLCHAIN}-tmp
@ -173,7 +173,7 @@ termux_step_setup_toolchain() {
export PKG_CONFIG_LIBDIR="$TERMUX_PKG_CONFIG_LIBDIR"
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
# 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

6
scripts/build/termux_step_setup_variables.sh

@ -13,7 +13,7 @@ termux_step_setup_variables() {
: "${TERMUX_INSTALL_DEPS:="false"}"
: "${TERMUX_PACKAGES_DIRECTORIES:="packages"}"
if $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "true" ]; then
# For on-device builds cross-compiling is not supported so we can
# store information about built packages under $TERMUX_TOPDIR.
TERMUX_BUILT_PACKAGES_DIRECTORY="$TERMUX_TOPDIR/.built-packages"
@ -73,11 +73,11 @@ termux_step_setup_variables() {
TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android"
if [ "$TERMUX_ARCH" = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi"; fi
if ! $TERMUX_ON_DEVICE_BUILD && [ ! -d "$NDK" ]; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && [ ! -d "$NDK" ]; then
termux_error_exit 'NDK not pointing at a directory!'
fi
if ! $TERMUX_ON_DEVICE_BUILD && ! grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION_NUM" "$NDK/source.properties"; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && ! grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION_NUM" "$NDK/source.properties"; then
termux_error_exit "Wrong NDK version - we need $TERMUX_NDK_VERSION"
fi

14
scripts/build/termux_step_start_build.sh

@ -18,8 +18,8 @@ termux_step_start_build() {
TERMUX_PKG_FULLVERSION+="-$TERMUX_PKG_REVISION"
fi
if $TERMUX_DEBUG; then
if $TERMUX_PKG_HAS_DEBUG; then
if [ "$TERMUX_DEBUG" = "true" ]; then
if [ "$TERMUX_PKG_HAS_DEBUG" = "true" ]; then
DEBUG="-dbg"
else
echo "Skipping building debug build for $TERMUX_PKG_NAME"
@ -29,12 +29,12 @@ termux_step_start_build() {
DEBUG=""
fi
if ! $TERMUX_DEBUG && ${TERMUX_FORCE_BUILD-false}; then
if [ "$TERMUX_DEBUG" = "true" ] && [ "$TERMUX_FORCE_BUILD" = "true" ]; then
if [ -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/$TERMUX_PKG_NAME" ] &&
[ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/$TERMUX_PKG_NAME")" = "$TERMUX_PKG_FULLVERSION" ]; then
echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION built - skipping (rm $TERMUX_BUILT_PACKAGES_DIRECTORY/$TERMUX_PKG_NAME to force rebuild)"
exit 0
elif $TERMUX_ON_DEVICE_BUILD &&
elif [ "$TERMUX_ON_DEVICE_BUILD" = "true" ] &&
[ "$(dpkg-query -W -f '${db:Status-Status} ${Version}\n' "$TERMUX_PKG_NAME" 2>/dev/null)" = "installed $TERMUX_PKG_FULLVERSION" ]; then
echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION installed - skipping"
exit 0
@ -74,7 +74,7 @@ termux_step_start_build() {
TERMUX_BUILD_IGNORE_LOCK=true ./build-package.sh -I "${PKG_DIR}"
continue
else
if ! $TERMUX_ON_DEVICE_BUILD; then
if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then
if [ ! "$TERMUX_QUIET_BUILD" = true ]; then echo "extracting $PKG..."; fi
(
cd $TERMUX_COMMON_CACHEDIR-$DEP_ARCH
@ -125,7 +125,7 @@ termux_step_start_build() {
# 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:
! $TERMUX_ON_DEVICE_BUILD && ln -sf /bin/sh "$TERMUX_PREFIX/bin/sh"
[ "$TERMUX_ON_DEVICE_BUILD" = "false" ] && ln -sf /bin/sh "$TERMUX_PREFIX/bin/sh"
local TERMUX_ELF_CLEANER_SRC=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner.cpp
local TERMUX_ELF_CLEANER_VERSION
@ -139,7 +139,7 @@ termux_step_start_build() {
"$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER"
fi
if ${TERMUX_PKG_BUILD_IN_SRC-false}; then
if [ "$TERMUX_PKG_BUILD_IN_SRC" = "true" ]; then
echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set to true" > "$TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt"
TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR
fi

Loading…
Cancel
Save