preload-hacks: Some patches to make it work.
[termux-packages] / build-package.sh
index b02d1e6..6da765f 100755 (executable)
@@ -8,6 +8,10 @@ termux_error_exit() {
        exit 1
 }
 
+if [ `uname -o` = Android ]; then
+       termux_error_exit "On-device builds are not supported - see README.md"
+fi
+
 # Utility function to download a resource, optionally checking against a checksum.
 termux_download() {
        local URL="$1"
@@ -70,7 +74,7 @@ termux_setup_golang() {
                termux_error_exit "Unsupported arch: $TERMUX_ARCH"
        fi
 
-       local TERMUX_GO_VERSION=go1.9
+       local TERMUX_GO_VERSION=go1.10.2
        local TERMUX_GO_PLATFORM=linux-amd64
 
        local TERMUX_BUILDGO_FOLDER=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}
@@ -82,44 +86,45 @@ termux_setup_golang() {
        local TERMUX_BUILDGO_TAR=$TERMUX_COMMON_CACHEDIR/${TERMUX_GO_VERSION}.${TERMUX_GO_PLATFORM}.tar.gz
        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" \
-                       d70eadefce8e160638a9a6db97f7192d8463069ab33138893ad3bf31b0650a79
+               "$TERMUX_BUILDGO_TAR" \
+               4b677d698c65370afa33757b6954ade60347aaca310ea92a63ed717d7cb0c2ff
 
        ( 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.
+# Utility function to setup a current ninja build system.
 termux_setup_ninja() {
-       local NINJA_VERSION=1.7.2
+       local NINJA_VERSION=1.8.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
+                       d2fea9ff33b3ef353161ed906f260d565ca55b8ca0568fa07b1d2cab90a84a07
                unzip $NINJA_ZIP_FILE -d $NINJA_FOLDER
        fi
        export PATH=$NINJA_FOLDER:$PATH
 }
 
-# Utility function for cmake-built packages to setup a current meson.
+# Utility function to setup a current meson build system.
 termux_setup_meson() {
        termux_setup_ninja
-       local MESON_VERSION=0.42.0
-       local MESON_FOLDER=$TERMUX_COMMON_CACHEDIR/meson-$MESON_VERSION
+       local MESON_VERSION=0.45.1
+       local MESON_FOLDER=$TERMUX_COMMON_CACHEDIR/meson-$MESON_VERSION-v1
        if [ ! -d "$MESON_FOLDER" ]; then
                local MESON_TAR_NAME=meson-$MESON_VERSION.tar.gz
                local MESON_TAR_FILE=$TERMUX_PKG_TMPDIR/$MESON_TAR_NAME
+               local MESON_TMP_FOLDER=$TERMUX_PKG_TMPDIR/meson-$MESON_VERSION
                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)
+                       4d0bb0dbb1bb556cb7a4092fdfea3d6e76606bd739a4bc97481c2d7bc6200afb
+               tar xf "$MESON_TAR_FILE" -C "$TERMUX_PKG_TMPDIR"
+               mv $MESON_TMP_FOLDER $MESON_FOLDER
        fi
        TERMUX_MESON="$MESON_FOLDER/meson.py"
-       TERMUX_MESON_CROSSFILE=$TERMUX_COMMON_CACHEDIR/meson-crossfile-$TERMUX_ARCH-v1.txt
+       TERMUX_MESON_CROSSFILE=$TERMUX_COMMON_CACHEDIR/meson-crossfile-$TERMUX_ARCH-v2.txt
        if [ ! -f $TERMUX_MESON_CROSSFILE ]; then
                local MESON_CPU MESON_CPU_FAMILY
                if [ $TERMUX_ARCH = "arm" ]; then
@@ -144,7 +149,7 @@ termux_setup_meson() {
                        c = '$CC'
                        cpp = '$CXX'
                        ld = '$LD'
-                       pkg-config = '$PKG_CONFIG'
+                       pkgconfig = '$PKG_CONFIG'
                        strip = '$STRIP'
                        [properties]
                        needs_exe_wrapper = true
@@ -157,10 +162,10 @@ termux_setup_meson() {
        fi
 }
 
-# Utility function for cmake-built packages to setup a current cmake.
+# Utility function to setup a current cmake build system
 termux_setup_cmake() {
-       local TERMUX_CMAKE_MAJORVESION=3.9
-       local TERMUX_CMAKE_MINORVERSION=2
+       local TERMUX_CMAKE_MAJORVESION=3.11
+       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
@@ -168,7 +173,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" \
-                               f4e1e848e21c3fba134fbddd793860ba9a17c35d0aeaa3bd83149a6ec1bf9fbb
+                               3aa8d3b53903563bdc13dfec80716c286b2228db36ef65c23bc616f9bb930367
                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" \
@@ -185,22 +190,24 @@ termux_step_handle_arguments() {
 
        # Handle command-line arguments:
        _show_usage () {
-           echo "Usage: ./build-package.sh [-a ARCH] [-d] [-D] PACKAGE"
+           echo "Usage: ./build-package.sh [-a ARCH] [-d] [-D] [-f] [-q] [-s] PACKAGE"
            echo "Build a package by creating a .deb file in the debs/ folder."
            echo "  -a The architecture to build for: aarch64(default), arm, i686, x86_64 or all."
            echo "  -d Build with debug symbols."
            echo "  -D Build a disabled package in disabled-packages/."
            echo "  -f Force build even if package has already been built."
+           echo "  -q Quiet build"
            echo "  -s Skip dependency check."
            exit 1
        }
-       while getopts :a:hdDfs option; do
+       while getopts :a:hdDfqs option; do
                case "$option" in
                a) TERMUX_ARCH="$OPTARG";;
                h) _show_usage;;
                d) TERMUX_DEBUG=true;;
                D) local TERMUX_IS_DISABLED=true;;
                f) TERMUX_FORCE_BUILD=true;;
+               q) export TERMUX_QUIET_BUILD=true;;
                s) export TERMUX_SKIP_DEPCHECK=true;;
                ?) termux_error_exit "./build-package.sh: illegal option -$OPTARG";;
                esac
@@ -227,8 +234,6 @@ 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
@@ -254,8 +259,8 @@ termux_step_setup_variables() {
        : "${TERMUX_ANDROID_HOME:="/data/data/com.termux/files/home"}"
        : "${TERMUX_DEBUG:=""}"
        : "${TERMUX_PKG_API_LEVEL:="21"}"
-       : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="26.0.1"}"
-       : "${TERMUX_NDK_VERSION:="15.2"}"
+       : "${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="27.0.3"}"
+       : "${TERMUX_NDK_VERSION:="16"}"
 
        if [ "x86_64" = "$TERMUX_ARCH" ] || [ "aarch64" = "$TERMUX_ARCH" ]; then
                TERMUX_ARCH_BITS=64
@@ -309,7 +314,6 @@ termux_step_setup_variables() {
        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
@@ -365,7 +369,7 @@ termux_step_start_build() {
        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+="-v13"
+       TERMUX_STANDALONE_TOOLCHAIN+="-v3"
 
        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"
@@ -374,12 +378,10 @@ termux_step_start_build() {
 
        if [ -z "${TERMUX_SKIP_DEPCHECK:=""}" ]; then
                local p TERMUX_ALL_DEPS
-               TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_NAME")
+               TERMUX_ALL_DEPS=$(./scripts/buildorder.py "$TERMUX_PKG_BUILDER_DIR")
                for p in $TERMUX_ALL_DEPS; do
-                       if [ "$p" != "$TERMUX_PKG_NAME" ]; then
-                               echo "Building dependency $p if necessary..."
-                               ./build-package.sh -a $TERMUX_ARCH -s "$p"
-                       fi
+                       echo "Building dependency $p if necessary..."
+                       ./build-package.sh -a $TERMUX_ARCH -s "$p"
                done
        fi
 
@@ -389,6 +391,12 @@ termux_step_start_build() {
                TERMUX_PKG_FULLVERSION+="-$TERMUX_PKG_REVISION"
        fi
 
+       if [ "$TERMUX_DEBUG" == "true" ]; then
+               DEBUG="-dbg"
+       else
+               DEBUG=""
+       fi
+
        if [ -z "$TERMUX_DEBUG" ] &&
           [ -z "${TERMUX_FORCE_BUILD+x}" ] &&
           [ -e "/data/data/.built-packages/$TERMUX_PKG_NAME" ]; then
@@ -424,7 +432,7 @@ termux_step_start_build() {
        termux_download \
                https://raw.githubusercontent.com/termux/termux-elf-cleaner/v$TERMUX_ELF_CLEANER_VERSION/termux-elf-cleaner.cpp \
                $TERMUX_ELF_CLEANER_SRC \
-               11a38372f4d0e36b7556382c7ecffecae35cee8b68daaee2dbee025f758e17ee
+               62c3cf9813756a1b262108fbc39684c5cfd3f9a69b376276bb1ac6af138f5fa2
        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
@@ -469,19 +477,18 @@ termux_step_extract_package() {
        local file="$TERMUX_PKG_CACHEDIR/$filename"
        termux_download "$TERMUX_PKG_SRCURL" "$file" "$TERMUX_PKG_SHA256"
 
-       if [ "x$TERMUX_PKG_FOLDERNAME" = "x" ]; then
-               folder="${filename%%.t*}" && folder="${folder%%.zip}"
-               folder="${folder/_/-}" # dpkg uses _ in tar filename, but - in folder
-       else
-               folder=$TERMUX_PKG_FOLDERNAME
-       fi
-       rm -Rf $folder
+       local folder
+       set +o pipefail
        if [ "${file##*.}" = zip ]; then
+               folder=`unzip -qql "$file" | head -n1 | tr -s ' ' | cut -d' ' -f5-`
+               rm -Rf $folder
                unzip -q "$file"
+               mv $folder "$TERMUX_PKG_SRCDIR"
        else
-               tar xf "$file"
+               mkdir "$TERMUX_PKG_SRCDIR"
+               tar xf "$file" -C "$TERMUX_PKG_SRCDIR" --strip-components=1
        fi
-       mv $folder "$TERMUX_PKG_SRCDIR"
+       set -o pipefail
 }
 
 # Hook for packages to act just after the package has been extracted.
@@ -571,13 +578,17 @@ termux_step_setup_toolchain() {
        if [ -n "$TERMUX_DEBUG" ]; then
                CFLAGS+=" -g3 -O1 -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
        else
-               if [ "$TERMUX_PKG_CLANG" = "no" ] || [ "$TERMUX_PKG_NAME" = "ruby" -a "$TERMUX_ARCH" = arm ]; then
-                       # The exception for "ruby" and arm exception is to avoid -Oz for ruby, which causes
-                       # segmentation fault on 32-bit arm with NDK r15c and ruby 2.4.2 (#1520).
+               if [ "$TERMUX_PKG_CLANG" = "no" ]; then
                        CFLAGS+=" -Os"
                else
-                       # -Oz seems good for clang, see https://github.com/android-ndk/ndk/issues/133
-                       CFLAGS+=" -Oz"
+                       # -Oz seems good for clang, see https://github.com/android-ndk/ndk/issues/133.
+                       # However, on arm it has a lot of issues such as #1520, #1680, #1765 and
+                       # https://bugs.llvm.org/show_bug.cgi?id=35379, so use so use -Os there for now:
+                       if [ $TERMUX_ARCH = arm ]; then
+                               CFLAGS+=" -Os"
+                       else
+                               CFLAGS+=" -Oz"
+                       fi
                fi
        fi
 
@@ -663,13 +674,15 @@ termux_step_setup_toolchain() {
                                patch --silent -p1;
                done
                # 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
+               cp "$TERMUX_SCRIPTDIR"/ndk-patches/{elf.h,ifaddrs.h,libintl.h} usr/include
 
                # 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 usr/include/sys/{shm.h,sem.h}
+               # Remove <sys/sem.h> as it doesn't work for non-root.
+               # Remove <iconv.h> as we currently provide it from libandroid-support.
+               # Remove <glob.h> as we currently provide it from libandroid-glob.
+               # Remove <spawn.h> as it's only for future (later than android-27).
+               rm usr/include/sys/{shm.h,sem.h} usr/include/{iconv.h,glob.h,spawn.h}
 
                sed -i "s/define __ANDROID_API__ __ANDROID_API_FUTURE__/define __ANDROID_API__ $TERMUX_PKG_API_LEVEL/" \
                        usr/include/android/api-level.h
@@ -692,13 +705,13 @@ termux_step_setup_toolchain() {
 
        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 link to it,
+               # Setup libc++_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
                # We do however want to avoid installing this, to avoid problems where e.g.
                # libm.so on some i686 devices links against libstdc++.so.
-               # The libgnustl_shared.so library will be packaged in the libgnustl package
+               # The libc++_shared.so library will be packaged in the libc++ package
                # which is part of the base Termux installation.
                mkdir -p "$TERMUX_PREFIX/lib"
                cd "$TERMUX_PREFIX/lib"
@@ -766,30 +779,37 @@ termux_step_pre_configure() {
 termux_step_configure_autotools () {
        if [ ! -e "$TERMUX_PKG_SRCDIR/configure" ]; then return; fi
 
-       DISABLE_STATIC="--disable-static"
+       local DISABLE_STATIC="--disable-static"
        if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-static/}" ]; then
                # Do not --disable-static if package explicitly enables it (e.g. gdb needs enable-static to build)
                DISABLE_STATIC=""
        fi
 
-       DISABLE_NLS="--disable-nls"
+       local DISABLE_NLS="--disable-nls"
        if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--enable-nls/}" ]; then
                # Do not --disable-nls if package explicitly enables it (for gettext itself)
                DISABLE_NLS=""
        fi
 
-       ENABLE_SHARED="--enable-shared"
+       local ENABLE_SHARED="--enable-shared"
        if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--disable-shared/}" ]; then
                ENABLE_SHARED=""
        fi
-       HOST_FLAG="--host=$TERMUX_HOST_PLATFORM"
+
+       local HOST_FLAG="--host=$TERMUX_HOST_PLATFORM"
        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
+
+       local LIBEXEC_FLAG="--libexecdir=$TERMUX_PREFIX/libexec"
+       if [ "$TERMUX_PKG_EXTRA_CONFIGURE_ARGS" != "${TERMUX_PKG_EXTRA_CONFIGURE_ARGS/--libexecdir=/}" ]; then
+               LIBEXEC_FLAG=""
+       fi
+
+       local QUIET_BUILD=
+       if [ ! -z ${TERMUX_QUIET_BUILD+x} ]; then
+               QUIET_BUILD="--enable-silent-rules --silent --quiet"
+       fi
 
        # Some packages provides a $PKG-config script which some configure scripts pickup instead of pkg-config:
        mkdir "$TERMUX_PKG_TMPDIR/config-scripts"
@@ -826,6 +846,7 @@ termux_step_configure_autotools () {
        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_mknod_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"
@@ -858,7 +879,8 @@ termux_step_configure_autotools () {
                $DISABLE_NLS \
                $ENABLE_SHARED \
                $DISABLE_STATIC \
-               $LIBEXEC_FLAG
+               $LIBEXEC_FLAG \
+               $QUIET_BUILD
 }
 
 termux_step_configure_cmake () {
@@ -924,11 +946,16 @@ termux_step_post_configure () {
 }
 
 termux_step_make() {
+       local QUIET_BUILD=
+       if [ ! -z ${TERMUX_QUIET_BUILD+x} ]; then
+               QUIET_BUILD="-s"
+       fi
+
        if ls ./*akefile &> /dev/null; then
                if [ -z "$TERMUX_PKG_EXTRA_MAKE_ARGS" ]; then
-                       make -j $TERMUX_MAKE_PROCESSES
+                       make -j $TERMUX_MAKE_PROCESSES $QUIET_BUILD
                else
-                       make -j $TERMUX_MAKE_PROCESSES ${TERMUX_PKG_EXTRA_MAKE_ARGS}
+                       make -j $TERMUX_MAKE_PROCESSES $QUIET_BUILD ${TERMUX_PKG_EXTRA_MAKE_ARGS}
                fi
        fi
 }
@@ -943,7 +970,7 @@ termux_step_make_install() {
                        make -j 1 ${TERMUX_PKG_EXTRA_MAKE_ARGS} ${TERMUX_PKG_MAKE_INSTALL_TARGET}
                fi
        elif test -f build.ninja; then
-               ninja install
+               ninja -j $TERMUX_MAKE_PROCESSES install
        fi
 }
 
@@ -1080,7 +1107,7 @@ termux_step_massage() {
                mkdir -p DEBIAN
                cd DEBIAN
                cat > control <<-HERE
-                       Package: $SUB_PKG_NAME
+                       Package: $SUB_PKG_NAME$DEBUG
                        Architecture: ${SUB_PKG_ARCH}
                        Installed-Size: ${SUB_PKG_INSTALLSIZE}
                        Maintainer: $TERMUX_PKG_MAINTAINER
@@ -1096,7 +1123,7 @@ termux_step_massage() {
                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_SUBPKG_DEBFILE=$TERMUX_DEBDIR/${SUB_PKG_NAME}${DEBUG}_${TERMUX_PKG_FULLVERSION}_${SUB_PKG_ARCH}.deb
                test ! -f "$TERMUX_COMMON_CACHEDIR/debian-binary" && echo "2.0" > "$TERMUX_COMMON_CACHEDIR/debian-binary"
                ar cr "$TERMUX_SUBPKG_DEBFILE" \
                                   "$TERMUX_COMMON_CACHEDIR/debian-binary" \
@@ -1148,7 +1175,7 @@ termux_step_create_debfile() {
 
        mkdir -p DEBIAN
        cat > DEBIAN/control <<-HERE
-               Package: $TERMUX_PKG_NAME
+               Package: $TERMUX_PKG_NAME$DEBUG
                Architecture: ${TERMUX_ARCH}
                Installed-Size: ${TERMUX_PKG_INSTALLSIZE}
                Maintainer: $TERMUX_PKG_MAINTAINER
@@ -1175,7 +1202,7 @@ termux_step_create_debfile() {
        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_PKG_DEBFILE=$TERMUX_DEBDIR/${TERMUX_PKG_NAME}${DEBUG}_${TERMUX_PKG_FULLVERSION}_${TERMUX_ARCH}.deb
        # Create the actual .deb file:
        ar cr "$TERMUX_PKG_DEBFILE" \
               "$TERMUX_COMMON_CACHEDIR/debian-binary" \