Minor comment cleanups of Dockerfile
[termux-packages] / build-package.sh
index 4e52fd9..f213e51 100755 (executable)
@@ -10,14 +10,14 @@ test -f $HOME/.termuxrc && . $HOME/.termuxrc
 : ${NDK:="${HOME}/lib/android-ndk"}
 : ${TERMUX_MAKE_PROCESSES:='4'}
 : ${TERMUX_TOPDIR:="$HOME/.termux-build"}
-: ${TERMUX_ARCH:="aarch64"} # (arm|aarch64|i686|x86_64) - the x86_64 arch is not yet used or tested.
+: ${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_PROCESS_DEB:=""}
 : ${TERMUX_API_LEVEL:="21"}
 : ${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="24.0.1"}
-: ${TERMUX_NDK_VERSION:="12"}
+: ${TERMUX_NDK_VERSION:="13"}
 
 # Handle command-line arguments:
 show_usage () {
@@ -68,7 +68,7 @@ fi
 
 # Handle 'all' arch:
 if [ $TERMUX_ARCH = 'all' ]; then
-       for arch in 'arm' 'i686' 'aarch64'; do
+       for arch in 'arm' 'i686' 'aarch64' 'x86_64'; do
                ./build-package.sh -a $arch $1
        done
        exit
@@ -123,7 +123,7 @@ TERMUX_PKG_INCLUDE_IN_DEVPACKAGE=""
 TERMUX_PKG_DEVPACKAGE_DEPENDS=""
 # Set if a host build should be done in TERMUX_PKG_HOSTBUILD_DIR:
 TERMUX_PKG_HOSTBUILD=""
-TERMUX_PKG_MAINTAINER="Fredrik Fornwall <fredrik@fornwall.net>"
+TERMUX_PKG_MAINTAINER="Fredrik Fornwall @fornwall"
 TERMUX_PKG_CLANG=no
 
 # Cleanup old state
@@ -161,7 +161,8 @@ termux_download() {
 
        TMPFILE=`mktemp $TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX`
        echo "Downloading ${URL}"
-       for i in 1 2 3 4 5 6; do
+       TRYMAX=6
+       for try in $(seq 1 $TRYMAX); do
                if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then
                        if [ $# = 3 ]; then
                                # Optional checksum argument:
@@ -173,7 +174,7 @@ termux_download() {
                        mv "$TMPFILE" "$DESTINATION"
                        return
                else
-                       echo "Download of $1 failed (attempt $i/3)" 1>&2
+                       echo "Download of $1 failed (attempt $try/$TRYMAX)" 1>&2
                        sleep 45
                fi
        done
@@ -182,17 +183,10 @@ termux_download() {
        exit 1
 }
 
-# Get fresh versions of config.sub and config.guess
-for f in config.sub config.guess; do
-       if [ ! -f $TERMUX_COMMON_CACHEDIR/$f ]; then
-               termux_download "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=${f};hb=HEAD" $TERMUX_COMMON_CACHEDIR/$f
-       fi
-done
-
 # Have a debian-binary file ready for deb packaging:
 test ! -f $TERMUX_COMMON_CACHEDIR/debian-binary && echo "2.0" > $TERMUX_COMMON_CACHEDIR/debian-binary
 # The host tuple that may be given to --host configure flag, but normally autodetected so not needed explicitly
-TERMUX_HOST_TUPLE=`sh $TERMUX_COMMON_CACHEDIR/config.guess`
+TERMUX_HOST_TUPLE=`sh $TERMUX_SCRIPTDIR/scripts/config.guess`
 
 # Make $TERMUX_PREFIX/bin/sh executable on the builder, so that build script can assume that it works
 # on both builder and host later on:
@@ -251,8 +245,8 @@ termux_step_patch_package () {
                        patch --silent -p1
        done
 
-       find . -name config.sub -exec chmod u+w '{}' \; -exec cp $TERMUX_COMMON_CACHEDIR/config.sub '{}' \;
-       find . -name config.guess -exec chmod u+w '{}' \; -exec cp $TERMUX_COMMON_CACHEDIR/config.guess '{}' \;
+       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 '{}' \;
 }
 
 termux_step_pre_configure () {
@@ -376,8 +370,12 @@ termux_step_massage () {
                rm -Rf share/info
        fi
 
-       # Remove other docs:
-       rm -Rf share/doc share/locale
+       # Remove locale files we're not interested in::
+       rm -Rf share/locale
+       if [ -z ${TERMUX_PKG_KEEP_SHARE_DOC+x} ]; then
+               # Remove info pages:
+               rm -Rf share/doc
+       fi
 
        # Remove old kept libraries (readline):
        find . -name '*.old' -delete
@@ -388,7 +386,7 @@ termux_step_massage () {
                find . -name '*.la' -delete
        fi
 
-       # .. move over sbin to bin
+       # 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.
@@ -399,15 +397,16 @@ termux_step_massage () {
                # Strip binaries. file(1) may fail for certain unusual files, so disable pipefail.
                set +e +o pipefail
                find . -type f | xargs -r file | grep -E "(executable|shared object)" | grep ELF | cut -f 1 -d : | \
-                       xargs -r $STRIP --strip-unneeded --preserve-dates -R '.gnu.version*'
+                       xargs -r $STRIP --strip-unneeded --preserve-dates
                set -e -o pipefail
-               # Remove DT_ entries which the android 5.1 linker warns about:
-               find . -type f -print0 | xargs -r -0 $TERMUX_ELF_CLEANER
        fi
-        # Fix shebang paths:
-        for file in `find -L . -type f`; do
-                head -c 100 $file | grep -E "^#\!.*\\/bin\\/.*" | grep -q -E -v "^#\! ?\\/system" && sed --follow-symlinks -i -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" $file
-        done
+       # Remove DT_ entries which the android 5.1 linker warns about:
+       find . -type f -print0 | xargs -r -0 $TERMUX_ELF_CLEANER
+
+       # Fix shebang paths:
+       for file in `find -L . -type f`; do
+               head -c 100 $file | grep -E "^#\!.*\\/bin\\/.*" | grep -q -E -v "^#\! ?\\/system" && sed --follow-symlinks -i -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" $file
+       done
 
        test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL
 
@@ -558,13 +557,8 @@ if [ "$TERMUX_PKG_BUILD_REVISION" != "0" -o "$TERMUX_PKG_FULLVERSION" != "${TERM
 fi
 
 # Compute standalone toolchain dir, bitness of arch and name of host platform:
-TERMUX_STANDALONE_TOOLCHAIN="$TERMUX_TOPDIR/_lib/toolchain-${TERMUX_ARCH}-ndk${TERMUX_NDK_VERSION}-api${TERMUX_API_LEVEL}-"
-if [ "$TERMUX_PKG_CLANG" = "no" ]; then
-       TERMUX_STANDALONE_TOOLCHAIN+="gcc4.9"
-else
-       TERMUX_STANDALONE_TOOLCHAIN+="clang38"
-fi
-# Bump the below version if a change is made in toolchain setup, to ensure
+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+="-v1"
 
@@ -626,7 +620,7 @@ else
 fi
 
 if [ -n "$TERMUX_DEBUG" ]; then
-        CFLAGS+=" -g3 -Og -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
+        CFLAGS+=" -g3 -O1 -fstack-protector --param ssp-buffer-size=4 -D_FORTIFY_SOURCE=2"
 else
         CFLAGS+=" -Os"
 fi
@@ -639,41 +633,41 @@ export ac_cv_func_getpwnam=no
 export ac_cv_func_getpwuid=no
 
 if [ ! -d $TERMUX_STANDALONE_TOOLCHAIN ]; then
-       # See https://developer.android.com/ndk/guides/standalone_toolchain.html about toolchain naming.
-       if [ "i686" = $TERMUX_ARCH ]; then
-               _TERMUX_NDK_TOOLCHAIN_NAME="x86"
-       elif [ "x86_64" = $TERMUX_ARCH ]; then
-               _TERMUX_NDK_TOOLCHAIN_NAME="x86_64"
-       else
-               _TERMUX_NDK_TOOLCHAIN_NAME="$TERMUX_HOST_PLATFORM"
-       fi
-
-       if [ "$TERMUX_PKG_CLANG" = "" ]; then
-               _TERMUX_TOOLCHAIN="${_TERMUX_NDK_TOOLCHAIN_NAME}-4.9"
-       else
-               _TERMUX_TOOLCHAIN="${_TERMUX_NDK_TOOLCHAIN_NAME}-clang"
-       fi
-
        # Do not put toolchain in place until we are done with setup, to avoid having a half setup
        # toolchain left in place if something goes wrong (or process is just aborted):
        _TERMUX_TOOLCHAIN_TMPDIR=${TERMUX_STANDALONE_TOOLCHAIN}-tmp
        rm -Rf $_TERMUX_TOOLCHAIN_TMPDIR
 
-       bash $NDK/build/tools/make-standalone-toolchain.sh --platform=android-$TERMUX_API_LEVEL --toolchain=${_TERMUX_TOOLCHAIN} \
-               --install-dir=$_TERMUX_TOOLCHAIN_TMPDIR
-        if [ "arm" = $TERMUX_ARCH ]; then
-                # Fix to allow e.g. <bits/c++config.h> 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
-        fi
+       _NDK_ARCHNAME=$TERMUX_ARCH
+       if [ $TERMUX_ARCH = "aarch64" ]; then
+               _NDK_ARCHNAME=arm64
+       elif [ $TERMUX_ARCH = "i686" ]; then
+               _NDK_ARCHNAME=x86
+       fi
+       $NDK/build/tools/make_standalone_toolchain.py \
+               --api $TERMUX_API_LEVEL \
+               --arch $_NDK_ARCHNAME \
+               --install-dir $_TERMUX_TOOLCHAIN_TMPDIR
+
+       if [ "arm" = $TERMUX_ARCH ]; then
+               # Fix to allow e.g. <bits/c++config.h> 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
+       fi
+
        cd $_TERMUX_TOOLCHAIN_TMPDIR/sysroot
+
        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.
+       # 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
+
+       $TERMUX_ELF_CLEANER usr/lib/libc.so
+
        mv $_TERMUX_TOOLCHAIN_TMPDIR $TERMUX_STANDALONE_TOOLCHAIN
 fi
 
@@ -698,31 +692,26 @@ if [ ! -f $TERMUX_PREFIX/lib/libstdc++.so ]; then
        ln -f -s libgnustl_shared.so libstdc++.so
 fi
 
-if [ ! -f $PKG_CONFIG ]; then
-       echo "Creating pkg-config wrapper..."
-       # We use path to host pkg-config to avoid picking up a cross-compiled pkg-config later on
-       _HOST_PKGCONFIG=`which pkg-config`
-       mkdir -p $TERMUX_STANDALONE_TOOLCHAIN/bin $PKG_CONFIG_LIBDIR
-       cat > $PKG_CONFIG <<HERE
+# Create pkg-config wrapper. We use path to host pkg-config to
+# avoid picking up a cross-compiled pkg-config later on.
+_HOST_PKGCONFIG=`which pkg-config`
+mkdir -p $TERMUX_STANDALONE_TOOLCHAIN/bin $PKG_CONFIG_LIBDIR
+cat > $PKG_CONFIG <<HERE
 #!/bin/sh
 export PKG_CONFIG_DIR=
 export PKG_CONFIG_LIBDIR=$PKG_CONFIG_LIBDIR
-# export PKG_CONFIG_SYSROOT_DIR=${TERMUX_PREFIX}
 exec $_HOST_PKGCONFIG "\$@"
 HERE
-       chmod +x $PKG_CONFIG
-
-       # Add a pkg-config file for the system zlib
-       cat > $PKG_CONFIG_LIBDIR/zlib.pc <<HERE
+chmod +x $PKG_CONFIG
+# Add a pkg-config file for the system zlib
+cat > $PKG_CONFIG_LIBDIR/zlib.pc <<HERE
 Name: zlib
 Description: zlib compression library
 Version: 1.2.3
 
 Requires:
-Libs: -L$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib -lz
-Cflags: -I$TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include
+Libs: -lz
 HERE
-fi
 
 # Keep track of when build started so we can see what files have been created.
 # We start by sleeping so that any generated files above (such as zlib.pc) get