if [ ! -d "$NDK" ]; then echo 'ERROR: $NDK not defined as pointing at a directory - define it pointing at a android NDK installation!'; exit 1; fi
: ${TERMUX_MAKE_PROCESSES:='4'}
: ${TERMUX_TOPDIR:="$HOME/termux"}
-: ${TERMUX_ARCH:="arm"} # (arm|aarch64|i686|x86_64) - the 64 bit variants do not work yet
+: ${TERMUX_ARCH:="arm"} # (arm|aarch64|i686|x86_64) - the x86_64 arch is not yet used or tested.
TERMUX_ARCH_BITS="32"
if [ "x86_64" = $TERMUX_ARCH -o "aarch64" = $TERMUX_ARCH ]; then
TERMUX_ARCH_BITS="64"
fi
+: ${TERMUX_CLANG:=""} # Set to non-empty to use clang.
: ${TERMUX_HOST_PLATFORM:="${TERMUX_ARCH}-linux-android"}
if [ $TERMUX_ARCH = "arm" ]; then TERMUX_HOST_PLATFORM="${TERMUX_HOST_PLATFORM}eabi"; fi
: ${TERMUX_PREFIX:='/data/data/com.termux/files/usr'}
: ${TERMUX_ANDROID_HOME:='/data/data/com.termux/files/home'}
: ${TERMUX_DEBUG:=""}
: ${TERMUX_PROCESS_DEB:=""}
-: ${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:="23.0.2"}
+if [ "$TERMUX_CLANG" = "" ]; then
+ : ${TERMUX_STANDALONE_TOOLCHAIN:="$HOME/lib/android-standalone-toolchain-${TERMUX_ARCH}-api${TERMUX_API_LEVEL}-gcc4.9"}
+else
+ : ${TERMUX_STANDALONE_TOOLCHAIN:="$HOME/lib/android-standalone-toolchain-${TERMUX_ARCH}-api${TERMUX_API_LEVEL}-clang38"}
+fi
+: ${TERMUX_ANDROID_BUILD_TOOLS_VERSION:="23.0.3"}
# 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.
test `uname` = "Darwin" && TERMUX_TOUCH=gtouch
# Compute NDK version. We remove the first character (the r in e.g. r9d) to get a version number which can be used in packages):
-export TERMUX_NDK_VERSION=`cut -d ' ' -f 1 $NDK/RELEASE.TXT | cut -c 2-`
+export TERMUX_NDK_VERSION=11
+if grep -s -q "Pkg.Revision = $TERMUX_NDK_VERSION" $NDK/source.properties; then
+ :
+else
+ echo "Wrong NDK version - we need $TERMUX_NDK_VERSION"
+ exit 1
+fi
export prefix=${TERMUX_PREFIX} # prefix is used by some makefiles
#export ACLOCAL="aclocal -I $TERMUX_PREFIX/share/aclocal"
export AR=$TERMUX_HOST_PLATFORM-ar
-export AS=${TERMUX_HOST_PLATFORM}-gcc
-export CC=$TERMUX_HOST_PLATFORM-gcc
+if [ "$TERMUX_CLANG" = "" ]; then
+ export AS=${TERMUX_HOST_PLATFORM}-gcc
+ export CC=$TERMUX_HOST_PLATFORM-gcc
+ export CXX=$TERMUX_HOST_PLATFORM-g++
+ _SPECSFLAG="-specs=$TERMUX_SCRIPTDIR/termux.spec"
+else
+ export AS=${TERMUX_HOST_PLATFORM}-gcc
+ export CC=$TERMUX_HOST_PLATFORM-clang
+ export CXX=$TERMUX_HOST_PLATFORM-clang++
+ # TODO: clang does not have specs file, how to ensure pie
+ # binaries gets built?
+ _SPECSFLAG=""
+fi
export CPP=${TERMUX_HOST_PLATFORM}-cpp
-export CXX=$TERMUX_HOST_PLATFORM-g++
export CC_FOR_BUILD=gcc
export LD=$TERMUX_HOST_PLATFORM-ld
export OBJDUMP=$TERMUX_HOST_PLATFORM-objdump
export READELF=$TERMUX_HOST_PLATFORM-readelf
export STRIP=$TERMUX_HOST_PLATFORM-strip
-_SPECSFLAG="-specs=$TERMUX_SCRIPTDIR/termux.spec"
export CFLAGS="$_SPECSFLAG"
export LDFLAGS="$_SPECSFLAG -L${TERMUX_PREFIX}/lib"
if [ "$TERMUX_ARCH" = "arm" ]; then
- # For hard support: http://blog.alexrp.com/2014/02/18/android-hard-float-support/
- # "First, to utilize the hard float ABI, you must either compile every last component of your application
- # as hard float (the -mhard-float GCC/Clang switch), or mark individual functions with the appropriate
- # __attribute__ to indicate the desired ABI. For example, to mark a function so that it’s called with the
- # soft float ABI, stick __attribute__((pcs("aapcs"))) on it.
- # Note that the NDK will link to a libm which uses the aforementioned attribute on all of its functions.
- # This means that if you use libm functions a lot, you’re not likely to get much of a boost in those places.
- # The way to fix this is to add -mhard-float -D_NDK_MATH_NO_SOFTFP=1 to your GCC/Clang command line. Then
- # add -lm_hard to your linker command line (or -Wl,-lm_hard if you just invoke GCC/Clang to link). This will
- # make your application link statically to a libm compiled for the hard float ABI. The only downside of this
- # is that your application will increase somewhat in size."
- CFLAGS+=" -march=armv7-a -mfpu=neon -mhard-float -Wl,--no-warn-mismatch"
- LDFLAGS+=" -march=armv7-a -Wl,--no-warn-mismatch"
+ CFLAGS+=" -march=armv7-a -mfpu=neon -mfloat-abi=softfp"
+ # "first flag instructs the linker to pick libgcc.a, libgcov.a, and
+ # crt*.o, which are tailored for armv7-a"
+ # - https://developer.android.com/ndk/guides/standalone_toolchain.html
+ LDFLAGS+=" -march=armv7-a -Wl,--fix-cortex-a8"
elif [ $TERMUX_ARCH = "i686" ]; then
# From $NDK/docs/CPU-ARCH-ABIS.html:
CFLAGS+=" -march=i686 -msse3 -mstackrealign -mfpmath=sse"
else
_TERMUX_NDK_TOOLCHAIN_NAME="$TERMUX_HOST_PLATFORM"
fi
- bash $NDK/build/tools/make-standalone-toolchain.sh --platform=android-$TERMUX_API_LEVEL --toolchain=${_TERMUX_NDK_TOOLCHAIN_NAME}-${TERMUX_GCC_VERSION} \
- --install-dir=$TERMUX_STANDALONE_TOOLCHAIN --system=`uname | tr '[:upper:]' '[:lower:]'`-x86_64
+
+ if [ "$TERMUX_CLANG" = "" ]; then
+ _TERMUX_TOOLCHAIN="${_TERMUX_NDK_TOOLCHAIN_NAME}-4.9"
+ else
+ _TERMUX_TOOLCHAIN="${_TERMUX_NDK_TOOLCHAIN_NAME}-clang"
+ fi
+ bash $NDK/build/tools/make-standalone-toolchain.sh --platform=android-$TERMUX_API_LEVEL --toolchain=${_TERMUX_TOOLCHAIN} \
+ --install-dir=$TERMUX_STANDALONE_TOOLCHAIN
if [ "arm" = $TERMUX_ARCH ]; then
# Fix to allow e.g. <bits/c++config.h> to be included:
- cp $TERMUX_STANDALONE_TOOLCHAIN/include/c++/$TERMUX_GCC_VERSION/arm-linux-androideabi/armv7-a/bits/* $TERMUX_STANDALONE_TOOLCHAIN/include/c++/$TERMUX_GCC_VERSION/bits
+ cp $TERMUX_STANDALONE_TOOLCHAIN/include/c++/4.9/arm-linux-androideabi/armv7-a/bits/* $TERMUX_STANDALONE_TOOLCHAIN/include/c++/4.9/bits
fi
cd $TERMUX_STANDALONE_TOOLCHAIN/sysroot
for f in $TERMUX_SCRIPTDIR/ndk_patches/*.patch; do
patch -p1;
echo "PATCHING FILE $f done!"
done
- # sha1.h was removed from android ndk for platforms above 19, but needed by the aapt package
- # JNIHelp.h is also used by aapt
- # sysexits.h is header-only and used by some unix code
- cp $TERMUX_SCRIPTDIR/ndk_patches/{sha1.h,sysexits.h,JNIHelp.h} $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include
+ # 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_STANDALONE_TOOLCHAIN/sysroot/usr/include
fi
export TERMUX_COMMON_CACHEDIR="$TERMUX_TOPDIR/_cache"
echo $TERMUX_ARCH > $TERMUX_ARCH_FILE
# Ensure folders present (but not $TERMUX_PKG_SRCDIR, it will be created in build)
-mkdir -p $TERMUX_PKG_BUILDDIR $TERMUX_PKG_PACKAGEDIR $TERMUX_PKG_TMPDIR $TERMUX_PKG_CACHEDIR $TERMUX_PKG_MASSAGEDIR $PKG_CONFIG_LIBDIR $TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp}
+mkdir -p $TERMUX_PKG_BUILDDIR $TERMUX_PKG_PACKAGEDIR $TERMUX_PKG_TMPDIR $TERMUX_PKG_CACHEDIR $TERMUX_PKG_MASSAGEDIR $PKG_CONFIG_LIBDIR $TERMUX_PREFIX/{bin,etc,lib,libexec,share,tmp,include}
# 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:
fi
TERMUX_ELF_CLEANER=$TERMUX_COMMON_CACHEDIR/termux-elf-cleaner
-TERMUX_ELF_CLEANER_SRC=$TERMUX_SCRIPTDIR/packages/termux-tools/termux-elf-cleaner.cpp
+TERMUX_ELF_CLEANER_SRC=$TERMUX_SCRIPTDIR/packages/termux-elf-cleaner/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
cd $TERMUX_PKG_SRCDIR
# Suffix patch with ".patch32" or ".patch64" to only apply for these bitnesses:
for patch in $TERMUX_PKG_BUILDER_DIR/*.patch{$TERMUX_ARCH_BITS,}; do
- test -f $patch && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $patch | patch -p1
+ test -f $patch && sed "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" $patch | \
+ sed "s%\@TERMUX_HOME\@%${TERMUX_ANDROID_HOME}%g" | \
+ patch -p1
done
find . -name config.sub -exec chmod u+w '{}' \; -exec cp $TERMUX_COMMON_CACHEDIR/config.sub '{}' \;
# <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"
env $AVOID_AUTOCONF_WRAPPERS $TERMUX_PKG_SRCDIR/configure \
--disable-dependency-tracking \
# Remove lib/charset.alias which is installed by gettext-using packages:
rm -f lib/charset.alias
+
# Remove non-english man pages:
test -d share/man && (cd share/man; for f in `ls | grep -v man`; do rm -Rf $f; done )
- # Remove info pages and other docs:
- rm -Rf share/info share/doc share/locale
+
+ if [ -z ${TERMUX_PKG_KEEP_INFOPAGES+x} ]; then
+ # Remove info pages:
+ rm -Rf share/info
+ fi
+
+ # Remove other docs:
+ rm -Rf share/doc share/locale
+
# Remove old kept libraries (readline):
find . -name '*.old' -delete
- # .. remove static libraries:
+
+ # Remove static libraries:
if [ $TERMUX_PKG_KEEP_STATIC_LIBRARIES = "false" ]; then
find . -name '*.a' -delete
find . -name '*.la' -delete
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
# 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
+ 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
set -e -o pipefail
# Remove DT_ entries which the android 5.1 linker warns about:
- find . -type f -print0 | xargs -0 $TERMUX_ELF_CLEANER
+ if [ "$TERMUX_DEBUG" = "" ]; then
+ find . -type f -print0 | xargs -0 $TERMUX_ELF_CLEANER
+ fi
test ! -z "$TERMUX_PKG_RM_AFTER_INSTALL" && rm -Rf $TERMUX_PKG_RM_AFTER_INSTALL
for includeset in $TERMUX_SUBPKG_INCLUDE; do
_INCLUDE_DIRSET=`dirname $includeset`
test "$_INCLUDE_DIRSET" = "." && _INCLUDE_DIRSET=""
- if [ -e $includeset ]; then
+ if [ -e $includeset -o -L $includeset ]; then
+ # Add the -L clause to handle relative symbolic links:
mkdir -p $SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET
mv $includeset $SUB_PKG_MASSAGE_DIR/$_INCLUDE_DIRSET
fi
exit 1
fi
- local TERMUX_GO_VERSION=go1.6beta2
+ local TERMUX_GO_VERSION=go1.6.2
local TERMUX_GO_PLATFORM=linux-amd64
test `uname` = "Darwin" && TERMUX_GO_PLATFORM=darwin-amd64