X-Git-Url: https://git.distorted.org.uk/~mdw/termux-packages/blobdiff_plain/c9d4e74fa11c94958961e840c6aaf9af8d12d08d..fbf6030533fad61342a7f0b97a082a4ff44d63a3:/build-package.sh diff --git a/build-package.sh b/build-package.sh index 2790f6f7..b009c45e 100755 --- a/build-package.sh +++ b/build-package.sh @@ -70,7 +70,7 @@ termux_setup_golang() { termux_error_exit "Unsupported arch: $TERMUX_ARCH" fi - local TERMUX_GO_VERSION=go1.8rc3 + local TERMUX_GO_VERSION=go1.9 local TERMUX_GO_PLATFORM=linux-amd64 local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION} @@ -83,13 +83,83 @@ termux_setup_golang() { rm -Rf "$TERMUX_COMMON_CACHEDIR/go" "$TERMUX_BUILDGO_FOLDER" termux_download https://storage.googleapis.com/golang/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz \ "$TERMUX_BUILDGO_TAR" \ - 0ff3faba02ac83920a65b453785771e75f128fbf9ba4ad1d5e72c044103f9c7a + d70eadefce8e160638a9a6db97f7192d8463069ab33138893ad3bf31b0650a79 + ( cd "$TERMUX_COMMON_CACHEDIR"; tar xf "$TERMUX_BUILDGO_TAR"; mv go "$TERMUX_BUILDGO_FOLDER"; rm "$TERMUX_BUILDGO_TAR" ) } +# Utility function for cmake-built packages to setup a current ninja. +termux_setup_ninja() { + local NINJA_VERSION=1.7.2 + local NINJA_FOLDER=$TERMUX_COMMON_CACHEDIR/ninja-$NINJA_VERSION + if [ ! -x $NINJA_FOLDER/ninja ]; then + mkdir -p $NINJA_FOLDER + local NINJA_ZIP_FILE=$TERMUX_PKG_TMPDIR/ninja-$NINJA_VERSION.zip + termux_download https://github.com/ninja-build/ninja/releases/download/v$NINJA_VERSION/ninja-linux.zip \ + $NINJA_ZIP_FILE \ + 38fa8cfb9c1632a5cdf7a32fe1a7c5aa89e96c1d492c28624f4cc018e68458b9 + unzip $NINJA_ZIP_FILE -d $NINJA_FOLDER + fi + export PATH=$NINJA_FOLDER:$PATH +} + +# Utility function for cmake-built packages to setup a current meson. +termux_setup_meson() { + termux_setup_ninja + local MESON_VERSION=0.42.0 + local MESON_FOLDER=$TERMUX_COMMON_CACHEDIR/meson-$MESON_VERSION + if [ ! -d "$MESON_FOLDER" ]; then + local MESON_TAR_NAME=meson-$MESON_VERSION.tar.gz + local MESON_TAR_FILE=$TERMUX_PKG_TMPDIR/$MESON_TAR_NAME + termux_download \ + https://github.com/mesonbuild/meson/releases/download/$MESON_VERSION/meson-$MESON_VERSION.tar.gz \ + $MESON_TAR_FILE \ + a74c7387a3dd8171e931bcd948355f7f9529368eae72c3c22a9beef6c2e73498 + tar xf "$MESON_TAR_FILE" -C "$TERMUX_COMMON_CACHEDIR" + (cd $MESON_FOLDER && patch -p1 < $TERMUX_SCRIPTDIR/scripts/meson-android.patch) + fi + TERMUX_MESON="$MESON_FOLDER/meson.py" + TERMUX_MESON_CROSSFILE=$TERMUX_COMMON_CACHEDIR/meson-crossfile-$TERMUX_ARCH-v1.txt + if [ ! -f $TERMUX_MESON_CROSSFILE ]; then + local MESON_CPU MESON_CPU_FAMILY + if [ $TERMUX_ARCH = "arm" ]; then + MESON_CPU_FAMILY="arm" + MESON_CPU="armv7" + elif [ $TERMUX_ARCH = "i686" ]; then + MESON_CPU_FAMILY="x86" + MESON_CPU="i686" + elif [ $TERMUX_ARCH = "x86_64" ]; then + MESON_CPU_FAMILY="x86_64" + MESON_CPU="x86_64" + elif [ $TERMUX_ARCH = "aarch64" ]; then + MESON_CPU_FAMILY="arm" + MESON_CPU="aarch64" + else + termux_error_exit "Unsupported arch: $TERMUX_ARCH" + fi + + cat > $TERMUX_MESON_CROSSFILE <<-HERE + [binaries] + ar = '$AR' + c = '$CC' + cpp = '$CXX' + ld = '$LD' + pkg-config = '$PKG_CONFIG' + strip = '$STRIP' + [properties] + needs_exe_wrapper = true + [host_machine] + cpu_family = '$MESON_CPU_FAMILY' + cpu = '$MESON_CPU' + endian = 'little' + system = 'android' + HERE + fi +} + # Utility function for cmake-built packages to setup a current cmake. termux_setup_cmake() { - local TERMUX_CMAKE_MAJORVESION=3.7 + local TERMUX_CMAKE_MAJORVESION=3.9 local TERMUX_CMAKE_MINORVERSION=2 local TERMUX_CMAKE_VERSION=$TERMUX_CMAKE_MAJORVESION.$TERMUX_CMAKE_MINORVERSION local TERMUX_CMAKE_TARNAME=cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64.tar.gz @@ -98,7 +168,7 @@ termux_setup_cmake() { if [ ! -d "$TERMUX_CMAKE_FOLDER" ]; then termux_download https://cmake.org/files/v$TERMUX_CMAKE_MAJORVESION/$TERMUX_CMAKE_TARNAME \ "$TERMUX_CMAKE_TARFILE" \ - 0e6ec35d4fa9bf79800118916b51928b6471d5725ff36f1d0de5ebb34dcd5406 + f4e1e848e21c3fba134fbddd793860ba9a17c35d0aeaa3bd83149a6ec1bf9fbb rm -Rf "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64" tar xf "$TERMUX_CMAKE_TARFILE" -C "$TERMUX_PKG_TMPDIR" mv "$TERMUX_PKG_TMPDIR/cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64" \ @@ -157,6 +227,8 @@ termux_step_handle_arguments() { if [ ! -d "$1" ]; then termux_error_exit "'$1' seems to be a path but is not a directory"; fi export TERMUX_PKG_BUILDER_DIR TERMUX_PKG_BUILDER_DIR=$(realpath "$1") + # Skip depcheck for external package: + TERMUX_SKIP_DEPCHECK=true else # Package name: if [ -n "${TERMUX_IS_DISABLED=""}" ]; then @@ -175,15 +247,15 @@ termux_step_handle_arguments() { termux_step_setup_variables() { : "${ANDROID_HOME:="${HOME}/lib/android-sdk"}" : "${NDK:="${HOME}/lib/android-ndk"}" - : "${TERMUX_MAKE_PROCESSES:="4"}" + : "${TERMUX_MAKE_PROCESSES:="$(nproc)"}" : "${TERMUX_TOPDIR:="$HOME/.termux-build"}" : "${TERMUX_ARCH:="aarch64"}" # arm, aarch64, i686 or x86_64. : "${TERMUX_PREFIX:="/data/data/com.termux/files/usr"}" : "${TERMUX_ANDROID_HOME:="/data/data/com.termux/files/home"}" : "${TERMUX_DEBUG:=""}" - : "${TERMUX_API_LEVEL:="21"}" - : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="25.0.1"}" - : "${TERMUX_NDK_VERSION:="13"}" + : "${TERMUX_PKG_API_LEVEL:="21"}" + : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="26.0.1"}" + : "${TERMUX_NDK_VERSION:="15.2"}" if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then TERMUX_ARCH_BITS=64 @@ -208,23 +280,13 @@ termux_step_setup_variables() { # to avoid stuff like arm-linux-androideabi-ld there to conflict with ones from # the standalone toolchain. TERMUX_DX=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/dx - TERMUX_JACK=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/jack.jar - TERMUX_JILL=$ANDROID_HOME/build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/jill.jar TERMUX_COMMON_CACHEDIR="$TERMUX_TOPDIR/_cache" TERMUX_DEBDIR="$TERMUX_SCRIPTDIR/debs" TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner - TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/toolchain-${TERMUX_ARCH}-ndk${TERMUX_NDK_VERSION}-api${TERMUX_API_LEVEL}" - # Bump the below version if a change is made in toolchain setup to ensure - # that everyone gets an updated toolchain: - TERMUX_STANDALONE_TOOLCHAIN+="-v10" - - export TERMUX_TAR="tar" - export TERMUX_TOUCH="touch" export prefix=${TERMUX_PREFIX} export PREFIX=${TERMUX_PREFIX} - export PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig TERMUX_PKG_BUILDDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/build TERMUX_PKG_CACHEDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/cache @@ -242,13 +304,16 @@ termux_step_setup_variables() { TERMUX_PKG_EXTRA_MAKE_ARGS="" TERMUX_PKG_BUILD_IN_SRC="" TERMUX_PKG_RM_AFTER_INSTALL="" + TERMUX_PKG_BREAKS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps TERMUX_PKG_DEPENDS="" + TERMUX_PKG_BUILD_DEPENDS="" TERMUX_PKG_HOMEPAGE="" TERMUX_PKG_DESCRIPTION="FIXME:Add description" TERMUX_PKG_FOLDERNAME="" TERMUX_PKG_KEEP_STATIC_LIBRARIES="false" TERMUX_PKG_ESSENTIAL="" TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts + TERMUX_PKG_RECOMMENDS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps TERMUX_PKG_REPLACES="" TERMUX_PKG_CONFFILES="" TERMUX_PKG_INCLUDE_IN_DEVPACKAGE="" @@ -278,7 +343,9 @@ termux_step_handle_buildarch() { if test -e "$TERMUX_DATA_PREVIOUS_BACKUPDIR"; then termux_error_exit "Directory already exists" fi - mv /data/data "$TERMUX_DATA_PREVIOUS_BACKUPDIR" + if [ -d /data/data ]; then + mv /data/data "$TERMUX_DATA_PREVIOUS_BACKUPDIR" + fi # Restore new one (if any) if [ -d "$TERMUX_DATA_CURRENT_BACKUPDIR" ]; then mv "$TERMUX_DATA_CURRENT_BACKUPDIR" /data/data @@ -295,6 +362,11 @@ termux_step_start_build() { # shellcheck source=/dev/null source "$TERMUX_PKG_BUILDER_SCRIPT" + TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/${TERMUX_NDK_VERSION}-${TERMUX_ARCH}-${TERMUX_PKG_API_LEVEL}" + # Bump the below version if a change is made in toolchain setup to ensure + # that everyone gets an updated toolchain: + TERMUX_STANDALONE_TOOLCHAIN+="-v14" + if [ -n "${TERMUX_PKG_BLACKLISTED_ARCHES:=""}" ] && [ "$TERMUX_PKG_BLACKLISTED_ARCHES" != "${TERMUX_PKG_BLACKLISTED_ARCHES/$TERMUX_ARCH/}" ]; then echo "Skipping building $TERMUX_PKG_NAME for arch $TERMUX_ARCH" exit 0 @@ -341,14 +413,18 @@ termux_step_start_build() { "$TERMUX_PKG_TMPDIR" \ "$TERMUX_PKG_CACHEDIR" \ "$TERMUX_PKG_MASSAGEDIR" \ - $PKG_CONFIG_LIBDIR \ $TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp,include} # 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: ln -f -s /bin/sh "$TERMUX_PREFIX/bin/sh" - TERMUX_ELF_CLEANER_SRC=$TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/termux-elf-cleaner.cpp + local TERMUX_ELF_CLEANER_SRC=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner.cpp + local TERMUX_ELF_CLEANER_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/build.sh; echo \$TERMUX_PKG_VERSION") + termux_download \ + https://raw.githubusercontent.com/termux/termux-elf-cleaner/v$TERMUX_ELF_CLEANER_VERSION/termux-elf-cleaner.cpp \ + $TERMUX_ELF_CLEANER_SRC \ + 11a38372f4d0e36b7556382c7ecffecae35cee8b68daaee2dbee025f758e17ee if [ "$TERMUX_ELF_CLEANER_SRC" -nt "$TERMUX_ELF_CLEANER" ]; then g++ -std=c++11 -Wall -Wextra -pedantic -Os "$TERMUX_ELF_CLEANER_SRC" -o "$TERMUX_ELF_CLEANER" fi @@ -361,8 +437,11 @@ termux_step_start_build() { echo "termux - building $TERMUX_PKG_NAME for arch $TERMUX_ARCH..." test -t 1 && printf "\033]0;%s...\007" "$TERMUX_PKG_NAME" - # Add a pkg-config file for the system zlib - cat > "$PKG_CONFIG_LIBDIR/zlib.pc" <<-HERE + # Avoid exporting PKG_CONFIG_LIBDIR until after termux_step_host_build. + export TERMUX_PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig + # Add a pkg-config file for the system zlib. + mkdir -p "$TERMUX_PKG_CONFIG_LIBDIR" + cat > "$TERMUX_PKG_CONFIG_LIBDIR/zlib.pc" <<-HERE Name: zlib Description: zlib compression library Version: 1.2.8 @@ -391,7 +470,7 @@ termux_step_extract_package() { termux_download "$TERMUX_PKG_SRCURL" "$file" "$TERMUX_PKG_SHA256" if [ "x$TERMUX_PKG_FOLDERNAME" = "x" ]; then - folder=`basename $filename .tar.bz2` && folder=`basename $folder .tar.gz` && folder=`basename $folder .tar.xz` && folder=`basename $folder .tar.lz` && folder=`basename $folder .tgz` && folder=`basename $folder .zip` + folder="${filename%%.t*}" && folder="${folder%%.zip}" folder="${folder/_/-}" # dpkg uses _ in tar filename, but - in folder else folder=$TERMUX_PKG_FOLDERNAME @@ -400,7 +479,7 @@ termux_step_extract_package() { if [ "${file##*.}" = zip ]; then unzip -q "$file" else - $TERMUX_TAR xf "$file" + tar xf "$file" fi mv $folder "$TERMUX_PKG_SRCDIR" } @@ -477,7 +556,7 @@ termux_step_setup_toolchain() { # "We recommend using the -mthumb compiler flag to force the generation of 16-bit Thumb-2 instructions". # With r13 of the ndk ruby 2.4.0 segfaults when built on arm with clang without -mthumb. CFLAGS+=" -march=armv7-a -mfpu=neon -mfloat-abi=softfp -mthumb" - LDFLAGS+=" -march=armv7-a -Wl,--fix-cortex-a8" + LDFLAGS+=" -march=armv7-a" elif [ "$TERMUX_ARCH" = "i686" ]; then # From $NDK/docs/CPU-ARCH-ABIS.html: CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse" @@ -492,7 +571,18 @@ termux_step_setup_toolchain() { if [ -n "$TERMUX_DEBUG" ]; then CFLAGS+=" -g3 -O1 -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2" else - CFLAGS+=" -Os" + if [ "$TERMUX_PKG_CLANG" = "no" ]; then + CFLAGS+=" -Os" + else + if [ "$TERMUX_PKG_NAME" = "ruby" -a "$TERMUX_ARCH" = arm ]; then + # This exception is to avoid a broken ruby on 32-bit arm + # with NDK r15c and ruby 2.4.2 - see #1520. + CFLAGS+=" -O1" + else + # -Oz seems good for clang, see https://github.com/android-ndk/ndk/issues/133 + CFLAGS+=" -Oz" + fi + fi fi export CXXFLAGS="$CFLAGS" @@ -507,6 +597,7 @@ termux_step_setup_toolchain() { export ac_cv_func_getpwent=no export ac_cv_func_getpwnam=no export ac_cv_func_getpwuid=no + export ac_cv_func_sigsetmask=no if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then # Do not put toolchain in place until we are done with setup, to avoid having a half setup @@ -522,10 +613,14 @@ termux_step_setup_toolchain() { fi "$NDK/build/tools/make_standalone_toolchain.py" \ - --api "$TERMUX_API_LEVEL" \ + --api "$TERMUX_PKG_API_LEVEL" \ --arch $_NDK_ARCHNAME \ + --stl=libc++ \ --install-dir $_TERMUX_TOOLCHAIN_TMPDIR + # Remove android-support header wrapping not needed on android-21: + rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/local + local wrapped plusplus CLANG_TARGET=$TERMUX_HOST_PLATFORM if [ $TERMUX_ARCH = arm ]; then CLANG_TARGET=${CLANG_TARGET/arm-/armv7a-}; fi for wrapped in ${TERMUX_HOST_PLATFORM}-clang clang; do @@ -535,16 +630,12 @@ termux_step_setup_toolchain() { termux_error_exit "No toolchain file to override: $FILE_TO_REPLACE" fi cp "$TERMUX_SCRIPTDIR/scripts/clang-pie-wrapper" $FILE_TO_REPLACE - sed -i "s/COMPILER/clang38$plusplus/" $FILE_TO_REPLACE + sed -i "s/COMPILER/clang50$plusplus/" $FILE_TO_REPLACE sed -i "s/CLANG_TARGET/$CLANG_TARGET/" $FILE_TO_REPLACE done done - if [ "$TERMUX_ARCH" = "arm" ]; then - # Fix to allow e.g. to be included: - cp $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/arm-linux-androideabi/armv7-a/bits/* \ - $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x/bits - elif [ "$TERMUX_ARCH" = "aarch64" ]; then + if [ "$TERMUX_ARCH" = "aarch64" ]; then # Use gold by default to work around https://github.com/android-ndk/ndk/issues/148 cp $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld.gold \ $_TERMUX_TOOLCHAIN_TMPDIR/bin/aarch64-linux-android-ld @@ -552,32 +643,60 @@ termux_step_setup_toolchain() { $_TERMUX_TOOLCHAIN_TMPDIR/aarch64-linux-android/bin/ld fi + if [ "$TERMUX_ARCH" = "arm" ]; then + # Linker wrapper script to add '--exclude-libs libgcc.a', see + # https://github.com/android-ndk/ndk/issues/379 + # https://android-review.googlesource.com/#/c/389852/ + local linker + for linker in ld ld.bfd ld.gold; do + local wrap_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker + local real_linker=$_TERMUX_TOOLCHAIN_TMPDIR/$TERMUX_HOST_PLATFORM/bin/$linker.real + cp $wrap_linker $real_linker + echo '#!/bin/bash' > $wrap_linker + echo -n '`dirname $0`/' >> $wrap_linker + echo -n $linker.real >> $wrap_linker + echo ' --exclude-libs libgcc.a "$@"' >> $wrap_linker + done + fi + cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot - for f in $TERMUX_SCRIPTDIR/ndk_patches/*.patch; do + for f in $TERMUX_SCRIPTDIR/ndk-patches/*.patch; do sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$f" | \ sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ patch --silent -p1; done - # elf.h is taken from glibc since the elf.h in the NDK is lacking. - # sysexits.h is header-only and used by a few programs. - cp "$TERMUX_SCRIPTDIR"/ndk_patches/{elf.h,sysexits.h} $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include + # elf.h: Taken from glibc since the elf.h in the NDK is lacking. + # sysexits.h: Header-only and used by a few programs. + # ifaddrs.h: Added in android-24 unified headers, use a inline implementation for now. + cp "$TERMUX_SCRIPTDIR"/ndk-patches/{elf.h,sysexits.h,ifaddrs.h,libintl.h} usr/include + + # Remove from the NDK in favour of that from the libandroid-shmem. + # Also remove as it doesn't work for non-root. + rm usr/include/sys/{shm.h,sem.h} - $TERMUX_ELF_CLEANER usr/lib/*.so + sed -i "s/define __ANDROID_API__ __ANDROID_API_FUTURE__/define __ANDROID_API__ $TERMUX_PKG_API_LEVEL/" \ + usr/include/android/api-level.h + + local _LIBDIR=usr/lib + if [ $TERMUX_ARCH = x86_64 ]; then _LIBDIR+=64; fi + $TERMUX_ELF_CLEANER $_LIBDIR/*.so # zlib is really version 1.2.8 in the Android platform (at least # starting from Android 5), not older as the NDK headers claim. for file in zconf.h zlib.h; do - curl -o $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include/$file \ + curl -o usr/include/$file \ https://raw.githubusercontent.com/madler/zlib/v1.2.8/$file done unset file - + cd $_TERMUX_TOOLCHAIN_TMPDIR/include/c++/4.9.x + sed "s%\@TERMUX_HOST_PLATFORM\@%${TERMUX_HOST_PLATFORM}%g" $TERMUX_SCRIPTDIR/ndk-patches/*.cpppatch | patch -p1 mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN fi + local _STL_LIBFILE_NAME=libc++_shared.so if [ ! -f $TERMUX_PREFIX/lib/libstdc++.so ]; then - # Setup libgnustl_shared.so in $PREFIX/lib and libstdc++.so as a symlink to it, + # Setup libgnustl_shared.so in $PREFIX/lib and libstdc++.so as a link to it, # so that other C++ using packages links to it instead of the default android # C++ library which does not support exceptions or STL: # https://developer.android.com/ndk/guides/cpp-support.html @@ -587,16 +706,28 @@ termux_step_setup_toolchain() { # which is part of the base Termux installation. mkdir -p "$TERMUX_PREFIX/lib" cd "$TERMUX_PREFIX/lib" - _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/libgnustl_shared.so + + local _STL_LIBFILE= if [ "$TERMUX_ARCH" = arm ]; then - _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/armv7-a/libgnustl_shared.so + local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/armv7-a/$_STL_LIBFILE_NAME elif [ "$TERMUX_ARCH" = x86_64 ]; then - _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/libgnustl_shared.so + local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/$_STL_LIBFILE_NAME + else + local _STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib/$_STL_LIBFILE_NAME fi + cp "$_STL_LIBFILE" . - ln -f -s libgnustl_shared.so libstdc++.so + $STRIP --strip-unneeded $_STL_LIBFILE_NAME + $TERMUX_ELF_CLEANER $_STL_LIBFILE_NAME + if [ $TERMUX_ARCH = "arm" ]; then + # Use a linker script to get libunwind.a. + echo 'INPUT(-lunwind -lc++_shared)' > libstdc++.so + else + ln -f $_STL_LIBFILE_NAME libstdc++.so + fi fi + export PKG_CONFIG_LIBDIR="$TERMUX_PKG_CONFIG_LIBDIR" # 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 @@ -615,12 +746,18 @@ termux_step_setup_toolchain() { termux_step_patch_package() { cd "$TERMUX_PKG_SRCDIR" # Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses: + shopt -s nullglob for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,}; do test -f "$patch" && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" "$patch" | \ sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \ patch --silent -p1 done + shopt -u nullglob +} +# Replace autotools build-aux/config.{sub,guess} with ours to add android targets. +termux_step_replace_guess_scripts () { + cd "$TERMUX_PKG_SRCDIR" find . -name config.sub -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.sub" '{}' \; find . -name config.guess -exec chmod u+w '{}' \; -exec cp "$TERMUX_SCRIPTDIR/scripts/config.guess" '{}' \; } @@ -653,6 +790,10 @@ termux_step_configure_autotools () { if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--host=/}" ]; then HOST_FLAG="" fi + LIBEXEC_FLAG="--libexecdir=$TERMUX_PREFIX/libexec" + if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--libexecdir=/}" ]; then + LIBEXEC_FLAG="" + fi # Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config: mkdir "$TERMUX_PKG_TMPDIR/config-scripts" @@ -661,19 +802,58 @@ termux_step_configure_autotools () { done export PATH=$TERMUX_PKG_TMPDIR/config-scripts:$PATH - # See http://wiki.buici.com/xwiki/bin/view/Programing+C+and+C%2B%2B/Autoconf+and+RPL_MALLOC - # about this problem which may cause linker errors in test scripts not undef:ing malloc and - # also cause problems with e.g. malloc interceptors such as libgc: - local AVOID_AUTOCONF_WRAPPERS="ac_cv_func_malloc_0_nonnull=yes ac_cv_func_realloc_0_nonnull=yes" - # Similarly, disable gnulib's rpl_getcwd(). It returns the wrong value, affecting zile. See - # . - AVOID_AUTOCONF_WRAPPERS+=" gl_cv_func_getcwd_null=yes gl_cv_func_getcwd_posix_signature=yes gl_cv_func_getcwd_path_max=yes gl_cv_func_getcwd_abort_bug=no" - AVOID_AUTOCONF_WRAPPERS+=" gl_cv_header_working_fcntl_h=yes gl_cv_func_fcntl_f_dupfd_cloexec=yes gl_cv_func_fcntl_f_dupfd_works=yes" - # Remove rpl_gettimeofday reference when building at least coreutils: - AVOID_AUTOCONF_WRAPPERS+=" gl_cv_func_tzset_clobber=no gl_cv_func_gettimeofday_clobber=no gl_cv_func_gettimeofday_posix_signature=yes" - - # NOTE: We do not want to quote AVOID_AUTOCONF_WRAPPERS as we want word expansion. - env $AVOID_AUTOCONF_WRAPPERS "$TERMUX_PKG_SRCDIR/configure" \ + # Avoid gnulib wrapping of functions when cross compiling. See + # http://wiki.osdev.org/Cross-Porting_Software#Gnulib + # https://gitlab.com/sortix/sortix/wikis/Gnulib + # https://github.com/termux/termux-packages/issues/76 + local AVOID_GNULIB="" + AVOID_GNULIB+=" ac_cv_func_calloc_0_nonnull=yes" + AVOID_GNULIB+=" ac_cv_func_chown_works=yes" + AVOID_GNULIB+=" ac_cv_func_getgroups_works=yes" + AVOID_GNULIB+=" ac_cv_func_malloc_0_nonnull=yes" + AVOID_GNULIB+=" ac_cv_func_realloc_0_nonnull=yes" + AVOID_GNULIB+=" am_cv_func_working_getline=yes" + AVOID_GNULIB+=" gl_cv_func_dup2_works=yes" + AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_cloexec=yes" + AVOID_GNULIB+=" gl_cv_func_fcntl_f_dupfd_works=yes" + AVOID_GNULIB+=" gl_cv_func_fnmatch_posix=yes" + AVOID_GNULIB+=" gl_cv_func_getcwd_abort_bug=no" + AVOID_GNULIB+=" gl_cv_func_getcwd_null=yes" + AVOID_GNULIB+=" gl_cv_func_getcwd_path_max=yes" + AVOID_GNULIB+=" gl_cv_func_getcwd_posix_signature=yes" + AVOID_GNULIB+=" gl_cv_func_gettimeofday_clobber=no" + AVOID_GNULIB+=" gl_cv_func_gettimeofday_posix_signature=yes" + AVOID_GNULIB+=" gl_cv_func_link_works=yes" + AVOID_GNULIB+=" gl_cv_func_lstat_dereferences_slashed_symlink=yes" + AVOID_GNULIB+=" gl_cv_func_malloc_0_nonnull=yes" + AVOID_GNULIB+=" gl_cv_func_memchr_works=yes" + AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_dot_works=yes" + AVOID_GNULIB+=" gl_cv_func_mkdir_trailing_slash_works=yes" + AVOID_GNULIB+=" gl_cv_func_mkfifo_works=yes" + AVOID_GNULIB+=" gl_cv_func_realpath_works=yes" + AVOID_GNULIB+=" gl_cv_func_select_detects_ebadf=yes" + AVOID_GNULIB+=" gl_cv_func_snprintf_posix=yes" + AVOID_GNULIB+=" gl_cv_func_snprintf_retval_c99=yes" + AVOID_GNULIB+=" gl_cv_func_snprintf_truncation_c99=yes" + AVOID_GNULIB+=" gl_cv_func_stat_dir_slash=yes" + AVOID_GNULIB+=" gl_cv_func_stat_file_slash=yes" + AVOID_GNULIB+=" gl_cv_func_strerror_0_works=yes" + AVOID_GNULIB+=" gl_cv_func_symlink_works=yes" + AVOID_GNULIB+=" gl_cv_func_tzset_clobber=no" + AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes" + AVOID_GNULIB+=" gl_cv_func_unlink_honors_slashes=yes" + AVOID_GNULIB+=" gl_cv_func_vsnprintf_posix=yes" + AVOID_GNULIB+=" gl_cv_func_vsnprintf_zerosize_c99=yes" + AVOID_GNULIB+=" gl_cv_func_wcwidth_works=yes" + AVOID_GNULIB+=" gl_cv_func_working_getdelim=yes" + AVOID_GNULIB+=" gl_cv_func_working_mkstemp=yes" + AVOID_GNULIB+=" gl_cv_func_working_mktime=yes" + AVOID_GNULIB+=" gl_cv_func_working_strerror=yes" + AVOID_GNULIB+=" gl_cv_header_working_fcntl_h=yes" + AVOID_GNULIB+=" gl_cv_C_locale_sans_EILSEQ=yes" + + # NOTE: We do not want to quote AVOID_GNULIB as we want word expansion. + env $AVOID_GNULIB "$TERMUX_PKG_SRCDIR/configure" \ --disable-dependency-tracking \ --prefix=$TERMUX_PREFIX \ --disable-rpath --disable-rpath-hack \ @@ -682,7 +862,7 @@ termux_step_configure_autotools () { $DISABLE_NLS \ $ENABLE_SHARED \ $DISABLE_STATIC \ - --libexecdir=$TERMUX_PREFIX/libexec + $LIBEXEC_FLAG } termux_step_configure_cmake () { @@ -699,6 +879,7 @@ termux_step_configure_cmake () { # pick up cross compiled binutils tool in $PREFIX/bin: cmake -G 'Unix Makefiles' "$TERMUX_PKG_SRCDIR" \ -DCMAKE_AR="$(which $AR)" \ + -DCMAKE_UNAME="$(which uname)" \ -DCMAKE_RANLIB="$(which $RANLIB)" \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_CROSSCOMPILING=True \ @@ -719,11 +900,26 @@ termux_step_configure_cmake () { $TERMUX_PKG_EXTRA_CONFIGURE_ARGS $TOOLCHAIN_ARGS } +termux_step_configure_meson () { + termux_setup_meson + CC=gcc CXX=g++ $TERMUX_MESON \ + $TERMUX_PKG_SRCDIR \ + $TERMUX_PKG_BUILDDIR \ + --cross-file $TERMUX_MESON_CROSSFILE \ + --prefix $TERMUX_PREFIX \ + --libdir lib \ + --buildtype minsize \ + --strip \ + $TERMUX_PKG_EXTRA_CONFIGURE_ARGS +} + termux_step_configure () { if [ "$TERMUX_PKG_FORCE_CMAKE" == 'no' ] && [ -f "$TERMUX_PKG_SRCDIR/configure" ]; then termux_step_configure_autotools elif [ -f "$TERMUX_PKG_SRCDIR/CMakeLists.txt" ]; then termux_step_configure_cmake + elif [ -f "$TERMUX_PKG_SRCDIR/meson.build" ]; then + termux_step_configure_meson fi } @@ -750,6 +946,8 @@ termux_step_make_install() { else make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET} fi + elif test -f build.ninja; then + ninja install fi } @@ -763,12 +961,14 @@ termux_step_extract_into_massagedir() { # Build diff tar with what has changed during the build: cd $TERMUX_PREFIX - $TERMUX_TAR -N "$TERMUX_BUILD_TS_FILE" -czf "$TARBALL_ORIG" . + tar -N "$TERMUX_BUILD_TS_FILE" \ + --exclude='lib/libc++_shared.so' --exclude='lib/libstdc++.so' \ + -czf "$TARBALL_ORIG" . # Extract tar in order to massage it mkdir -p "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" cd "$TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX" - $TERMUX_TAR xf "$TARBALL_ORIG" + tar xf "$TARBALL_ORIG" rm "$TARBALL_ORIG" } @@ -805,10 +1005,11 @@ termux_step_massage() { # Move over sbin to bin: for file in sbin/*; do if test -f "$file"; then mv "$file" bin/; fi; done - # Remove world permissions and add write permissions. + # Remove world permissions and add write permissions. # The -f flag is used to suppress warnings about dangling symlinks (such # as ones to /system/... which may not exist on the build machine): - find . -exec chmod -f u+w,o-rwx \{\} \; + find . -exec chmod -f u+w,g-rwx,o-rwx \{\} \; + if [ "$TERMUX_DEBUG" = "" ]; then # Strip binaries. file(1) may fail for certain unusual files, so disable pipefail. set +e +o pipefail @@ -833,7 +1034,7 @@ termux_step_massage() { if [ -d include ] && [ -z "${TERMUX_PKG_NO_DEVELSPLIT}" ]; then # Add virtual -dev sub package if there are include files: local _DEVEL_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-dev.subpackage.sh - echo TERMUX_SUBPKG_INCLUDE=\"include share/man/man3 lib/pkgconfig share/aclocal lib/cmake $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > "$_DEVEL_SUBPACKAGE_FILE" + echo TERMUX_SUBPKG_INCLUDE=\"include share/vala share/man/man3 lib/pkgconfig share/aclocal lib/cmake $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > "$_DEVEL_SUBPACKAGE_FILE" echo "TERMUX_SUBPKG_DESCRIPTION=\"Development files for ${TERMUX_PKG_NAME}\"" >> "$_DEVEL_SUBPACKAGE_FILE" if [ -n "$TERMUX_PKG_DEVPACKAGE_DEPENDS" ]; then echo "TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME,$TERMUX_PKG_DEVPACKAGE_DEPENDS\"" >> "$_DEVEL_SUBPACKAGE_FILE" @@ -852,6 +1053,8 @@ termux_step_massage() { local SUB_PKG_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages/$SUB_PKG_NAME local TERMUX_SUBPKG_DEPENDS="" local TERMUX_SUBPKG_CONFLICTS="" + local TERMUX_SUBPKG_REPLACES="" + local TERMUX_SUBPKG_CONFFILES="" local SUB_PKG_MASSAGE_DIR=$SUB_PKG_DIR/massage/$TERMUX_PREFIX local SUB_PKG_PACKAGE_DIR=$SUB_PKG_DIR/package mkdir -p "$SUB_PKG_MASSAGE_DIR" "$SUB_PKG_PACKAGE_DIR" @@ -876,7 +1079,7 @@ termux_step_massage() { cd "$SUB_PKG_DIR/massage" local SUB_PKG_INSTALLSIZE SUB_PKG_INSTALLSIZE=$(du -sk . | cut -f 1) - $TERMUX_TAR -cJf "$SUB_PKG_PACKAGE_DIR/data.tar.xz" . + tar -cJf "$SUB_PKG_PACKAGE_DIR/data.tar.xz" . mkdir -p DEBIAN cd DEBIAN @@ -891,7 +1094,10 @@ termux_step_massage() { HERE test ! -z "$TERMUX_SUBPKG_DEPENDS" && echo "Depends: $TERMUX_SUBPKG_DEPENDS" >> control test ! -z "$TERMUX_SUBPKG_CONFLICTS" && echo "Conflicts: $TERMUX_SUBPKG_CONFLICTS" >> control - $TERMUX_TAR -cJf "$SUB_PKG_PACKAGE_DIR/control.tar.xz" . + test ! -z "$TERMUX_SUBPKG_REPLACES" && echo "Replaces: $TERMUX_SUBPKG_REPLACES" >> control + tar -cJf "$SUB_PKG_PACKAGE_DIR/control.tar.xz" . + + for f in $TERMUX_SUBPKG_CONFFILES; do echo "$TERMUX_PREFIX/$f" >> conffiles; done # Create the actual .deb file: TERMUX_SUBPKG_DEBFILE=$TERMUX_DEBDIR/${SUB_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${SUB_PKG_ARCH}.deb @@ -919,10 +1125,16 @@ termux_step_post_massage() { termux_step_create_datatar() { # Create data tarball containing files to package: cd "$TERMUX_PKG_MASSAGEDIR" + + local HARDLINKS="$(find . -type f -links +1)" + if [ -n "$HARDLINKS" ]; then + termux_error_exit "Package contains hard links: $HARDLINKS" + fi + if [ -z "${TERMUX_PKG_METAPACKAGE+x}" ] && [ "$(find . -type f)" = "" ]; then termux_error_exit "No files in package" fi - $TERMUX_TAR -cJf "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" . + tar -cJf "$TERMUX_PKG_PACKAGEDIR/data.tar.xz" . } termux_step_create_debscripts() { @@ -948,9 +1160,11 @@ termux_step_create_debfile() { Description: $TERMUX_PKG_DESCRIPTION Homepage: $TERMUX_PKG_HOMEPAGE HERE + test ! -z "$TERMUX_PKG_BREAKS" && echo "Breaks: $TERMUX_PKG_BREAKS" >> DEBIAN/control 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 + test ! -z "$TERMUX_PKG_RECOMMENDS" && echo "Recommends: $TERMUX_PKG_RECOMMENDS" >> DEBIAN/control test ! -z "$TERMUX_PKG_REPLACES" && echo "Replaces: $TERMUX_PKG_REPLACES" >> DEBIAN/control # Create DEBIAN/conffiles (see https://www.debian.org/doc/debian-policy/ap-pkg-conffiles.html): @@ -962,7 +1176,7 @@ termux_step_create_debfile() { termux_step_create_debscripts # Create control.tar.xz - $TERMUX_TAR -cJf "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" . + tar -cJf "$TERMUX_PKG_PACKAGEDIR/control.tar.xz" . test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary" TERMUX_PKG_DEBFILE=$TERMUX_DEBDIR/${TERMUX_PKG_NAME}_${TERMUX_PKG_FULLVERSION}_${TERMUX_ARCH}.deb @@ -992,7 +1206,8 @@ termux_step_post_extract_package termux_step_handle_hostbuild termux_step_setup_toolchain termux_step_patch_package -cd "$TERMUX_PKG_BUILDDIR" +termux_step_replace_guess_scripts +cd "$TERMUX_PKG_SRCDIR" termux_step_pre_configure cd "$TERMUX_PKG_BUILDDIR" termux_step_configure