| 1 | #!/bin/bash |
| 2 | |
| 3 | set -e -o pipefail -u |
| 4 | |
| 5 | # Utility function to log an error message and exit with an error code. |
| 6 | termux_error_exit() { |
| 7 | echo "ERROR: $*" 1>&2 |
| 8 | exit 1 |
| 9 | } |
| 10 | |
| 11 | # Utility function to download a resource, optionally checking against a checksum. |
| 12 | termux_download() { |
| 13 | local URL="$1" |
| 14 | local DESTINATION="$2" |
| 15 | |
| 16 | if [ -f "$DESTINATION" ] && [ $# = 3 ] && [ -n "$3" ]; then |
| 17 | # Keep existing file if checksum matches. |
| 18 | local EXISTING_CHECKSUM |
| 19 | EXISTING_CHECKSUM=$(sha256sum "$DESTINATION" | cut -f 1 -d ' ') |
| 20 | if [ "$EXISTING_CHECKSUM" = "$3" ]; then return; fi |
| 21 | fi |
| 22 | |
| 23 | local TMPFILE |
| 24 | TMPFILE=$(mktemp "$TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX") |
| 25 | echo "Downloading ${URL}" |
| 26 | local TRYMAX=6 |
| 27 | for try in $(seq 1 $TRYMAX); do |
| 28 | if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then |
| 29 | local ACTUAL_CHECKSUM |
| 30 | ACTUAL_CHECKSUM=$(sha256sum "$TMPFILE" | cut -f 1 -d ' ') |
| 31 | if [ $# = 3 ] && [ -n "$3" ]; then |
| 32 | # Optional checksum argument: |
| 33 | local EXPECTED=$3 |
| 34 | if [ "$EXPECTED" != "$ACTUAL_CHECKSUM" ]; then |
| 35 | >&2 printf "Wrong checksum for %s:\nExpected: %s\nActual: %s\n" \ |
| 36 | "$URL" "$EXPECTED" "$ACTUAL_CHECKSUM" |
| 37 | exit 1 |
| 38 | fi |
| 39 | else |
| 40 | printf "No validation of checksum for %s:\nActual: %s\n" \ |
| 41 | "$URL" "$ACTUAL_CHECKSUM" |
| 42 | fi |
| 43 | mv "$TMPFILE" "$DESTINATION" |
| 44 | return |
| 45 | else |
| 46 | echo "Download of $URL failed (attempt $try/$TRYMAX)" 1>&2 |
| 47 | sleep 45 |
| 48 | fi |
| 49 | done |
| 50 | |
| 51 | termux_error_exit "Failed to download $URL" |
| 52 | } |
| 53 | |
| 54 | # Utility function for golang-using packages to setup a go toolchain. |
| 55 | termux_setup_golang() { |
| 56 | export GOOS=android |
| 57 | export CGO_ENABLED=1 |
| 58 | export GO_LDFLAGS="-extldflags=-pie" |
| 59 | if [ "$TERMUX_ARCH" = "arm" ]; then |
| 60 | export GOARCH=arm |
| 61 | export GOARM=7 |
| 62 | elif [ "$TERMUX_ARCH" = "i686" ]; then |
| 63 | export GOARCH=386 |
| 64 | export GO386=sse2 |
| 65 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then |
| 66 | export GOARCH=arm64 |
| 67 | elif [ "$TERMUX_ARCH" = "x86_64" ]; then |
| 68 | export GOARCH=amd64 |
| 69 | else |
| 70 | termux_error_exit "Unsupported arch: $TERMUX_ARCH" |
| 71 | fi |
| 72 | |
| 73 | local TERMUX_GO_VERSION=go1.9.2 |
| 74 | local TERMUX_GO_PLATFORM=linux-amd64 |
| 75 | |
| 76 | local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION} |
| 77 | export GOROOT=$TERMUX_BUILDGO_FOLDER |
| 78 | export PATH=$GOROOT/bin:$PATH |
| 79 | |
| 80 | if [ -d "$TERMUX_BUILDGO_FOLDER" ]; then return; fi |
| 81 | |
| 82 | local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz |
| 83 | rm -Rf "$TERMUX_COMMON_CACHEDIR/go" "$TERMUX_BUILDGO_FOLDER" |
| 84 | termux_download https://storage.googleapis.com/golang/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz \ |
| 85 | "$TERMUX_BUILDGO_TAR" \ |
| 86 | de874549d9a8d8d8062be05808509c09a88a248e77ec14eb77453530829ac02b |
| 87 | |
| 88 | ( cd "$TERMUX_COMMON_CACHEDIR"; tar xf "$TERMUX_BUILDGO_TAR"; mv go "$TERMUX_BUILDGO_FOLDER"; rm "$TERMUX_BUILDGO_TAR" ) |
| 89 | } |
| 90 | |
| 91 | # Utility function to setup a current ninja build system. |
| 92 | termux_setup_ninja() { |
| 93 | local NINJA_VERSION=1.8.2 |
| 94 | local NINJA_FOLDER=$TERMUX_COMMON_CACHEDIR/ninja-$NINJA_VERSION |
| 95 | if [ ! -x $NINJA_FOLDER/ninja ]; then |
| 96 | mkdir -p $NINJA_FOLDER |
| 97 | local NINJA_ZIP_FILE=$TERMUX_PKG_TMPDIR/ninja-$NINJA_VERSION.zip |
| 98 | termux_download https://github.com/ninja-build/ninja/releases/download/v$NINJA_VERSION/ninja-linux.zip \ |
| 99 | $NINJA_ZIP_FILE \ |
| 100 | d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07 |
| 101 | unzip $NINJA_ZIP_FILE -d $NINJA_FOLDER |
| 102 | fi |
| 103 | export PATH=$NINJA_FOLDER:$PATH |
| 104 | } |
| 105 | |
| 106 | # Utility function to setup a current meson build system. |
| 107 | termux_setup_meson() { |
| 108 | termux_setup_ninja |
| 109 | local MESON_VERSION=0.43.0 |
| 110 | local MESON_FOLDER=$TERMUX_COMMON_CACHEDIR/meson-$MESON_VERSION |
| 111 | if [ ! -d "$MESON_FOLDER" ]; then |
| 112 | local MESON_TAR_NAME=meson-$MESON_VERSION.tar.gz |
| 113 | local MESON_TAR_FILE=$TERMUX_PKG_TMPDIR/$MESON_TAR_NAME |
| 114 | termux_download \ |
| 115 | https://github.com/mesonbuild/meson/releases/download/$MESON_VERSION/meson-$MESON_VERSION.tar.gz \ |
| 116 | $MESON_TAR_FILE \ |
| 117 | c513eca90e0d70bf14cd1eaafea2fa91cf40a73326a7ff61f08a005048057340 |
| 118 | tar xf "$MESON_TAR_FILE" -C "$TERMUX_COMMON_CACHEDIR" |
| 119 | (cd $MESON_FOLDER && patch -p1 < $TERMUX_SCRIPTDIR/scripts/meson-android.patch) |
| 120 | fi |
| 121 | TERMUX_MESON="$MESON_FOLDER/meson.py" |
| 122 | TERMUX_MESON_CROSSFILE=$TERMUX_COMMON_CACHEDIR/meson-crossfile-$TERMUX_ARCH-v2.txt |
| 123 | if [ ! -f $TERMUX_MESON_CROSSFILE ]; then |
| 124 | local MESON_CPU MESON_CPU_FAMILY |
| 125 | if [ $TERMUX_ARCH = "arm" ]; then |
| 126 | MESON_CPU_FAMILY="arm" |
| 127 | MESON_CPU="armv7" |
| 128 | elif [ $TERMUX_ARCH = "i686" ]; then |
| 129 | MESON_CPU_FAMILY="x86" |
| 130 | MESON_CPU="i686" |
| 131 | elif [ $TERMUX_ARCH = "x86_64" ]; then |
| 132 | MESON_CPU_FAMILY="x86_64" |
| 133 | MESON_CPU="x86_64" |
| 134 | elif [ $TERMUX_ARCH = "aarch64" ]; then |
| 135 | MESON_CPU_FAMILY="arm" |
| 136 | MESON_CPU="aarch64" |
| 137 | else |
| 138 | termux_error_exit "Unsupported arch: $TERMUX_ARCH" |
| 139 | fi |
| 140 | |
| 141 | cat > $TERMUX_MESON_CROSSFILE <<-HERE |
| 142 | [binaries] |
| 143 | ar = '$AR' |
| 144 | c = '$CC' |
| 145 | cpp = '$CXX' |
| 146 | ld = '$LD' |
| 147 | pkgconfig = '$PKG_CONFIG' |
| 148 | strip = '$STRIP' |
| 149 | [properties] |
| 150 | needs_exe_wrapper = true |
| 151 | [host_machine] |
| 152 | cpu_family = '$MESON_CPU_FAMILY' |
| 153 | cpu = '$MESON_CPU' |
| 154 | endian = 'little' |
| 155 | system = 'android' |
| 156 | HERE |
| 157 | fi |
| 158 | } |
| 159 | |
| 160 | # Utility function to setup a current cmake build system |
| 161 | termux_setup_cmake() { |
| 162 | local TERMUX_CMAKE_MAJORVESION=3.9 |
| 163 | local TERMUX_CMAKE_MINORVERSION=6 |
| 164 | local TERMUX_CMAKE_VERSION=$TERMUX_CMAKE_MAJORVESION.$TERMUX_CMAKE_MINORVERSION |
| 165 | local TERMUX_CMAKE_TARNAME=cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64.tar.gz |
| 166 | local TERMUX_CMAKE_TARFILE=$TERMUX_PKG_TMPDIR/$TERMUX_CMAKE_TARNAME |
| 167 | local TERMUX_CMAKE_FOLDER=$TERMUX_COMMON_CACHEDIR/cmake-$TERMUX_CMAKE_VERSION |
| 168 | if [ ! -d "$TERMUX_CMAKE_FOLDER" ]; then |
| 169 | termux_download https://cmake.org/files/v$TERMUX_CMAKE_MAJORVESION/$TERMUX_CMAKE_TARNAME \ |
| 170 | "$TERMUX_CMAKE_TARFILE" \ |
| 171 | 062bf45bee36ce7c2a55ae26b8b5324720f370d420a05cba91b9448c64ffdbea |
| 172 | rm -Rf "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64" |
| 173 | tar xf "$TERMUX_CMAKE_TARFILE" -C "$TERMUX_PKG_TMPDIR" |
| 174 | mv "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64" \ |
| 175 | "$TERMUX_CMAKE_FOLDER" |
| 176 | fi |
| 177 | export PATH=$TERMUX_CMAKE_FOLDER/bin:$PATH |
| 178 | export CMAKE_INSTALL_ALWAYS=1 |
| 179 | } |
| 180 | |
| 181 | # First step is to handle command-line arguments. Not to be overridden by packages. |
| 182 | termux_step_handle_arguments() { |
| 183 | # shellcheck source=/dev/null |
| 184 | test -f "$HOME/.termuxrc" && source "$HOME/.termuxrc" |
| 185 | |
| 186 | # Handle command-line arguments: |
| 187 | _show_usage () { |
| 188 | echo "Usage: ./build-package.sh [-a ARCH] [-d] [-D] [-f] [-q] [-s] PACKAGE" |
| 189 | echo "Build a package by creating a .deb file in the debs/ folder." |
| 190 | echo " -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all." |
| 191 | echo " -d Build with debug symbols." |
| 192 | echo " -D Build a disabled package in disabled-packages/." |
| 193 | echo " -f Force build even if package has already been built." |
| 194 | echo " -q Quiet build" |
| 195 | echo " -s Skip dependency check." |
| 196 | exit 1 |
| 197 | } |
| 198 | while getopts :a:hdDfqs option; do |
| 199 | case "$option" in |
| 200 | a) TERMUX_ARCH="$OPTARG";; |
| 201 | h) _show_usage;; |
| 202 | d) TERMUX_DEBUG=true;; |
| 203 | D) local TERMUX_IS_DISABLED=true;; |
| 204 | f) TERMUX_FORCE_BUILD=true;; |
| 205 | q) export TERMUX_QUIET_BUILD=true;; |
| 206 | s) export TERMUX_SKIP_DEPCHECK=true;; |
| 207 | ?) termux_error_exit "./build-package.sh: illegal option -$OPTARG";; |
| 208 | esac |
| 209 | done |
| 210 | shift $((OPTIND-1)) |
| 211 | |
| 212 | if [ "$#" -ne 1 ]; then _show_usage; fi |
| 213 | unset -f _show_usage |
| 214 | |
| 215 | # Handle 'all' arch: |
| 216 | if [ -n "${TERMUX_ARCH+x}" ] && [ "${TERMUX_ARCH}" = 'all' ]; then |
| 217 | for arch in 'aarch64' 'arm' 'i686' 'x86_64'; do |
| 218 | ./build-package.sh ${TERMUX_FORCE_BUILD+-f} -a $arch "$1" |
| 219 | done |
| 220 | exit |
| 221 | fi |
| 222 | |
| 223 | # Check the package to build: |
| 224 | TERMUX_PKG_NAME=$(basename "$1") |
| 225 | export TERMUX_SCRIPTDIR |
| 226 | TERMUX_SCRIPTDIR=$(cd "$(dirname "$0")"; pwd) |
| 227 | if [[ $1 == *"/"* ]]; then |
| 228 | # Path to directory which may be outside this repo: |
| 229 | if [ ! -d "$1" ]; then termux_error_exit "'$1' seems to be a path but is not a directory"; fi |
| 230 | export TERMUX_PKG_BUILDER_DIR |
| 231 | TERMUX_PKG_BUILDER_DIR=$(realpath "$1") |
| 232 | else |
| 233 | # Package name: |
| 234 | if [ -n "${TERMUX_IS_DISABLED=""}" ]; then |
| 235 | export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/disabled-packages/$TERMUX_PKG_NAME |
| 236 | else |
| 237 | export TERMUX_PKG_BUILDER_DIR=$TERMUX_SCRIPTDIR/packages/$TERMUX_PKG_NAME |
| 238 | fi |
| 239 | fi |
| 240 | TERMUX_PKG_BUILDER_SCRIPT=$TERMUX_PKG_BUILDER_DIR/build.sh |
| 241 | if test ! -f "$TERMUX_PKG_BUILDER_SCRIPT"; then |
| 242 | termux_error_exit "No build.sh script at package dir $TERMUX_PKG_BUILDER_DIR!" |
| 243 | fi |
| 244 | } |
| 245 | |
| 246 | # Setup variables used by the build. Not to be overridden by packages. |
| 247 | termux_step_setup_variables() { |
| 248 | : "${ANDROID_HOME:="${HOME}/lib/android-sdk"}" |
| 249 | : "${NDK:="${HOME}/lib/android-ndk"}" |
| 250 | : "${TERMUX_MAKE_PROCESSES:="$(nproc)"}" |
| 251 | : "${TERMUX_TOPDIR:="$HOME/.termux-build"}" |
| 252 | : "${TERMUX_ARCH:="aarch64"}" # arm, aarch64, i686 or x86_64. |
| 253 | : "${TERMUX_PREFIX:="/data/data/com.termux/files/usr"}" |
| 254 | : "${TERMUX_ANDROID_HOME:="/data/data/com.termux/files/home"}" |
| 255 | : "${TERMUX_DEBUG:=""}" |
| 256 | : "${TERMUX_PKG_API_LEVEL:="21"}" |
| 257 | : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="27.0.1"}" |
| 258 | : "${TERMUX_NDK_VERSION:="16"}" |
| 259 | |
| 260 | if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then |
| 261 | TERMUX_ARCH_BITS=64 |
| 262 | else |
| 263 | TERMUX_ARCH_BITS=32 |
| 264 | fi |
| 265 | |
| 266 | TERMUX_HOST_PLATFORM="${TERMUX_ARCH}-linux-android" |
| 267 | if [ "$TERMUX_ARCH" = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi"; fi |
| 268 | |
| 269 | if [ ! -d "$NDK" ]; then |
| 270 | termux_error_exit 'NDK not pointing at a directory!' |
| 271 | fi |
| 272 | if ! grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION" "$NDK/source.properties"; then |
| 273 | termux_error_exit "Wrong NDK version - we need $TERMUX_NDK_VERSION" |
| 274 | fi |
| 275 | |
| 276 | # The build tuple that may be given to --build configure flag: |
| 277 | TERMUX_BUILD_TUPLE=$(sh "$TERMUX_SCRIPTDIR/scripts/config.guess") |
| 278 | |
| 279 | # We do not put all of build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/ into PATH |
| 280 | # to avoid stuff like arm-linux-androideabi-ld there to conflict with ones from |
| 281 | # the standalone toolchain. |
| 282 | TERMUX_DX=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/dx |
| 283 | |
| 284 | TERMUX_COMMON_CACHEDIR="$TERMUX_TOPDIR/_cache" |
| 285 | TERMUX_DEBDIR="$TERMUX_SCRIPTDIR/debs" |
| 286 | TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner |
| 287 | |
| 288 | export prefix=${TERMUX_PREFIX} |
| 289 | export PREFIX=${TERMUX_PREFIX} |
| 290 | |
| 291 | TERMUX_PKG_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/build |
| 292 | TERMUX_PKG_CACHEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/cache |
| 293 | TERMUX_PKG_MASSAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/massage |
| 294 | TERMUX_PKG_PACKAGEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/package |
| 295 | TERMUX_PKG_SRCDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/src |
| 296 | TERMUX_PKG_SHA256="" |
| 297 | TERMUX_PKG_TMPDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/tmp |
| 298 | TERMUX_PKG_HOSTBUILD_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/host-build |
| 299 | TERMUX_PKG_PLATFORM_INDEPENDENT="" |
| 300 | TERMUX_PKG_NO_DEVELSPLIT="" |
| 301 | TERMUX_PKG_REVISION="0" # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version |
| 302 | TERMUX_PKG_EXTRA_CONFIGURE_ARGS="" |
| 303 | TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS="" |
| 304 | TERMUX_PKG_EXTRA_MAKE_ARGS="" |
| 305 | TERMUX_PKG_BUILD_IN_SRC="" |
| 306 | TERMUX_PKG_RM_AFTER_INSTALL="" |
| 307 | TERMUX_PKG_BREAKS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps |
| 308 | TERMUX_PKG_DEPENDS="" |
| 309 | TERMUX_PKG_BUILD_DEPENDS="" |
| 310 | TERMUX_PKG_HOMEPAGE="" |
| 311 | TERMUX_PKG_DESCRIPTION="FIXME:Add description" |
| 312 | TERMUX_PKG_KEEP_STATIC_LIBRARIES="false" |
| 313 | TERMUX_PKG_ESSENTIAL="" |
| 314 | TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts |
| 315 | TERMUX_PKG_RECOMMENDS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps |
| 316 | TERMUX_PKG_REPLACES="" |
| 317 | TERMUX_PKG_CONFFILES="" |
| 318 | TERMUX_PKG_INCLUDE_IN_DEVPACKAGE="" |
| 319 | TERMUX_PKG_DEVPACKAGE_DEPENDS="" |
| 320 | # Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR: |
| 321 | TERMUX_PKG_HOSTBUILD="" |
| 322 | TERMUX_PKG_MAINTAINER="Fredrik Fornwall @fornwall" |
| 323 | TERMUX_PKG_CLANG=yes # does nothing for cmake based packages. clang is chosen by cmake |
| 324 | TERMUX_PKG_FORCE_CMAKE=no # if the package has autotools as well as cmake, then set this to prefer cmake |
| 325 | |
| 326 | unset CFLAGS CPPFLAGS LDFLAGS CXXFLAGS |
| 327 | } |
| 328 | |
| 329 | # Save away and restore build setups which may change between builds. |
| 330 | termux_step_handle_buildarch() { |
| 331 | # If $TERMUX_PREFIX already exists, it may have been built for a different arch |
| 332 | local TERMUX_ARCH_FILE=/data/TERMUX_ARCH |
| 333 | if [ -f "${TERMUX_ARCH_FILE}" ]; then |
| 334 | local TERMUX_PREVIOUS_ARCH |
| 335 | TERMUX_PREVIOUS_ARCH=$(cat $TERMUX_ARCH_FILE) |
| 336 | if [ "$TERMUX_PREVIOUS_ARCH" != "$TERMUX_ARCH" ]; then |
| 337 | local TERMUX_DATA_BACKUPDIRS=$TERMUX_TOPDIR/_databackups |
| 338 | mkdir -p "$TERMUX_DATA_BACKUPDIRS" |
| 339 | local TERMUX_DATA_PREVIOUS_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_PREVIOUS_ARCH |
| 340 | local TERMUX_DATA_CURRENT_BACKUPDIR=$TERMUX_DATA_BACKUPDIRS/$TERMUX_ARCH |
| 341 | # Save current /data (removing old backup if any) |
| 342 | if test -e "$TERMUX_DATA_PREVIOUS_BACKUPDIR"; then |
| 343 | termux_error_exit "Directory already exists" |
| 344 | fi |
| 345 | if [ -d /data/data ]; then |
| 346 | mv /data/data "$TERMUX_DATA_PREVIOUS_BACKUPDIR" |
| 347 | fi |
| 348 | # Restore new one (if any) |
| 349 | if [ -d "$TERMUX_DATA_CURRENT_BACKUPDIR" ]; then |
| 350 | mv "$TERMUX_DATA_CURRENT_BACKUPDIR" /data/data |
| 351 | fi |
| 352 | fi |
| 353 | fi |
| 354 | |
| 355 | # Keep track of current arch we are building for. |
| 356 | echo "$TERMUX_ARCH" > $TERMUX_ARCH_FILE |
| 357 | } |
| 358 | |
| 359 | # Source the package build script and start building. No to be overridden by packages. |
| 360 | termux_step_start_build() { |
| 361 | # shellcheck source=/dev/null |
| 362 | source "$TERMUX_PKG_BUILDER_SCRIPT" |
| 363 | |
| 364 | TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/${TERMUX_NDK_VERSION}-${TERMUX_ARCH}-${TERMUX_PKG_API_LEVEL}" |
| 365 | # Bump the below version if a change is made in toolchain setup to ensure |
| 366 | # that everyone gets an updated toolchain: |
| 367 | TERMUX_STANDALONE_TOOLCHAIN+="-v2" |
| 368 | |
| 369 | if [ -n "${TERMUX_PKG_BLACKLISTED_ARCHES:=""}" ] && [ "$TERMUX_PKG_BLACKLISTED_ARCHES" != "${TERMUX_PKG_BLACKLISTED_ARCHES/$TERMUX_ARCH/}" ]; then |
| 370 | echo "Skipping building $TERMUX_PKG_NAME for arch $TERMUX_ARCH" |
| 371 | exit 0 |
| 372 | fi |
| 373 | |
| 374 | if [ -z "${TERMUX_SKIP_DEPCHECK:=""}" ]; then |
| 375 | local p TERMUX_ALL_DEPS |
| 376 | TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_BUILDER_DIR") |
| 377 | for p in $TERMUX_ALL_DEPS; do |
| 378 | echo "Building dependency $p if necessary..." |
| 379 | ./build-package.sh -a $TERMUX_ARCH -s "$p" |
| 380 | done |
| 381 | fi |
| 382 | |
| 383 | TERMUX_PKG_FULLVERSION=$TERMUX_PKG_VERSION |
| 384 | if [ "$TERMUX_PKG_REVISION" != "0" ] || [ "$TERMUX_PKG_FULLVERSION" != "${TERMUX_PKG_FULLVERSION/-/}" ]; then |
| 385 | # "0" is the default revision, so only include it if the upstream versions contains "-" itself |
| 386 | TERMUX_PKG_FULLVERSION+="-$TERMUX_PKG_REVISION" |
| 387 | fi |
| 388 | |
| 389 | if [ -z "$TERMUX_DEBUG" ] && |
| 390 | [ -z "${TERMUX_FORCE_BUILD+x}" ] && |
| 391 | [ -e "/data/data/.built-packages/$TERMUX_PKG_NAME" ]; then |
| 392 | if [ "$(cat "/data/data/.built-packages/$TERMUX_PKG_NAME")" = "$TERMUX_PKG_FULLVERSION" ]; then |
| 393 | echo "$TERMUX_PKG_NAME@$TERMUX_PKG_FULLVERSION built - skipping (rm /data/data/.built-packages/$TERMUX_PKG_NAME to force rebuild)" |
| 394 | exit 0 |
| 395 | fi |
| 396 | fi |
| 397 | |
| 398 | # Cleanup old state: |
| 399 | rm -Rf "$TERMUX_PKG_BUILDDIR" \ |
| 400 | "$TERMUX_PKG_PACKAGEDIR" \ |
| 401 | "$TERMUX_PKG_SRCDIR" \ |
| 402 | "$TERMUX_PKG_TMPDIR" \ |
| 403 | "$TERMUX_PKG_MASSAGEDIR" |
| 404 | |
| 405 | # Ensure folders present (but not $TERMUX_PKG_SRCDIR, it will be created in build) |
| 406 | mkdir -p "$TERMUX_COMMON_CACHEDIR" \ |
| 407 | "$TERMUX_DEBDIR" \ |
| 408 | "$TERMUX_PKG_BUILDDIR" \ |
| 409 | "$TERMUX_PKG_PACKAGEDIR" \ |
| 410 | "$TERMUX_PKG_TMPDIR" \ |
| 411 | "$TERMUX_PKG_CACHEDIR" \ |
| 412 | "$TERMUX_PKG_MASSAGEDIR" \ |
| 413 | $TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp,include} |
| 414 | |
| 415 | # Make $TERMUX_PREFIX/bin/sh executable on the builder, so that build |
| 416 | # scripts can assume that it works on both builder and host later on: |
| 417 | ln -f -s /bin/sh "$TERMUX_PREFIX/bin/sh" |
| 418 | |
| 419 | local TERMUX_ELF_CLEANER_SRC=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner.cpp |
| 420 | local TERMUX_ELF_CLEANER_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/build.sh; echo \$TERMUX_PKG_VERSION") |
| 421 | termux_download \ |
| 422 | https://raw.githubusercontent.com/termux/termux-elf-cleaner/v$TERMUX_ELF_CLEANER_VERSION/termux-elf-cleaner.cpp \ |
| 423 | $TERMUX_ELF_CLEANER_SRC \ |
| 424 | 62c3cf9813756a1b262108fbc39684c5cfd3f9a69b376276bb1ac6af138f5fa2 |
| 425 | if [ "$TERMUX_ELF_CLEANER_SRC" -nt "$TERMUX_ELF_CLEANER" ]; then |
| 426 | g++ -std=c++11 -Wall -Wextra -pedantic -Os "$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER" |
| 427 | fi |
| 428 | |
| 429 | if [ -n "$TERMUX_PKG_BUILD_IN_SRC" ]; then |
| 430 | echo "Building in src due to TERMUX_PKG_BUILD_IN_SRC being set" > "$TERMUX_PKG_BUILDDIR/BUILDING_IN_SRC.txt" |
| 431 | TERMUX_PKG_BUILDDIR=$TERMUX_PKG_SRCDIR |
| 432 | fi |
| 433 | |
| 434 | echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..." |
| 435 | test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME" |
| 436 | |
| 437 | # Avoid exporting PKG_CONFIG_LIBDIR until after termux_step_host_build. |
| 438 | export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig |
| 439 | # Add a pkg-config file for the system zlib. |
| 440 | mkdir -p "$TERMUX_PKG_CONFIG_LIBDIR" |
| 441 | cat > "$TERMUX_PKG_CONFIG_LIBDIR/zlib.pc" <<-HERE |
| 442 | Name: zlib |
| 443 | Description: zlib compression library |
| 444 | Version: 1.2.8 |
| 445 | Requires: |
| 446 | Libs: -lz |
| 447 | HERE |
| 448 | |
| 449 | # Keep track of when build started so we can see what files have been created. |
| 450 | # We start by sleeping so that any generated files above (such as zlib.pc) get |
| 451 | # an older timestamp than the TERMUX_BUILD_TS_FILE. |
| 452 | sleep 1 |
| 453 | TERMUX_BUILD_TS_FILE=$TERMUX_PKG_TMPDIR/timestamp_$TERMUX_PKG_NAME |
| 454 | touch "$TERMUX_BUILD_TS_FILE" |
| 455 | } |
| 456 | |
| 457 | # Run just after sourcing $TERMUX_PKG_BUILDER_SCRIPT. May be overridden by packages. |
| 458 | termux_step_extract_package() { |
| 459 | if [ -z "${TERMUX_PKG_SRCURL:=""}" ]; then |
| 460 | mkdir -p "$TERMUX_PKG_SRCDIR" |
| 461 | return |
| 462 | fi |
| 463 | cd "$TERMUX_PKG_TMPDIR" |
| 464 | local filename |
| 465 | filename=$(basename "$TERMUX_PKG_SRCURL") |
| 466 | local file="$TERMUX_PKG_CACHEDIR/$filename" |
| 467 | termux_download "$TERMUX_PKG_SRCURL" "$file" "$TERMUX_PKG_SHA256" |
| 468 | |
| 469 | local folder |
| 470 | set +o pipefail |
| 471 | if [ "${file##*.}" = zip ]; then |
| 472 | folder=`unzip -qql "$file" | head -n1 | tr -s ' ' | cut -d' ' -f5-` |
| 473 | rm -Rf $folder |
| 474 | unzip -q "$file" |
| 475 | mv $folder "$TERMUX_PKG_SRCDIR" |
| 476 | else |
| 477 | mkdir "$TERMUX_PKG_SRCDIR" |
| 478 | tar xf "$file" -C "$TERMUX_PKG_SRCDIR" --strip-components=1 |
| 479 | fi |
| 480 | set -o pipefail |
| 481 | } |
| 482 | |
| 483 | # Hook for packages to act just after the package has been extracted. |
| 484 | # Invoked in $TERMUX_PKG_SRCDIR. |
| 485 | termux_step_post_extract_package() { |
| 486 | return |
| 487 | } |
| 488 | |
| 489 | # Optional host build. Not to be overridden by packages. |
| 490 | termux_step_handle_hostbuild() { |
| 491 | if [ "x$TERMUX_PKG_HOSTBUILD" = "x" ]; then return; fi |
| 492 | |
| 493 | cd "$TERMUX_PKG_SRCDIR" |
| 494 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch.beforehostbuild; do |
| 495 | test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | patch --silent -p1 |
| 496 | done |
| 497 | |
| 498 | local TERMUX_HOSTBUILD_MARKER="$TERMUX_PKG_HOSTBUILD_DIR/TERMUX_BUILT_FOR_$TERMUX_PKG_VERSION" |
| 499 | if [ ! -f "$TERMUX_HOSTBUILD_MARKER" ]; then |
| 500 | rm -Rf "$TERMUX_PKG_HOSTBUILD_DIR" |
| 501 | mkdir -p "$TERMUX_PKG_HOSTBUILD_DIR" |
| 502 | cd "$TERMUX_PKG_HOSTBUILD_DIR" |
| 503 | termux_step_host_build |
| 504 | touch "$TERMUX_HOSTBUILD_MARKER" |
| 505 | fi |
| 506 | } |
| 507 | |
| 508 | # Perform a host build. Will be called in $TERMUX_PKG_HOSTBUILD_DIR. |
| 509 | # After termux_step_post_extract_package() and before termux_step_patch_package() |
| 510 | termux_step_host_build() { |
| 511 | "$TERMUX_PKG_SRCDIR/configure" ${TERMUX_PKG_EXTRA_HOSTBUILD_CONFIGURE_ARGS} |
| 512 | make -j $TERMUX_MAKE_PROCESSES |
| 513 | } |
| 514 | |
| 515 | # Setup a standalone Android NDK toolchain. Not to be overridden by packages. |
| 516 | termux_step_setup_toolchain() { |
| 517 | # We put this after system PATH to avoid picking up toolchain stripped python |
| 518 | export PATH=$PATH:$TERMUX_STANDALONE_TOOLCHAIN/bin |
| 519 | |
| 520 | export CFLAGS="" |
| 521 | export LDFLAGS="-L${TERMUX_PREFIX}/lib" |
| 522 | |
| 523 | if [ "$TERMUX_PKG_CLANG" = "no" ]; then |
| 524 | export AS=${TERMUX_HOST_PLATFORM}-gcc |
| 525 | export CC=$TERMUX_HOST_PLATFORM-gcc |
| 526 | export CXX=$TERMUX_HOST_PLATFORM-g++ |
| 527 | LDFLAGS+=" -specs=$TERMUX_SCRIPTDIR/termux.spec" |
| 528 | CFLAGS+=" -specs=$TERMUX_SCRIPTDIR/termux.spec" |
| 529 | else |
| 530 | export AS=${TERMUX_HOST_PLATFORM}-clang |
| 531 | export CC=$TERMUX_HOST_PLATFORM-clang |
| 532 | export CXX=$TERMUX_HOST_PLATFORM-clang++ |
| 533 | fi |
| 534 | |
| 535 | export AR=$TERMUX_HOST_PLATFORM-ar |
| 536 | export CPP=${TERMUX_HOST_PLATFORM}-cpp |
| 537 | export CC_FOR_BUILD=gcc |
| 538 | export LD=$TERMUX_HOST_PLATFORM-ld |
| 539 | export OBJDUMP=$TERMUX_HOST_PLATFORM-objdump |
| 540 | # Setup pkg-config for cross-compiling: |
| 541 | export PKG_CONFIG=$TERMUX_STANDALONE_TOOLCHAIN/bin/${TERMUX_HOST_PLATFORM}-pkg-config |
| 542 | export RANLIB=$TERMUX_HOST_PLATFORM-ranlib |
| 543 | export READELF=$TERMUX_HOST_PLATFORM-readelf |
| 544 | export STRIP=$TERMUX_HOST_PLATFORM-strip |
| 545 | |
| 546 | # Android 7 started to support DT_RUNPATH (but not DT_RPATH), so we may want |
| 547 | # LDFLAGS+="-Wl,-rpath=$TERMUX_PREFIX/lib -Wl,--enable-new-dtags" |
| 548 | # and no longer remove DT_RUNPATH in termux-elf-cleaner. |
| 549 | |
| 550 | if [ "$TERMUX_ARCH" = "arm" ]; then |
| 551 | # https://developer.android.com/ndk/guides/standalone_toolchain.html#abi_compatibility: |
| 552 | # "We recommend using the -mthumb compiler flag to force the generation of 16-bit Thumb-2 instructions". |
| 553 | # With r13 of the ndk ruby 2.4.0 segfaults when built on arm with clang without -mthumb. |
| 554 | CFLAGS+=" -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb" |
| 555 | LDFLAGS+=" -march=armv7-a" |
| 556 | elif [ "$TERMUX_ARCH" = "i686" ]; then |
| 557 | # From $NDK/docs/CPU-ARCH-ABIS.html: |
| 558 | CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse" |
| 559 | elif [ "$TERMUX_ARCH" = "aarch64" ]; then |
| 560 | : |
| 561 | elif [ "$TERMUX_ARCH" = "x86_64" ]; then |
| 562 | : |
| 563 | else |
| 564 | termux_error_exit "Invalid arch '$TERMUX_ARCH' - support arches are 'arm', 'i686', 'aarch64', 'x86_64'" |
| 565 | fi |
| 566 | |
| 567 | if [ -n "$TERMUX_DEBUG" ]; then |
| 568 | CFLAGS+=" -g3 -O1 -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2" |
| 569 | else |
| 570 | if [ "$TERMUX_PKG_CLANG" = "no" ]; then |
| 571 | CFLAGS+=" -Os" |
| 572 | else |
| 573 | if [ "$TERMUX_PKG_NAME" = "ruby" -a "$TERMUX_ARCH" = arm ]; then |
| 574 | # This exception is to avoid a broken ruby on 32-bit arm |
| 575 | # with NDK r15c and ruby 2.4.2 - see #1520. |
| 576 | CFLAGS+=" -O1" |
| 577 | else |
| 578 | # -Oz seems good for clang, see https://github.com/android-ndk/ndk/issues/133 |
| 579 | CFLAGS+=" -Oz" |
| 580 | fi |
| 581 | fi |
| 582 | fi |
| 583 | |
| 584 | export CXXFLAGS="$CFLAGS" |
| 585 | export CPPFLAGS="-I${TERMUX_PREFIX}/include" |
| 586 | |
| 587 | if [ "$TERMUX_PKG_DEPENDS" != "${TERMUX_PKG_DEPENDS/libandroid-support/}" ]; then |
| 588 | # If using the android support library, link to it and include its headers as system headers: |
| 589 | CPPFLAGS+=" -isystem $TERMUX_PREFIX/include/libandroid-support" |
| 590 | LDFLAGS+=" -landroid-support" |
| 591 | fi |
| 592 | |
| 593 | export ac_cv_func_getpwent=no |
| 594 | export ac_cv_func_getpwnam=no |
| 595 | export ac_cv_func_getpwuid=no |
| 596 | export ac_cv_func_sigsetmask=no |
| 597 | |
| 598 | if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then |
| 599 | # Do not put toolchain in place until we are done with setup, to avoid having a half setup |
| 600 | # toolchain left in place if something goes wrong (or process is just aborted): |
| 601 | local _TERMUX_TOOLCHAIN_TMPDIR=${TERMUX_STANDALONE_TOOLCHAIN}-tmp |
| 602 | rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR |
| 603 | |
| 604 | local _NDK_ARCHNAME=$TERMUX_ARCH |
| 605 | if [ "$TERMUX_ARCH" = "aarch64" ]; then |
| 606 | _NDK_ARCHNAME=arm64 |
| 607 | elif [ "$TERMUX_ARCH" = "i686" ]; then |
| 608 | _NDK_ARCHNAME=x86 |
| 609 | fi |
| 610 | |
| 611 | "$NDK/build/tools/make_standalone_toolchain.py" \ |
| 612 | --api "$TERMUX_PKG_API_LEVEL" \ |
| 613 | --arch $_NDK_ARCHNAME \ |
| 614 | --stl=libc++ \ |
| 615 | --install-dir $_TERMUX_TOOLCHAIN_TMPDIR |
| 616 | |
| 617 | # Remove android-support header wrapping not needed on android-21: |
| 618 | rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/local |
| 619 | |
| 620 | local wrapped plusplus CLANG_TARGET=$TERMUX_HOST_PLATFORM |
| 621 | if [ $TERMUX_ARCH = arm ]; then CLANG_TARGET=${CLANG_TARGET/arm-/armv7a-}; fi |
| 622 | for wrapped in ${TERMUX_HOST_PLATFORM}-clang clang; do |
| 623 | for plusplus in "" "++"; do |
| 624 | local FILE_TO_REPLACE=$_TERMUX_TOOLCHAIN_TMPDIR/bin/${wrapped}${plusplus} |
| 625 | if [ ! -f $FILE_TO_REPLACE ]; then |
| 626 | termux_error_exit "No toolchain file to override: $FILE_TO_REPLACE" |
| 627 | fi |
| 628 | cp "$TERMUX_SCRIPTDIR/scripts/clang-pie-wrapper" $FILE_TO_REPLACE |
| 629 | sed -i "s/COMPILER/clang50$plusplus/" $FILE_TO_REPLACE |
| 630 | sed -i "s/CLANG_TARGET/$CLANG_TARGET/" $FILE_TO_REPLACE |
| 631 | done |
| 632 | done |
| 633 | |
| 634 | if [ "$TERMUX_ARCH" = "aarch64" ]; then |
| 635 | # Use gold by default to work around https://github.com/android-ndk/ndk/issues/148 |
| 636 | cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld.gold \ |
| 637 | $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld |
| 638 | cp $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld.gold \ |
| 639 | $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld |
| 640 | fi |
| 641 | |
| 642 | if [ "$TERMUX_ARCH" = "arm" ]; then |
| 643 | # Linker wrapper script to add '--exclude-libs libgcc.a', see |
| 644 | # https://github.com/android-ndk/ndk/issues/379 |
| 645 | # https://android-review.googlesource.com/#/c/389852/ |
| 646 | local linker |
| 647 | for linker in ld ld.bfd ld.gold; do |
| 648 | local wrap_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker |
| 649 | local real_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker.real |
| 650 | cp $wrap_linker $real_linker |
| 651 | echo '#!/bin/bash' > $wrap_linker |
| 652 | echo -n '`dirname $0`/' >> $wrap_linker |
| 653 | echo -n $linker.real >> $wrap_linker |
| 654 | echo ' --exclude-libs libgcc.a "$@"' >> $wrap_linker |
| 655 | done |
| 656 | fi |
| 657 | |
| 658 | cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot |
| 659 | |
| 660 | for f in $TERMUX_SCRIPTDIR/ndk-patches/*.patch; do |
| 661 | sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$f" | \ |
| 662 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ |
| 663 | patch --silent -p1; |
| 664 | done |
| 665 | # elf.h: Taken from glibc since the elf.h in the NDK is lacking. |
| 666 | # sysexits.h: Header-only and used by a few programs. |
| 667 | # ifaddrs.h: Added in android-24 unified headers, use a inline implementation for now. |
| 668 | cp "$TERMUX_SCRIPTDIR"/ndk-patches/{elf.h,sysexits.h,ifaddrs.h,libintl.h} usr/include |
| 669 | |
| 670 | # Remove <sys/shm.h> from the NDK in favour of that from the libandroid-shmem. |
| 671 | # Remove <sys/sem.h> as it doesn't work for non-root. |
| 672 | # Remove <iconv.h> as we currently provide it from libandroid-support. |
| 673 | # Remove <glob.h> as we currently provide it from libandroid-glob. |
| 674 | # Remove <spawn.h> as it's only for future (later than android-27). |
| 675 | rm usr/include/sys/{shm.h,sem.h} usr/include/{iconv.h,glob.h,spawn.h} |
| 676 | |
| 677 | sed -i "s/define __ANDROID_API__ __ANDROID_API_FUTURE__/define __ANDROID_API__ $TERMUX_PKG_API_LEVEL/" \ |
| 678 | usr/include/android/api-level.h |
| 679 | |
| 680 | local _LIBDIR=usr/lib |
| 681 | if [ $TERMUX_ARCH = x86_64 ]; then _LIBDIR+=64; fi |
| 682 | $TERMUX_ELF_CLEANER $_LIBDIR/*.so |
| 683 | |
| 684 | # zlib is really version 1.2.8 in the Android platform (at least |
| 685 | # starting from Android 5), not older as the NDK headers claim. |
| 686 | for file in zconf.h zlib.h; do |
| 687 | curl -o usr/include/$file \ |
| 688 | https://raw.githubusercontent.com/madler/zlib/v1.2.8/$file |
| 689 | done |
| 690 | unset file |
| 691 | cd $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x |
| 692 | sed "s%\@TERMUX_HOST_PLATFORM\@%${TERMUX_HOST_PLATFORM}%g" $TERMUX_SCRIPTDIR/ndk-patches/*.cpppatch | patch -p1 |
| 693 | mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN |
| 694 | fi |
| 695 | |
| 696 | local _STL_LIBFILE_NAME=libc++_shared.so |
| 697 | if [ ! -f $TERMUX_PREFIX/lib/libstdc++.so ]; then |
| 698 | # Setup libgnustl_shared.so in $PREFIX/lib and libstdc++.so as a link to it, |
| 699 | # so that other C++ using packages links to it instead of the default android |
| 700 | # C++ library which does not support exceptions or STL: |
| 701 | # https://developer.android.com/ndk/guides/cpp-support.html |
| 702 | # We do however want to avoid installing this, to avoid problems where e.g. |
| 703 | # libm.so on some i686 devices links against libstdc++.so. |
| 704 | # The libgnustl_shared.so library will be packaged in the libgnustl package |
| 705 | # which is part of the base Termux installation. |
| 706 | mkdir -p "$TERMUX_PREFIX/lib" |
| 707 | cd "$TERMUX_PREFIX/lib" |
| 708 | |
| 709 | local _STL_LIBFILE= |
| 710 | if [ "$TERMUX_ARCH" = arm ]; then |
| 711 | local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/armv7-a/$_STL_LIBFILE_NAME |
| 712 | elif [ "$TERMUX_ARCH" = x86_64 ]; then |
| 713 | local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/$_STL_LIBFILE_NAME |
| 714 | else |
| 715 | local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/$_STL_LIBFILE_NAME |
| 716 | fi |
| 717 | |
| 718 | cp "$_STL_LIBFILE" . |
| 719 | $STRIP --strip-unneeded $_STL_LIBFILE_NAME |
| 720 | $TERMUX_ELF_CLEANER $_STL_LIBFILE_NAME |
| 721 | if [ $TERMUX_ARCH = "arm" ]; then |
| 722 | # Use a linker script to get libunwind.a. |
| 723 | echo 'INPUT(-lunwind -lc++_shared)' > libstdc++.so |
| 724 | else |
| 725 | ln -f $_STL_LIBFILE_NAME libstdc++.so |
| 726 | fi |
| 727 | fi |
| 728 | |
| 729 | export PKG_CONFIG_LIBDIR="$TERMUX_PKG_CONFIG_LIBDIR" |
| 730 | # Create a pkg-config wrapper. We use path to host pkg-config to |
| 731 | # avoid picking up a cross-compiled pkg-config later on. |
| 732 | local _HOST_PKGCONFIG |
| 733 | _HOST_PKGCONFIG=$(which pkg-config) |
| 734 | mkdir -p $TERMUX_STANDALONE_TOOLCHAIN/bin "$PKG_CONFIG_LIBDIR" |
| 735 | cat > "$PKG_CONFIG" <<-HERE |
| 736 | #!/bin/sh |
| 737 | export PKG_CONFIG_DIR= |
| 738 | export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR |
| 739 | exec $_HOST_PKGCONFIG "\$@" |
| 740 | HERE |
| 741 | chmod +x "$PKG_CONFIG" |
| 742 | } |
| 743 | |
| 744 | # Apply all *.patch files for the package. Not to be overridden by packages. |
| 745 | termux_step_patch_package() { |
| 746 | cd "$TERMUX_PKG_SRCDIR" |
| 747 | # Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses: |
| 748 | shopt -s nullglob |
| 749 | for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,}; do |
| 750 | test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | \ |
| 751 | sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ |
| 752 | patch --silent -p1 |
| 753 | done |
| 754 | shopt -u nullglob |
| 755 | } |
| 756 | |
| 757 | # Replace autotools build-aux/config.{sub,guess} with ours to add android targets. |
| 758 | termux_step_replace_guess_scripts () { |
| 759 | cd "$TERMUX_PKG_SRCDIR" |
| 760 | find . -name config.sub -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.sub" '{}' \; |
| 761 | find . -name config.guess -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.guess" '{}' \; |
| 762 | } |
| 763 | |
| 764 | # For package scripts to override. Called in $TERMUX_PKG_BUILDDIR. |
| 765 | termux_step_pre_configure() { |
| 766 | return |
| 767 | } |
| 768 | |
| 769 | termux_step_configure_autotools () { |
| 770 | if [ ! -e "$TERMUX_PKG_SRCDIR/configure" ]; then return; fi |
| 771 | |
| 772 | DISABLE_STATIC="--disable-static" |
| 773 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-static/}" ]; then |
| 774 | # Do not --disable-static if package explicitly enables it (e.g. gdb needs enable-static to build) |
| 775 | DISABLE_STATIC="" |
| 776 | fi |
| 777 | |
| 778 | DISABLE_NLS="--disable-nls" |
| 779 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-nls/}" ]; then |
| 780 | # Do not --disable-nls if package explicitly enables it (for gettext itself) |
| 781 | DISABLE_NLS="" |
| 782 | fi |
| 783 | |
| 784 | ENABLE_SHARED="--enable-shared" |
| 785 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--disable-shared/}" ]; then |
| 786 | ENABLE_SHARED="" |
| 787 | fi |
| 788 | HOST_FLAG="--host=$TERMUX_HOST_PLATFORM" |
| 789 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--host=/}" ]; then |
| 790 | HOST_FLAG="" |
| 791 | fi |
| 792 | LIBEXEC_FLAG="--libexecdir=$TERMUX_PREFIX/libexec" |
| 793 | if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--libexecdir=/}" ]; then |
| 794 | LIBEXEC_FLAG="" |
| 795 | fi |
| 796 | QUIET_BUILD= |
| 797 | if [ ! -z ${TERMUX_QUIET_BUILD+x} ]; then |
| 798 | QUIET_BUILD="--enable-silent-rules" |
| 799 | fi |
| 800 | |
| 801 | # Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config: |
| 802 | mkdir "$TERMUX_PKG_TMPDIR/config-scripts" |
| 803 | for f in $TERMUX_PREFIX/bin/*config; do |
| 804 | test -f "$f" && cp "$f" "$TERMUX_PKG_TMPDIR/config-scripts" |
| 805 | done |
| 806 | export PATH=$TERMUX_PKG_TMPDIR/config-scripts:$PATH |
| 807 | |
| 808 | # Avoid gnulib wrapping of functions when cross compiling. See |
| 809 | # http://wiki.osdev.org/Cross-Porting_Software#Gnulib |
| 810 | # https://gitlab.com/sortix/sortix/wikis/Gnulib |
| 811 | # https://github.com/termux/termux-packages/issues/76 |
| 812 | local AVOID_GNULIB="" |
| 813 | AVOID_GNULIB+=" ac_cv_func_calloc_0_nonnull=yes" |
| 814 | AVOID_GNULIB+=" ac_cv_func_chown_works=yes" |
| 815 | AVOID_GNULIB+=" ac_cv_func_getgroups_works=yes" |
| 816 | AVOID_GNULIB+=" ac_cv_func_malloc_0_nonnull=yes" |
| 817 | AVOID_GNULIB+=" ac_cv_func_realloc_0_nonnull=yes" |
| 818 | AVOID_GNULIB+=" am_cv_func_working_getline=yes" |
| 819 | AVOID_GNULIB+=" gl_cv_func_dup2_works=yes" |
| 820 | AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_cloexec=yes" |
| 821 | AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_works=yes" |
| 822 | AVOID_GNULIB+=" gl_cv_func_fnmatch_posix=yes" |
| 823 | AVOID_GNULIB+=" gl_cv_func_getcwd_abort_bug=no" |
| 824 | AVOID_GNULIB+=" gl_cv_func_getcwd_null=yes" |
| 825 | AVOID_GNULIB+=" gl_cv_func_getcwd_path_max=yes" |
| 826 | AVOID_GNULIB+=" gl_cv_func_getcwd_posix_signature=yes" |
| 827 | AVOID_GNULIB+=" gl_cv_func_gettimeofday_clobber=no" |
| 828 | AVOID_GNULIB+=" gl_cv_func_gettimeofday_posix_signature=yes" |
| 829 | AVOID_GNULIB+=" gl_cv_func_link_works=yes" |
| 830 | AVOID_GNULIB+=" gl_cv_func_lstat_dereferences_slashed_symlink=yes" |
| 831 | AVOID_GNULIB+=" gl_cv_func_malloc_0_nonnull=yes" |
| 832 | AVOID_GNULIB+=" gl_cv_func_memchr_works=yes" |
| 833 | AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_dot_works=yes" |
| 834 | AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_slash_works=yes" |
| 835 | AVOID_GNULIB+=" gl_cv_func_mkfifo_works=yes" |
| 836 | AVOID_GNULIB+=" gl_cv_func_realpath_works=yes" |
| 837 | AVOID_GNULIB+=" gl_cv_func_select_detects_ebadf=yes" |
| 838 | AVOID_GNULIB+=" gl_cv_func_snprintf_posix=yes" |
| 839 | AVOID_GNULIB+=" gl_cv_func_snprintf_retval_c99=yes" |
| 840 | AVOID_GNULIB+=" gl_cv_func_snprintf_truncation_c99=yes" |
| 841 | AVOID_GNULIB+=" gl_cv_func_stat_dir_slash=yes" |
| 842 | AVOID_GNULIB+=" gl_cv_func_stat_file_slash=yes" |
| 843 | AVOID_GNULIB+=" gl_cv_func_strerror_0_works=yes" |
| 844 | AVOID_GNULIB+=" gl_cv_func_symlink_works=yes" |
| 845 | AVOID_GNULIB+=" gl_cv_func_tzset_clobber=no" |
| 846 | AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes" |
| 847 | AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes" |
| 848 | AVOID_GNULIB+=" gl_cv_func_vsnprintf_posix=yes" |
| 849 | AVOID_GNULIB+=" gl_cv_func_vsnprintf_zerosize_c99=yes" |
| 850 | AVOID_GNULIB+=" gl_cv_func_wcwidth_works=yes" |
| 851 | AVOID_GNULIB+=" gl_cv_func_working_getdelim=yes" |
| 852 | AVOID_GNULIB+=" gl_cv_func_working_mkstemp=yes" |
| 853 | AVOID_GNULIB+=" gl_cv_func_working_mktime=yes" |
| 854 | AVOID_GNULIB+=" gl_cv_func_working_strerror=yes" |
| 855 | AVOID_GNULIB+=" gl_cv_header_working_fcntl_h=yes" |
| 856 | AVOID_GNULIB+=" gl_cv_C_locale_sans_EILSEQ=yes" |
| 857 | |
| 858 | # NOTE: We do not want to quote AVOID_GNULIB as we want word expansion. |
| 859 | env $AVOID_GNULIB "$TERMUX_PKG_SRCDIR/configure" \ |
| 860 | --disable-dependency-tracking \ |
| 861 | --prefix=$TERMUX_PREFIX \ |
| 862 | --disable-rpath --disable-rpath-hack \ |
| 863 | $HOST_FLAG \ |
| 864 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS \ |
| 865 | $DISABLE_NLS \ |
| 866 | $ENABLE_SHARED \ |
| 867 | $DISABLE_STATIC \ |
| 868 | $LIBEXEC_FLAG \ |
| 869 | $QUIET_BUILD |
| 870 | } |
| 871 | |
| 872 | termux_step_configure_cmake () { |
| 873 | termux_setup_cmake |
| 874 | |
| 875 | local TOOLCHAIN_ARGS="-DCMAKE_ANDROID_STANDALONE_TOOLCHAIN=$TERMUX_STANDALONE_TOOLCHAIN" |
| 876 | local BUILD_TYPE=MinSizeRel |
| 877 | test -n "$TERMUX_DEBUG" && BUILD_TYPE=Debug |
| 878 | |
| 879 | local CMAKE_PROC=$TERMUX_ARCH |
| 880 | test $CMAKE_PROC == "arm" && CMAKE_PROC='armv7-a' |
| 881 | |
| 882 | # XXX: CMAKE_{AR,RANLIB} needed for at least jsoncpp build to not |
| 883 | # pick up cross compiled binutils tool in $PREFIX/bin: |
| 884 | cmake -G 'Unix Makefiles' "$TERMUX_PKG_SRCDIR" \ |
| 885 | -DCMAKE_AR="$(which $AR)" \ |
| 886 | -DCMAKE_UNAME="$(which uname)" \ |
| 887 | -DCMAKE_RANLIB="$(which $RANLIB)" \ |
| 888 | -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ |
| 889 | -DCMAKE_CROSSCOMPILING=True \ |
| 890 | -DCMAKE_C_FLAGS="$CFLAGS $CPPFLAGS" \ |
| 891 | -DCMAKE_CXX_FLAGS="$CXXFLAGS $CPPFLAGS" \ |
| 892 | -DCMAKE_LINKER="$TERMUX_STANDALONE_TOOLCHAIN/bin/$LD $LDFLAGS" \ |
| 893 | -DCMAKE_FIND_ROOT_PATH=$TERMUX_PREFIX \ |
| 894 | -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ |
| 895 | -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \ |
| 896 | -DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX \ |
| 897 | -DCMAKE_MAKE_PROGRAM=`which make` \ |
| 898 | -DCMAKE_SYSTEM_PROCESSOR=$CMAKE_PROC \ |
| 899 | -DCMAKE_SYSTEM_NAME=Android \ |
| 900 | -DCMAKE_SYSTEM_VERSION=21 \ |
| 901 | -DCMAKE_SKIP_INSTALL_RPATH=ON \ |
| 902 | -DCMAKE_USE_SYSTEM_LIBRARIES=True \ |
| 903 | -DBUILD_TESTING=OFF \ |
| 904 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS $TOOLCHAIN_ARGS |
| 905 | } |
| 906 | |
| 907 | termux_step_configure_meson () { |
| 908 | termux_setup_meson |
| 909 | CC=gcc CXX=g++ $TERMUX_MESON \ |
| 910 | $TERMUX_PKG_SRCDIR \ |
| 911 | $TERMUX_PKG_BUILDDIR \ |
| 912 | --cross-file $TERMUX_MESON_CROSSFILE \ |
| 913 | --prefix $TERMUX_PREFIX \ |
| 914 | --libdir lib \ |
| 915 | --buildtype minsize \ |
| 916 | --strip \ |
| 917 | $TERMUX_PKG_EXTRA_CONFIGURE_ARGS |
| 918 | } |
| 919 | |
| 920 | termux_step_configure () { |
| 921 | if [ "$TERMUX_PKG_FORCE_CMAKE" == 'no' ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then |
| 922 | termux_step_configure_autotools |
| 923 | elif [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then |
| 924 | termux_step_configure_cmake |
| 925 | elif [ -f "$TERMUX_PKG_SRCDIR/meson.build" ]; then |
| 926 | termux_step_configure_meson |
| 927 | fi |
| 928 | } |
| 929 | |
| 930 | termux_step_post_configure () { |
| 931 | return |
| 932 | } |
| 933 | |
| 934 | termux_step_make() { |
| 935 | if ls ./*akefile &> /dev/null; then |
| 936 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then |
| 937 | make -j $TERMUX_MAKE_PROCESSES |
| 938 | else |
| 939 | make -j $TERMUX_MAKE_PROCESSES ${TERMUX_PKG_EXTRA_MAKE_ARGS} |
| 940 | fi |
| 941 | fi |
| 942 | } |
| 943 | |
| 944 | termux_step_make_install() { |
| 945 | if ls ./*akefile &> /dev/null; then |
| 946 | : "${TERMUX_PKG_MAKE_INSTALL_TARGET:="install"}" |
| 947 | # Some packages have problem with parallell install, and it does not buy much, so use -j 1. |
| 948 | if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then |
| 949 | make -j 1 ${TERMUX_PKG_MAKE_INSTALL_TARGET} |
| 950 | else |
| 951 | make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET} |
| 952 | fi |
| 953 | elif test -f build.ninja; then |
| 954 | ninja install |
| 955 | fi |
| 956 | } |
| 957 | |
| 958 | # Hook function for package scripts to override. |
| 959 | termux_step_post_make_install() { |
| 960 | return |
| 961 | } |
| 962 | |
| 963 | termux_step_extract_into_massagedir() { |
| 964 | local TARBALL_ORIG=$TERMUX_PKG_PACKAGEDIR/${TERMUX_PKG_NAME}_orig.tar.gz |
| 965 | |
| 966 | # Build diff tar with what has changed during the build: |
| 967 | cd $TERMUX_PREFIX |
| 968 | tar -N "$TERMUX_BUILD_TS_FILE" \ |
| 969 | --exclude='lib/libc++_shared.so' --exclude='lib/libstdc++.so' \ |
| 970 | -czf "$TARBALL_ORIG" . |
| 971 | |
| 972 | # Extract tar in order to massage it |
| 973 | mkdir -p "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
| 974 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
| 975 | tar xf "$TARBALL_ORIG" |
| 976 | rm "$TARBALL_ORIG" |
| 977 | } |
| 978 | |
| 979 | termux_step_massage() { |
| 980 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
| 981 | |
| 982 | # Remove lib/charset.alias which is installed by gettext-using packages: |
| 983 | rm -f lib/charset.alias |
| 984 | |
| 985 | # Remove non-english man pages: |
| 986 | test -d share/man && (cd share/man; for f in `ls | grep -v man`; do rm -Rf $f; done ) |
| 987 | |
| 988 | if [ -z "${TERMUX_PKG_KEEP_INFOPAGES+x}" ]; then |
| 989 | # Remove info pages: |
| 990 | rm -Rf share/info |
| 991 | fi |
| 992 | |
| 993 | # Remove locale files we're not interested in:: |
| 994 | rm -Rf share/locale |
| 995 | if [ -z "${TERMUX_PKG_KEEP_SHARE_DOC+x}" ]; then |
| 996 | # Remove info pages: |
| 997 | rm -Rf share/doc |
| 998 | fi |
| 999 | |
| 1000 | # Remove old kept libraries (readline): |
| 1001 | find . -name '*.old' -delete |
| 1002 | |
| 1003 | # Remove static libraries: |
| 1004 | if [ $TERMUX_PKG_KEEP_STATIC_LIBRARIES = "false" ]; then |
| 1005 | find . -name '*.a' -delete |
| 1006 | find . -name '*.la' -delete |
| 1007 | fi |
| 1008 | |
| 1009 | # Move over sbin to bin: |
| 1010 | for file in sbin/*; do if test -f "$file"; then mv "$file" bin/; fi; done |
| 1011 | |
| 1012 | # Remove world permissions and add write permissions. |
| 1013 | # The -f flag is used to suppress warnings about dangling symlinks (such |
| 1014 | # as ones to /system/... which may not exist on the build machine): |
| 1015 | find . -exec chmod -f u+w,g-rwx,o-rwx \{\} \; |
| 1016 | |
| 1017 | if [ "$TERMUX_DEBUG" = "" ]; then |
| 1018 | # Strip binaries. file(1) may fail for certain unusual files, so disable pipefail. |
| 1019 | set +e +o pipefail |
| 1020 | find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | \ |
| 1021 | xargs -r "$STRIP" --strip-unneeded --preserve-dates |
| 1022 | set -e -o pipefail |
| 1023 | fi |
| 1024 | # Remove DT_ entries which the android 5.1 linker warns about: |
| 1025 | find . -type f -print0 | xargs -r -0 "$TERMUX_ELF_CLEANER" |
| 1026 | |
| 1027 | # Fix shebang paths: |
| 1028 | while IFS= read -r -d '' file |
| 1029 | do |
| 1030 | head -c 100 "$file" | grep -E "^#\!.*\\/bin\\/.*" | grep -q -E -v "^#\! ?\\/system" && sed --follow-symlinks -i -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" "$file" |
| 1031 | done < <(find -L . -type f -print0) |
| 1032 | |
| 1033 | test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL |
| 1034 | |
| 1035 | find . -type d -empty -delete # Remove empty directories |
| 1036 | |
| 1037 | # Sub packages: |
| 1038 | if [ -d include ] && [ -z "${TERMUX_PKG_NO_DEVELSPLIT}" ]; then |
| 1039 | # Add virtual -dev sub package if there are include files: |
| 1040 | local _DEVEL_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-dev.subpackage.sh |
| 1041 | echo TERMUX_SUBPKG_INCLUDE=\"include share/vala share/man/man3 lib/pkgconfig share/aclocal lib/cmake $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > "$_DEVEL_SUBPACKAGE_FILE" |
| 1042 | echo "TERMUX_SUBPKG_DESCRIPTION=\"Development files for ${TERMUX_PKG_NAME}\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
| 1043 | if [ -n "$TERMUX_PKG_DEVPACKAGE_DEPENDS" ]; then |
| 1044 | echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME,$TERMUX_PKG_DEVPACKAGE_DEPENDS\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
| 1045 | else |
| 1046 | echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME\"" >> "$_DEVEL_SUBPACKAGE_FILE" |
| 1047 | fi |
| 1048 | fi |
| 1049 | # Now build all sub packages |
| 1050 | rm -Rf "$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages" |
| 1051 | for subpackage in $TERMUX_PKG_BUILDER_DIR/*.subpackage.sh $TERMUX_PKG_TMPDIR/*subpackage.sh; do |
| 1052 | test ! -f "$subpackage" && continue |
| 1053 | local SUB_PKG_NAME |
| 1054 | SUB_PKG_NAME=$(basename "$subpackage" .subpackage.sh) |
| 1055 | # Default value is same as main package, but sub package may override: |
| 1056 | local TERMUX_SUBPKG_PLATFORM_INDEPENDENT=$TERMUX_PKG_PLATFORM_INDEPENDENT |
| 1057 | local SUB_PKG_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages/$SUB_PKG_NAME |
| 1058 | local TERMUX_SUBPKG_DEPENDS="" |
| 1059 | local TERMUX_SUBPKG_CONFLICTS="" |
| 1060 | local TERMUX_SUBPKG_REPLACES="" |
| 1061 | local TERMUX_SUBPKG_CONFFILES="" |
| 1062 | local SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX |
| 1063 | local SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package |
| 1064 | mkdir -p "$SUB_PKG_MASSAGE_DIR" "$SUB_PKG_PACKAGE_DIR" |
| 1065 | |
| 1066 | # shellcheck source=/dev/null |
| 1067 | source $subpackage |
| 1068 | |
| 1069 | for includeset in $TERMUX_SUBPKG_INCLUDE; do |
| 1070 | local _INCLUDE_DIRSET |
| 1071 | _INCLUDE_DIRSET=$(dirname "$includeset") |
| 1072 | test "$_INCLUDE_DIRSET" = "." && _INCLUDE_DIRSET="" |
| 1073 | if [ -e "$includeset" ] || [ -L "$includeset" ]; then |
| 1074 | # Add the -L clause to handle relative symbolic links: |
| 1075 | mkdir -p "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET" |
| 1076 | mv "$includeset" "$SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET" |
| 1077 | fi |
| 1078 | done |
| 1079 | |
| 1080 | local SUB_PKG_ARCH=$TERMUX_ARCH |
| 1081 | test -n "$TERMUX_SUBPKG_PLATFORM_INDEPENDENT" && SUB_PKG_ARCH=all |
| 1082 | |
| 1083 | cd "$SUB_PKG_DIR/massage" |
| 1084 | local SUB_PKG_INSTALLSIZE |
| 1085 | SUB_PKG_INSTALLSIZE=$(du -sk . | cut -f 1) |
| 1086 | tar -cJf "$SUB_PKG_PACKAGE_DIR/data.tar.xz" . |
| 1087 | |
| 1088 | mkdir -p DEBIAN |
| 1089 | cd DEBIAN |
| 1090 | cat > control <<-HERE |
| 1091 | Package: $SUB_PKG_NAME |
| 1092 | Architecture: ${SUB_PKG_ARCH} |
| 1093 | Installed-Size: ${SUB_PKG_INSTALLSIZE} |
| 1094 | Maintainer: $TERMUX_PKG_MAINTAINER |
| 1095 | Version: $TERMUX_PKG_FULLVERSION |
| 1096 | Description: $TERMUX_SUBPKG_DESCRIPTION |
| 1097 | Homepage: $TERMUX_PKG_HOMEPAGE |
| 1098 | HERE |
| 1099 | test ! -z "$TERMUX_SUBPKG_DEPENDS" && echo "Depends: $TERMUX_SUBPKG_DEPENDS" >> control |
| 1100 | test ! -z "$TERMUX_SUBPKG_CONFLICTS" && echo "Conflicts: $TERMUX_SUBPKG_CONFLICTS" >> control |
| 1101 | test ! -z "$TERMUX_SUBPKG_REPLACES" && echo "Replaces: $TERMUX_SUBPKG_REPLACES" >> control |
| 1102 | tar -cJf "$SUB_PKG_PACKAGE_DIR/control.tar.xz" . |
| 1103 | |
| 1104 | for f in $TERMUX_SUBPKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> conffiles; done |
| 1105 | |
| 1106 | # Create the actual .deb file: |
| 1107 | TERMUX_SUBPKG_DEBFILE=$TERMUX_DEBDIR/${SUB_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${SUB_PKG_ARCH}.deb |
| 1108 | test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary" |
| 1109 | ar cr "$TERMUX_SUBPKG_DEBFILE" \ |
| 1110 | "$TERMUX_COMMON_CACHEDIR/debian-binary" \ |
| 1111 | "$SUB_PKG_PACKAGE_DIR/control.tar.xz" \ |
| 1112 | "$SUB_PKG_PACKAGE_DIR/data.tar.xz" |
| 1113 | |
| 1114 | # Go back to main package: |
| 1115 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
| 1116 | done |
| 1117 | |
| 1118 | # .. remove empty directories (NOTE: keep this last): |
| 1119 | find . -type d -empty -delete |
| 1120 | # Make sure user can read and write all files (problem with dpkg otherwise): |
| 1121 | chmod -R u+rw . |
| 1122 | } |
| 1123 | |
| 1124 | termux_step_post_massage() { |
| 1125 | return |
| 1126 | } |
| 1127 | |
| 1128 | # Create data.tar.gz with files to package. Not to be overridden by package scripts. |
| 1129 | termux_step_create_datatar() { |
| 1130 | # Create data tarball containing files to package: |
| 1131 | cd "$TERMUX_PKG_MASSAGEDIR" |
| 1132 | |
| 1133 | local HARDLINKS="$(find . -type f -links +1)" |
| 1134 | if [ -n "$HARDLINKS" ]; then |
| 1135 | termux_error_exit "Package contains hard links: $HARDLINKS" |
| 1136 | fi |
| 1137 | |
| 1138 | if [ -z "${TERMUX_PKG_METAPACKAGE+x}" ] && [ "$(find . -type f)" = "" ]; then |
| 1139 | termux_error_exit "No files in package" |
| 1140 | fi |
| 1141 | tar -cJf "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" . |
| 1142 | } |
| 1143 | |
| 1144 | termux_step_create_debscripts() { |
| 1145 | return |
| 1146 | } |
| 1147 | |
| 1148 | # Create the build deb file. Not to be overridden by package scripts. |
| 1149 | termux_step_create_debfile() { |
| 1150 | # Get install size. This will be written as the "Installed-Size" deb field so is measured in 1024-byte blocks: |
| 1151 | local TERMUX_PKG_INSTALLSIZE |
| 1152 | TERMUX_PKG_INSTALLSIZE=$(du -sk . | cut -f 1) |
| 1153 | |
| 1154 | # From here on TERMUX_ARCH is set to "all" if TERMUX_PKG_PLATFORM_INDEPENDENT is set by the package |
| 1155 | test -n "$TERMUX_PKG_PLATFORM_INDEPENDENT" && TERMUX_ARCH=all |
| 1156 | |
| 1157 | mkdir -p DEBIAN |
| 1158 | cat > DEBIAN/control <<-HERE |
| 1159 | Package: $TERMUX_PKG_NAME |
| 1160 | Architecture: ${TERMUX_ARCH} |
| 1161 | Installed-Size: ${TERMUX_PKG_INSTALLSIZE} |
| 1162 | Maintainer: $TERMUX_PKG_MAINTAINER |
| 1163 | Version: $TERMUX_PKG_FULLVERSION |
| 1164 | Description: $TERMUX_PKG_DESCRIPTION |
| 1165 | Homepage: $TERMUX_PKG_HOMEPAGE |
| 1166 | HERE |
| 1167 | test ! -z "$TERMUX_PKG_BREAKS" && echo "Breaks: $TERMUX_PKG_BREAKS" >> DEBIAN/control |
| 1168 | test ! -z "$TERMUX_PKG_DEPENDS" && echo "Depends: $TERMUX_PKG_DEPENDS" >> DEBIAN/control |
| 1169 | test ! -z "$TERMUX_PKG_ESSENTIAL" && echo "Essential: yes" >> DEBIAN/control |
| 1170 | test ! -z "$TERMUX_PKG_CONFLICTS" && echo "Conflicts: $TERMUX_PKG_CONFLICTS" >> DEBIAN/control |
| 1171 | test ! -z "$TERMUX_PKG_RECOMMENDS" && echo "Recommends: $TERMUX_PKG_RECOMMENDS" >> DEBIAN/control |
| 1172 | test ! -z "$TERMUX_PKG_REPLACES" && echo "Replaces: $TERMUX_PKG_REPLACES" >> DEBIAN/control |
| 1173 | |
| 1174 | # Create DEBIAN/conffiles (see https://www.debian.org/doc/debian-policy/ap-pkg-conffiles.html): |
| 1175 | for f in $TERMUX_PKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> DEBIAN/conffiles; done |
| 1176 | |
| 1177 | # Allow packages to create arbitrary control files. |
| 1178 | # XXX: Should be done in a better way without a function? |
| 1179 | cd DEBIAN |
| 1180 | termux_step_create_debscripts |
| 1181 | |
| 1182 | # Create control.tar.xz |
| 1183 | tar -cJf "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" . |
| 1184 | |
| 1185 | test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary" |
| 1186 | TERMUX_PKG_DEBFILE=$TERMUX_DEBDIR/${TERMUX_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${TERMUX_ARCH}.deb |
| 1187 | # Create the actual .deb file: |
| 1188 | ar cr "$TERMUX_PKG_DEBFILE" \ |
| 1189 | "$TERMUX_COMMON_CACHEDIR/debian-binary" \ |
| 1190 | "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" \ |
| 1191 | "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" |
| 1192 | } |
| 1193 | |
| 1194 | # Finish the build. Not to be overridden by package scripts. |
| 1195 | termux_step_finish_build() { |
| 1196 | echo "termux - build of '$TERMUX_PKG_NAME' done" |
| 1197 | test -t 1 && printf "\033]0;%s - DONE\007" "$TERMUX_PKG_NAME" |
| 1198 | mkdir -p /data/data/.built-packages |
| 1199 | echo "$TERMUX_PKG_FULLVERSION" > "/data/data/.built-packages/$TERMUX_PKG_NAME" |
| 1200 | exit 0 |
| 1201 | } |
| 1202 | |
| 1203 | termux_step_handle_arguments "$@" |
| 1204 | termux_step_setup_variables |
| 1205 | termux_step_handle_buildarch |
| 1206 | termux_step_start_build |
| 1207 | termux_step_extract_package |
| 1208 | cd "$TERMUX_PKG_SRCDIR" |
| 1209 | termux_step_post_extract_package |
| 1210 | termux_step_handle_hostbuild |
| 1211 | termux_step_setup_toolchain |
| 1212 | termux_step_patch_package |
| 1213 | termux_step_replace_guess_scripts |
| 1214 | cd "$TERMUX_PKG_SRCDIR" |
| 1215 | termux_step_pre_configure |
| 1216 | cd "$TERMUX_PKG_BUILDDIR" |
| 1217 | termux_step_configure |
| 1218 | cd "$TERMUX_PKG_BUILDDIR" |
| 1219 | termux_step_post_configure |
| 1220 | cd "$TERMUX_PKG_BUILDDIR" |
| 1221 | termux_step_make |
| 1222 | cd "$TERMUX_PKG_BUILDDIR" |
| 1223 | termux_step_make_install |
| 1224 | cd "$TERMUX_PKG_BUILDDIR" |
| 1225 | termux_step_post_make_install |
| 1226 | cd "$TERMUX_PKG_MASSAGEDIR" |
| 1227 | termux_step_extract_into_massagedir |
| 1228 | cd "$TERMUX_PKG_MASSAGEDIR" |
| 1229 | termux_step_massage |
| 1230 | cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" |
| 1231 | termux_step_post_massage |
| 1232 | termux_step_create_datatar |
| 1233 | termux_step_create_debfile |
| 1234 | termux_step_finish_build |