termux_download() {
local URL="$1"
local DESTINATION="$2"
+
+ if [ -f "$DESTINATION" ] && [ $# = 3 ] && [ -n "$3" ]; then
+ # Keep existing file if checksum matches.
+ local EXISTING_CHECKSUM
+ EXISTING_CHECKSUM=$(sha256sum "$DESTINATION" | cut -f 1 -d ' ')
+ if [ "$EXISTING_CHECKSUM" = "$3" ]; then return; fi
+ fi
+
local TMPFILE
TMPFILE=$(mktemp "$TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX")
echo "Downloading ${URL}"
termux_error_exit "Unsupported arch: $TERMUX_ARCH"
fi
- local TERMUX_GO_VERSION=go1.8rc3
+ local TERMUX_GO_VERSION=go1.8.3
local TERMUX_GO_PLATFORM=linux-amd64
local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}
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
+ 1862f4c3d3907e59b04a757cfda0ea7aa9ef39274af99a784f5be843c80c6772
+
( 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 cmake.
termux_setup_cmake() {
- local TERMUX_CMAKE_MAJORVESION=3.7
- local TERMUX_CMAKE_MINORVERSION=2
+ local TERMUX_CMAKE_MAJORVESION=3.8
+ local TERMUX_CMAKE_MINORVERSION=1
local TERMUX_CMAKE_VERSION=$TERMUX_CMAKE_MAJORVESION.$TERMUX_CMAKE_MINORVERSION
local TERMUX_CMAKE_TARNAME=cmake-${TERMUX_CMAKE_VERSION}-Linux-x86_64.tar.gz
local TERMUX_CMAKE_TARFILE=$TERMUX_PKG_TMPDIR/$TERMUX_CMAKE_TARNAME
if [ ! -d "$TERMUX_CMAKE_FOLDER" ]; then
termux_download https://cmake.org/files/v$TERMUX_CMAKE_MAJORVESION/$TERMUX_CMAKE_TARNAME \
"$TERMUX_CMAKE_TARFILE" \
- 0e6ec35d4fa9bf79800118916b51928b6471d5725ff36f1d0de5ebb34dcd5406
+ 10ca0e25b7159a03da0c1ec627e686562dc2a40aad5985fd2088eb684b08e491
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" \
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
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_ANDROID_BUILD_TOOLS_VERSION:="25.0.3"}"
+ : "${TERMUX_NDK_VERSION:="14"}"
if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then
TERMUX_ARCH_BITS=64
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"
+ TERMUX_STANDALONE_TOOLCHAIN+="-v17"
- export TERMUX_TAR="tar"
- export TERMUX_TOUCH="touch"
export prefix=${TERMUX_PREFIX}
export PREFIX=${TERMUX_PREFIX}
export PKG_CONFIG_LIBDIR=$TERMUX_PREFIX/lib/pkgconfig
# 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
local filename
filename=$(basename "$TERMUX_PKG_SRCURL")
local file="$TERMUX_PKG_CACHEDIR/$filename"
- test ! -f "$file" && termux_download "$TERMUX_PKG_SRCURL" "$file" "$TERMUX_PKG_SHA256"
+ 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
if [ "${file##*.}" = zip ]; then
unzip -q "$file"
else
- $TERMUX_TAR xf "$file"
+ tar xf "$file"
fi
mv $folder "$TERMUX_PKG_SRCDIR"
}
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} $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include
- $TERMUX_ELF_CLEANER usr/lib/*.so
+ # Remove <sys/shm.h> from the NDK in favour of that from the libandroid-shmem.
+ # Also remove <sys/sem.h> as it doesn't work for non-root.
+ rm $_TERMUX_TOOLCHAIN_TMPDIR/sysroot/usr/include/sys/{shm.h,sem.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.
_STL_LIBFILE=$TERMUX_STANDALONE_TOOLCHAIN/${TERMUX_HOST_PLATFORM}/lib64/libgnustl_shared.so
fi
cp "$_STL_LIBFILE" .
+ $STRIP --strip-unneeded libgnustl_shared.so
+ $TERMUX_ELF_CLEANER libgnustl_shared.so
ln -f -s libgnustl_shared.so libstdc++.so
fi
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" '{}' \;
}
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"
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
- # <https://github.com/termux/termux-packages/issues/76>.
- 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_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_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"
+
+ # 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 \
$DISABLE_NLS \
$ENABLE_SHARED \
$DISABLE_STATIC \
- --libexecdir=$TERMUX_PREFIX/libexec
+ $LIBEXEC_FLAG
}
termux_step_configure_cmake () {
# 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" -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"
}
# 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
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"
local SUB_PKG_DIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/subpackages/$SUB_PKG_NAME
local TERMUX_SUBPKG_DEPENDS=""
local TERMUX_SUBPKG_CONFLICTS=""
+ 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"
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
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" .
+ 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
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() {
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
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