Add rpath-link parameter for aarch64 build
[termux-packages] / build-package.sh
index d950d67..eb65dc5 100755 (executable)
@@ -43,7 +43,7 @@ if [ $TERMUX_ARCH = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}e
 : ${TERMUX_GCC_VERSION:="4.9"}
 : ${TERMUX_API_LEVEL:="21"}
 : ${TERMUX_STANDALONE_TOOLCHAIN:="$HOME/lib/android-standalone-toolchain-${TERMUX_ARCH}-api${TERMUX_API_LEVEL}-gcc${TERMUX_GCC_VERSION}"}
-: ${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="22.0.1"}
+: ${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="23.0.0"}
 # We do not put all of build-tools/$TERMUX_ANDROID_BUILD_TOOLS_VERSION/ into PATH
 # to avoid stuff like arm-linux-androideabi-ld there to conflict with ones from
 # the standalone toolchain.
@@ -99,6 +99,9 @@ if [ "$TERMUX_ARCH" = "arm" ]; then
 elif [ $TERMUX_ARCH = "i686" ]; then
        # From $NDK/docs/CPU-ARCH-ABIS.html:
        CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse"
+elif [ $TERMUX_ARCH = "aarch64" ]; then
+       LDFLAGS+=" -Wl,-rpath-link,$TERMUX_PREFIX/lib"
+       LDFLAGS+=" -Wl,-rpath-link,$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib"
 fi
 
 if [ -n "$TERMUX_DEBUG" ]; then
@@ -175,7 +178,9 @@ TERMUX_PKG_FOLDERNAME=""
 TERMUX_PKG_KEEP_STATIC_LIBRARIES="false"
 TERMUX_PKG_KEEP_HEADER_FILES="false"
 TERMUX_PKG_ESSENTIAL=""
+TERMUX_PKG_CONFLICTS="" # https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts
 TERMUX_PKG_CONFFILES=""
+TERMUX_PKG_INCLUDE_IN_DEVPACKAGE=""
 # Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR:
 TERMUX_PKG_HOSTBUILD=""
 TERMUX_PKG_MAINTAINER="Fredrik Fornwall <fredrik@fornwall.net>"
@@ -239,8 +244,9 @@ HERE
 fi
 
 TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner
-if [ ! -f $TERMUX_ELF_CLEANER ]; then
-       g++ -std=c++11 -Wall -Wextra -pedantic -Os $TERMUX_SCRIPTDIR/packages/termux-tools/termux-elf-cleaner.cpp -o $TERMUX_ELF_CLEANER
+TERMUX_ELF_CLEANER_SRC=$TERMUX_SCRIPTDIR/packages/termux-tools/termux-elf-cleaner.cpp
+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
 
 # Keep track of when build started so we can see what files have been created
@@ -336,7 +342,12 @@ termux_step_configure () {
        set -e -o pipefail
        export PATH=$TERMUX_PKG_TMPDIR/config-scripts:$PATH
 
-       $TERMUX_PKG_SRCDIR/configure \
+       # 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"
+
+       env $AVOID_AUTOCONF_WRAPPERS $TERMUX_PKG_SRCDIR/configure \
                --disable-dependency-tracking \
                --prefix=$TERMUX_PREFIX \
                 --disable-rpath --disable-rpath-hack \
@@ -423,13 +434,13 @@ termux_step_massage () {
        if [ "$TERMUX_DEBUG" = "" ]; then
                 find . -type f | xargs file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | xargs $STRIP --strip-unneeded --preserve-dates -R '.gnu.version*'
        fi
-        # Remove DT_ entries which the android 5.1 linker warns about:
-        find . -type f | xargs $TERMUX_ELF_CLEANER
         # Fix shebang paths:
         for file in `find . -type f`; do
                 head -c 100 $file | grep -E "^#\!.*\\/bin\\/.*" | grep -q -E -v "^#\! ?\\/system" && sed --follow-symlinks -i -E "s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" $file
         done
        set -e -o pipefail
+        # Remove DT_ entries which the android 5.1 linker warns about:
+        find . -type f -print0 | xargs -0 $TERMUX_ELF_CLEANER
 
        test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL
 
@@ -439,7 +450,7 @@ termux_step_massage () {
         if [ -d include -a -z "${TERMUX_PKG_NO_DEVELSPLIT}" ]; then
                 # Add virtual -dev sub package if there are include files:
                 _DEVEL_SUBPACKAGE_FILE=$TERMUX_PKG_TMPDIR/${TERMUX_PKG_NAME}-dev.subpackage.sh
-                echo TERMUX_SUBPKG_INCLUDE=\"include share/man/man3 lib/pkgconfig share/aclocal\" > $_DEVEL_SUBPACKAGE_FILE
+                echo TERMUX_SUBPKG_INCLUDE=\"include share/man/man3 lib/pkgconfig share/aclocal $TERMUX_PKG_INCLUDE_IN_DEVPACKAGE\" > $_DEVEL_SUBPACKAGE_FILE
                 echo TERMUX_SUBPKG_DESCRIPTION=\"Development files for ${TERMUX_PKG_NAME}\" >> $_DEVEL_SUBPACKAGE_FILE
                 echo TERMUX_SUBPKG_DEPENDS=\"$TERMUX_PKG_NAME\" >> $_DEVEL_SUBPACKAGE_FILE
         fi
@@ -608,7 +619,9 @@ cd $TERMUX_PKG_BUILDDIR
 termux_step_post_make_install
 cd $TERMUX_PKG_MASSAGEDIR
 termux_step_extract_into_massagedir
+cd $TERMUX_PKG_MASSAGEDIR
 termux_step_massage
+cd $TERMUX_PKG_MASSAGEDIR/$TERMUX_PREFIX
 termux_step_post_massage
 
 # Create data tarball containing files to package:
@@ -640,6 +653,7 @@ Homepage: $TERMUX_PKG_HOMEPAGE
 HERE
 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
 
 # Create DEBIAN/conffiles (see https://www.debian.org/doc/debian-policy/ap-pkg-conffiles.html):
 for f in $TERMUX_PKG_CONFFILES; do echo $TERMUX_PREFIX/$f >> DEBIAN/conffiles; done