diff --git a/README.md b/README.md index ab22a53..c7639f7 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,27 @@ libiconv-libicu-android ======================= +## Swift android instructions + +Follow the original instructions, but instead of step (3), run ./build-android.sh instead + + +## Original instructions + Port of libiconv and libicu to Android You will need NDK r15, curl, autoconf, automake, libtool, and git installed. -There are no sources and no patches - everything is done with magical build scripts, -just run build.sh and enjoy. -Don't forget to strip them, because they are huge with debug info included. +There are no sources and no patches - everything is done with magical build scripts: + +(1) Make sure "which ndk-build" shows the correct version to build from + +(2) The scripts assume NDK/toolchain/... version 4.9. If otherwise, edit all the *.sh to + change GCCVER=4.9 as desired. + +(3) Run "./build.sh" and enjoy! + +(4) Don't forget to strip them, because they are huge with debug info included. There is no mips architecture, because there are very few devices using this architecture in the wild. diff --git a/build-android.sh b/build-android.sh new file mode 100755 index 0000000..cee908f --- /dev/null +++ b/build-android.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# +# *** build-android.sh *** +# +# This script automates editing the libiconv and libicu source code and build +# directives to build the libraries correctly to use when building swift for +# Android. Original instructions that this script automates are available at +# https://github.com/apple/swift/blob/4bf6f5475ddf5c9ff4a7e383bac41c8a0464cd90/docs/Android.md#adding-swift-suffix-to-icu-libraries +# + +set -e + +echo "warning: this script assumes it's running from the root of the libiconv-libicu-android directory" + +# Create armeabi-v7a dir +mkdir armeabi-v7a && cd armeabi-v7a +tar xvf ../icu4c-55_1-src.tgz +cd .. + +# Patch icu configure file +patch -i swift-android-source-patches/build.patch + +# Patch build.sh file +cd armeabi-v7a/icu/source/ +patch -i ../../../swift-android-source-patches/icu-configure.patch +cd ../../.. + +# 🎉 Run build.sh, with the edited sources +./build.sh + +echo "Done building 🎉🎉🎉" +echo "Check out the armeabi-v7a directory." diff --git a/build.sh b/build.sh index 85ba966..aa8989b 100755 --- a/build.sh +++ b/build.sh @@ -9,11 +9,11 @@ uname -s | grep -i "linux" && NCPU=`cat /proc/cpuinfo | grep -c -i processor` NDK=`which ndk-build` NDK=`dirname $NDK` -NDK=`readlink -f $NDK` +#NDK=`readlink -f $NDK` export CLANG=1 -for ARCH in armeabi armeabi-v7a arm64-v8a x86 x86_64; do +for ARCH in armeabi-v7a; do cd $BUILDDIR @@ -40,7 +40,7 @@ cd $BUILDDIR/$ARCH # =========== libiconv.so =========== -[ -e libiconv.so ] || { +true || [ -e libiconv.so ] || { rm -rf libiconv-1.15 @@ -159,16 +159,24 @@ cd $BUILDDIR/$ARCH cd $BUILDDIR/$ARCH -[ -e libicuuc.a ] || { +[ -e libicuuc$LIBSUFFIX.a ] || { rm -rf icu - tar xvf ../icu4c-59_1-src.tgz + [ -e ../icu4c-55_1-src.tgz ] || exit 1 + + tar xvf ../icu4c-55_1-src.tgz + + # The ENVVAR LIBSUFFIX should add the suffix only to the libname and not to the symbols. + # ToDo: Find the right way in Swift to refer to an alternative library with symbol prefixing or any other method to remove this. + if $[ -n "$LIBSUFFIX" ]; then + patch -p0 < ../patches/icu_suffix_only_on_libname.patch + fi cd icu/source - cp -f $BUILDDIR/config.sub . - cp -f $BUILDDIR/config.guess . + #cp -f $BUILDDIR/config.sub . + #cp -f $BUILDDIR/config.guess . [ -d cross ] || { mkdir cross @@ -178,8 +186,6 @@ cd $BUILDDIR/$ARCH cd .. } || exit 1 - sed -i "s@LD_SONAME *=.*@LD_SONAME =@g" config/mh-linux - sed -i "s%ln -s *%cp -f \$(dir \$@)/%g" config/mh-linux env CFLAGS="-I$NDK/sources/android/support/include -frtti -fexceptions" \ LDFLAGS="-frtti -fexceptions -L$BUILDDIR/$ARCH/lib" \ @@ -189,28 +195,27 @@ cd $BUILDDIR/$ARCH ./configure \ --host=$GCCPREFIX \ --prefix=`pwd`/../../ \ + --with-library-suffix=$LIBSUFFIX \ --with-cross-build=`pwd`/cross \ --enable-static --disable-shared \ - --with-data-packaging=archive \ || exit 1 # ICULEHB_CFLAGS="-I$BUILDDIR/$ARCH/include" \ # ICULEHB_LIBS="-licu-le-hb" \ # --enable-layoutex \ - sed -i "s@^prefix *= *.*@prefix = .@" icudefs.mk || exit 1 + sed -i.tmp 's/.$(SO_TARGET_VERSION_MAJOR)//' icudefs.mk + sed -i.tmp 's/$(PKGDATA_VERSIONING) -e/-e/' data/Makefile env PATH=`pwd`:$PATH \ $BUILDDIR/setCrossEnvironment-$ARCH.sh \ make -j$NCPU VERBOSE=1 || exit 1 - sed -i "s@^prefix *= *.*@prefix = `pwd`/../../@" icudefs.mk || exit 1 - env PATH=`pwd`:$PATH \ $BUILDDIR/setCrossEnvironment-$ARCH.sh \ make V=1 install || exit 1 - for f in libicudata libicutest libicui18n libicuio libicutu libicuuc; do + for f in libicudata$LIBSUFFIX libicutest$LIBSUFFIX libicui18n$LIBSUFFIX libicuio$LIBSUFFIX libicule$LIBSUFFIX libiculx$LIBSUFFIX libicutu$LIBSUFFIX libicuuc$LIBSUFFIX; do #cp -f -H ../../lib/$f.so ../../ cp -f ../../lib/$f.a ../../ #$BUILDDIR/setCrossEnvironment-$ARCH.sh \ diff --git a/patches/icu_suffix_only_on_libname.patch b/patches/icu_suffix_only_on_libname.patch new file mode 100644 index 0000000..e773089 --- /dev/null +++ b/patches/icu_suffix_only_on_libname.patch @@ -0,0 +1,18 @@ +--- icu/source/configure 2013-05-23 20:06:32.000000000 +0000 ++++ icu/source/configure.patched 2018-02-21 23:35:25.934967613 +0000 +@@ -7217,14 +7217,7 @@ + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $msg" >&5 + $as_echo "$msg" >&6; } + +-if test "$ICULIBSUFFIX" != "" +-then +- U_HAVE_LIB_SUFFIX=1 +- ICULIBSUFFIXCNAME=`echo _$ICULIBSUFFIX | sed 's/^A-Za-z0-9_/_/g'` +- UCONFIG_CPPFLAGS="${UCONFIG_CPPFLAGS} -DU_HAVE_LIB_SUFFIX=1 -DU_LIB_SUFFIX_C_NAME=${ICULIBSUFFIXCNAME} " +-else +- U_HAVE_LIB_SUFFIX=0 +-fi ++U_HAVE_LIB_SUFFIX=0 + + + diff --git a/setCrossEnvironment-armeabi-v7a.sh b/setCrossEnvironment-armeabi-v7a.sh index a2a0598..bf79811 100755 --- a/setCrossEnvironment-armeabi-v7a.sh +++ b/setCrossEnvironment-armeabi-v7a.sh @@ -1,11 +1,13 @@ -#!/bin/sh +#!/bin/bash + +NDK_STL="libc++" IFS=' ' MYARCH=linux-x86_64 if uname -s | grep -i "linux" > /dev/null ; then - MYARCH=linux-x86_64 + MYARCH=linux-`arch` fi if uname -s | grep -i "darwin" > /dev/null ; then MYARCH=darwin-x86_64 @@ -16,12 +18,16 @@ fi NDK=`which ndk-build` NDK=`dirname $NDK` -NDK=`readlink -f $NDK` +#NDK=`readlink -f $NDK` + +grep "64.bit" "$NDK/RELEASE.TXT" >/dev/null 2>&1 && MYARCH="${MYARCH}_64" #echo NDK $NDK GCCPREFIX=arm-linux-androideabi [ -z "$NDK_TOOLCHAIN_VERSION" ] && NDK_TOOLCHAIN_VERSION=4.9 -[ -z "$PLATFORMVER" ] && PLATFORMVER=android-15 +[ -z "$PLATFORMVER" ] && PLATFORMVER=android-16 +GCCVER=4.9 + LOCAL_PATH=`dirname $0` if which realpath > /dev/null ; then LOCAL_PATH=`realpath $LOCAL_PATH` @@ -29,7 +35,15 @@ else LOCAL_PATH=`cd $LOCAL_PATH && pwd` fi ARCH=armeabi-v7a - +STL_CFLAGS="-isystem$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/include \ +-isystem$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/libs/$ARCH/include" +STL_LDFLAGS="-L$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/libs/$ARCH" +STL_LDLIB="-lgnustl_shared -lsupc++" +if [[ "$NDK_STL" == "libc++" ]] ; then + STL_CFLAGS="-isystem$NDK/sources/cxx-stl/llvm-libc++/include" + STL_LDFLAGS="-L$NDK/sources/cxx-stl/llvm-libc++/libs/$ARCH" + STL_LDLIB="-lc++_shared" +fi CFLAGS=" -fexceptions diff --git a/setCrossEnvironment-armeabi.sh b/setCrossEnvironment-armeabi.sh index d2752a0..96ab545 100755 --- a/setCrossEnvironment-armeabi.sh +++ b/setCrossEnvironment-armeabi.sh @@ -5,7 +5,7 @@ IFS=' MYARCH=linux-x86_64 if uname -s | grep -i "linux" > /dev/null ; then - MYARCH=linux-x86_64 + MYARCH=linux-`arch` fi if uname -s | grep -i "darwin" > /dev/null ; then MYARCH=darwin-x86_64 @@ -16,12 +16,13 @@ fi NDK=`which ndk-build` NDK=`dirname $NDK` -NDK=`readlink -f $NDK` +#NDK=`readlink -f $NDK` -#echo NDK $NDK GCCPREFIX=arm-linux-androideabi [ -z "$NDK_TOOLCHAIN_VERSION" ] && NDK_TOOLCHAIN_VERSION=4.9 [ -z "$PLATFORMVER" ] && PLATFORMVER=android-15 +GCCVER=4.9 + LOCAL_PATH=`dirname $0` if which realpath > /dev/null ; then LOCAL_PATH=`realpath $LOCAL_PATH` diff --git a/setCrossEnvironment-x86.sh b/setCrossEnvironment-x86.sh index e14d083..ff1261e 100755 --- a/setCrossEnvironment-x86.sh +++ b/setCrossEnvironment-x86.sh @@ -5,7 +5,7 @@ IFS=' MYARCH=linux-x86_64 if uname -s | grep -i "linux" > /dev/null ; then - MYARCH=linux-x86_64 + MYARCH=linux-`arch` fi if uname -s | grep -i "darwin" > /dev/null ; then MYARCH=darwin-x86_64 @@ -16,12 +16,16 @@ fi NDK=`which ndk-build` NDK=`dirname $NDK` -NDK=`readlink -f $NDK` +#NDK=`readlink -f $NDK` + +grep "64.bit" "$NDK/RELEASE.TXT" >/dev/null 2>&1 && MYARCH="${MYARCH}_64" #echo NDK $NDK GCCPREFIX=i686-linux-android [ -z "$NDK_TOOLCHAIN_VERSION" ] && NDK_TOOLCHAIN_VERSION=4.9 [ -z "$PLATFORMVER" ] && PLATFORMVER=android-15 +GCCVER=4.9 + LOCAL_PATH=`dirname $0` if which realpath > /dev/null ; then LOCAL_PATH=`realpath $LOCAL_PATH` diff --git a/swift-android-source-patches/build.patch b/swift-android-source-patches/build.patch new file mode 100644 index 0000000..9124450 --- /dev/null +++ b/swift-android-source-patches/build.patch @@ -0,0 +1,34 @@ +--- build.sh 2018-01-19 09:56:47.000000000 -0800 ++++ build.sh.new 2018-01-19 09:56:38.000000000 -0800 +@@ -77,11 +77,11 @@ + + # =========== libicuXX.so =========== + +-[ -e libicuuc.so ] || { ++[ -e libicuucswifswiftt.so ] || { + +- [ -e ../icu4c-55_1-src.tgz ] || exit 1 ++# [ -e ../icu4c-55_1-src.tgz ] || exit 1 + +- tar xvf ../icu4c-55_1-src.tgz ++# tar xvf ../icu4c-55_1-src.tgz + + cd icu/source + +@@ -104,6 +104,7 @@ + ./configure \ + --host=arm-linux-androideabi \ + --prefix=`pwd`/../../ \ ++ --with-library-suffix=swift \ + --with-cross-build=`pwd`/cross \ + --enable-static --enable-shared \ + || exit 1 +@@ -119,7 +120,7 @@ + $BUILDDIR/setCrossEnvironment-$ARCH.sh \ + make V=1 install || exit 1 + +- for f in libicudata libicutest libicui18n libicuio libicule libiculx libicutu libicuuc; do ++ for f in libicudataswift libicutestswift libicui18nswift libicuioswift libiculeswift libiculxswift libicutuswift libicuucswift; do + cp -f -H ../../lib/$f.so ../../ + cp -f ../../lib/$f.a ../../ + $BUILDDIR/setCrossEnvironment-$ARCH.sh \ diff --git a/swift-android-source-patches/icu-configure.patch b/swift-android-source-patches/icu-configure.patch new file mode 100644 index 0000000..79c201c --- /dev/null +++ b/swift-android-source-patches/icu-configure.patch @@ -0,0 +1,22 @@ +--- armeabi-v7a/icu/source/configure 2018-01-18 17:31:55.000000000 -0800 ++++ armeabi-v7a/icu/source/configure.new 2018-01-18 17:33:27.000000000 -0800 +@@ -7599,14 +7599,14 @@ + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $msg" >&5 + $as_echo "$msg" >&6; } + +-if test "$ICULIBSUFFIX" != "" +-then +- U_HAVE_LIB_SUFFIX=1 +- ICULIBSUFFIXCNAME=`echo _$ICULIBSUFFIX | sed 's/^A-Za-z0-9_/_/g'` +- UCONFIG_CPPFLAGS="${UCONFIG_CPPFLAGS} -DU_HAVE_LIB_SUFFIX=1 -DU_LIB_SUFFIX_C_NAME=${ICULIBSUFFIXCNAME} " +-else +- U_HAVE_LIB_SUFFIX=0 +-fi ++# if test "$ICULIBSUFFIX" != "" ++# then ++# U_HAVE_LIB_SUFFIX=1 ++# ICULIBSUFFIXCNAME=`echo _$ICULIBSUFFIX | sed 's/^A-Za-z0-9_/_/g'` ++# UCONFIG_CPPFLAGS="${UCONFIG_CPPFLAGS} -DU_HAVE_LIB_SUFFIX=1 -DU_LIB_SUFFIX_C_NAME=${ICULIBSUFFIXCNAME} " ++# else ++U_HAVE_LIB_SUFFIX=0 ++# fi