add php-pgsql and php-fpm (#875)
[termux-packages] / build-package.sh
index d952d83..02e1cd0 100755 (executable)
@@ -183,7 +183,7 @@ termux_step_setup_variables() {
        : "${TERMUX_DEBUG:=""}"
        : "${TERMUX_API_LEVEL:="21"}"
        : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="25.0.1"}"
-       : "${TERMUX_NDK_VERSION:="13"}"
+       : "${TERMUX_NDK_VERSION:="14"}"
 
        if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then
                TERMUX_ARCH_BITS=64
@@ -218,7 +218,7 @@ termux_step_setup_variables() {
        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"
@@ -559,11 +559,18 @@ termux_step_setup_toolchain() {
                                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.
@@ -594,6 +601,8 @@ termux_step_setup_toolchain() {
                        _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
 
@@ -615,12 +624,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 +668,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"
@@ -709,7 +728,7 @@ termux_step_configure_autotools () {
                $DISABLE_NLS \
                $ENABLE_SHARED \
                $DISABLE_STATIC \
-               --libexecdir=$TERMUX_PREFIX/libexec
+               $LIBEXEC_FLAG
 }
 
 termux_step_configure_cmake () {
@@ -860,7 +879,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"
@@ -920,6 +939,8 @@ termux_step_massage() {
                test ! -z "$TERMUX_SUBPKG_CONFLICTS" && echo "Conflicts: $TERMUX_SUBPKG_CONFLICTS" >> control
                $TERMUX_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
                test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary"
@@ -946,6 +967,12 @@ 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
@@ -1019,6 +1046,7 @@ termux_step_post_extract_package
 termux_step_handle_hostbuild
 termux_step_setup_toolchain
 termux_step_patch_package
+termux_step_replace_guess_scripts
 cd "$TERMUX_PKG_BUILDDIR"
 termux_step_pre_configure
 cd "$TERMUX_PKG_BUILDDIR"