diff --git a/README.md b/README.md index 2a313e7..536bb2e 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 r10e, 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. If you need libintl, you may download it here: https://github.com/pelya/commandergenius/tree/sdl_android/project/jni/intl 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 417535f..3d273a8 100755 --- a/build.sh +++ b/build.sh @@ -9,9 +9,9 @@ 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` -for ARCH in armeabi armeabi-v7a x86 mips; do +for ARCH in armeabi-v7a; do cd $BUILDDIR mkdir -p $ARCH @@ -24,7 +24,7 @@ mkdir -p android_support cd android_support ln -sf $NDK/sources/android/support jni -ndk-build -j$NCPU APP_ABI=$ARCH || exit 1 +ndk-build -j$NCPU APP_ABI=$ARCH LIBCXX_FORCE_REBUILD=true || exit 1 cp -f obj/local/$ARCH/libandroid_support.a ../ } || exit 1 @@ -33,7 +33,7 @@ cd $BUILDDIR/$ARCH # =========== libiconv.so =========== -[ -e libiconv.so ] || { +true || [ -e libiconv.so ] || { [ -e ../libiconv-1.14.tar.gz ] || curl -L http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz -o ../libiconv-1.14.tar.gz || exit 1 @@ -79,14 +79,14 @@ cd $BUILDDIR/$ARCH [ -e libicuuc.so ] || { - [ -e ../icu4c-52_1-src.tgz ] || curl http://pkgs.fedoraproject.org/repo/pkgs/icu/icu4c-52_1-src.tgz/9e96ed4c1d99c0d14ac03c140f9f346c/icu4c-52_1-src.tgz -o ../icu4c-52_1-src.tgz || exit 1 + [ -e ../icu4c-55_1-src.tgz ] || exit 1 - tar xvf ../icu4c-52_1-src.tgz + tar xvf ../icu4c-55_1-src.tgz 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 @@ -96,29 +96,25 @@ 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" \ - LIBS="-L$BUILDDIR/$ARCH -landroid_support -lgnustl_static -lstdc++" \ + LIBS="-L$BUILDDIR/$ARCH -landroid_support -lc++_shared -lstdc++" \ $BUILDDIR/setCrossEnvironment-$ARCH.sh \ ./configure \ --host=arm-linux-androideabi \ --prefix=`pwd`/../../ \ --with-cross-build=`pwd`/cross \ --enable-static --enable-shared \ - --with-data-packaging=archive \ || exit 1 - 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 diff --git a/icu4c-52_1-src.tgz b/icu4c-55_1-src.tgz similarity index 68% rename from icu4c-52_1-src.tgz rename to icu4c-55_1-src.tgz index 3973086..0b38bcd 100644 Binary files a/icu4c-52_1-src.tgz and b/icu4c-55_1-src.tgz differ diff --git a/setCrossEnvironment-armeabi-v7a.sh b/setCrossEnvironment-armeabi-v7a.sh index c284746..deddf57 100755 --- a/setCrossEnvironment-armeabi-v7a.sh +++ b/setCrossEnvironment-armeabi-v7a.sh @@ -1,14 +1,16 @@ -#!/bin/sh +#!/bin/bash + +NDK_STL="libc++" IFS=' ' MYARCH=linux-x86 if uname -s | grep -i "linux" > /dev/null ; then - MYARCH=linux-x86 + MYARCH=linux-`arch` fi if uname -s | grep -i "darwin" > /dev/null ; then - MYARCH=darwin-x86 + MYARCH=darwin-x86_64 fi if uname -s | grep -i "windows" > /dev/null ; then MYARCH=windows-x86 @@ -16,14 +18,12 @@ fi NDK=`which ndk-build` NDK=`dirname $NDK` -NDK=`readlink -f $NDK` - -grep "64.bit" "$NDK/RELEASE.TXT" >/dev/null 2>&1 && MYARCH="${MYARCH}_64" +#NDK=`readlink -f $NDK` -[ -z "$NDK" ] && { echo "You need Andorid NDK r8 or newer installed to run this script" ; exit 1 ; } +[ -z "$NDK" ] && { echo "You need Android NDK r8 or newer installed to run this script" ; exit 1 ; } GCCPREFIX=arm-linux-androideabi -GCCVER=4.8 -PLATFORMVER=android-14 +GCCVER=4.9 +PLATFORMVER=android-16 LOCAL_PATH=`dirname $0` if which realpath > /dev/null ; then LOCAL_PATH=`realpath $LOCAL_PATH` @@ -31,6 +31,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="\ -fpic -ffunction-sections -funwind-tables -fstack-protector \ @@ -38,8 +47,7 @@ CFLAGS="\ -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -marm -fno-omit-frame-pointer \ -DANDROID -DNDEBUG -O2 -g -finline-functions -Wa,--noexecstack -Wformat -Werror=format-security \ -isystem$NDK/platforms/$PLATFORMVER/arch-arm/usr/include \ --isystem$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/include \ --isystem$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/libs/$ARCH/include \ +$STL_CFLAGS \ $CFLAGS" UNRESOLVED="-Wl,--no-undefined" @@ -57,11 +65,10 @@ $SHARED \ --sysroot=$NDK/platforms/$PLATFORMVER/arch-arm \ -L$NDK/platforms/$PLATFORMVER/arch-arm/usr/lib \ -lc -lm -ldl -lz \ --L$NDK/sources/cxx-stl/gnu-libstdc++/$GCCVER/libs/$ARCH \ --lgnustl_static \ +$STL_LDFLAGS \ +$STL_LDLIB \ -march=armv7-a -Wl,--fix-cortex-a8 \ -no-canonical-prefixes $UNRESOLVED -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now \ --lsupc++ \ $LDFLAGS" env PATH=$NDK/toolchains/$GCCPREFIX-$GCCVER/prebuilt/$MYARCH/bin:$LOCAL_PATH:$PATH \ diff --git a/setCrossEnvironment-armeabi.sh b/setCrossEnvironment-armeabi.sh index 1032fa9..e8ef612 100755 --- a/setCrossEnvironment-armeabi.sh +++ b/setCrossEnvironment-armeabi.sh @@ -5,10 +5,10 @@ IFS=' MYARCH=linux-x86 if uname -s | grep -i "linux" > /dev/null ; then - MYARCH=linux-x86 + MYARCH=linux-`arch` fi if uname -s | grep -i "darwin" > /dev/null ; then - MYARCH=darwin-x86 + MYARCH=darwin-x86_64 fi if uname -s | grep -i "windows" > /dev/null ; then MYARCH=windows-x86 @@ -16,13 +16,11 @@ 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" - -[ -z "$NDK" ] && { echo "You need Andorid NDK r8 or newer installed to run this script" ; exit 1 ; } +[ -z "$NDK" ] && { echo "You need Android NDK r8 or newer installed to run this script" ; exit 1 ; } GCCPREFIX=arm-linux-androideabi -GCCVER=4.8 +GCCVER=4.9 PLATFORMVER=android-14 LOCAL_PATH=`dirname $0` if which realpath > /dev/null ; then diff --git a/setCrossEnvironment-mips.sh b/setCrossEnvironment-mips.sh index 083b3ab..d0660ff 100755 --- a/setCrossEnvironment-mips.sh +++ b/setCrossEnvironment-mips.sh @@ -5,10 +5,10 @@ IFS=' MYARCH=linux-x86 if uname -s | grep -i "linux" > /dev/null ; then - MYARCH=linux-x86 + MYARCH=linux-`arch` fi if uname -s | grep -i "darwin" > /dev/null ; then - MYARCH=darwin-x86 + MYARCH=darwin-x86_64 fi if uname -s | grep -i "windows" > /dev/null ; then MYARCH=windows-x86 @@ -16,13 +16,11 @@ 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" - -[ -z "$NDK" ] && { echo "You need Andorid NDK r8 or newer installed to run this script" ; exit 1 ; } +[ -z "$NDK" ] && { echo "You need Android NDK r8 or newer installed to run this script" ; exit 1 ; } GCCPREFIX=mipsel-linux-android -GCCVER=4.8 +GCCVER=4.9 PLATFORMVER=android-14 LOCAL_PATH=`dirname $0` if which realpath > /dev/null ; then diff --git a/setCrossEnvironment-x86.sh b/setCrossEnvironment-x86.sh index 8b641c5..3cd14fa 100755 --- a/setCrossEnvironment-x86.sh +++ b/setCrossEnvironment-x86.sh @@ -5,10 +5,10 @@ IFS=' MYARCH=linux-x86 if uname -s | grep -i "linux" > /dev/null ; then - MYARCH=linux-x86 + MYARCH=linux-`arch` fi if uname -s | grep -i "darwin" > /dev/null ; then - MYARCH=darwin-x86 + MYARCH=darwin-x86_64 fi if uname -s | grep -i "windows" > /dev/null ; then MYARCH=windows-x86 @@ -16,13 +16,11 @@ 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" - -[ -z "$NDK" ] && { echo "You need Andorid NDK r8 or newer installed to run this script" ; exit 1 ; } +[ -z "$NDK" ] && { echo "You need Android NDK r8 or newer installed to run this script" ; exit 1 ; } GCCPREFIX=i686-linux-android -GCCVER=4.8 +GCCVER=4.9 PLATFORMVER=android-14 LOCAL_PATH=`dirname $0` if which realpath > /dev/null ; then 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