Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build-android] Create template for build-android #5

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions build-android.sh
Original file line number Diff line number Diff line change
@@ -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."
26 changes: 11 additions & 15 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Binary file renamed icu4c-52_1-src.tgz → icu4c-55_1-src.tgz
Binary file not shown.
35 changes: 21 additions & 14 deletions setCrossEnvironment-armeabi-v7a.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
#!/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
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`
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 \
-no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb \
-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"
Expand All @@ -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 \
Expand Down
12 changes: 5 additions & 7 deletions setCrossEnvironment-armeabi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ 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
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
Expand Down
12 changes: 5 additions & 7 deletions setCrossEnvironment-mips.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ 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
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
Expand Down
12 changes: 5 additions & 7 deletions setCrossEnvironment-x86.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ 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
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
Expand Down
34 changes: 34 additions & 0 deletions swift-android-source-patches/build.patch
Original file line number Diff line number Diff line change
@@ -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 \
22 changes: 22 additions & 0 deletions swift-android-source-patches/icu-configure.patch
Original file line number Diff line number Diff line change
@@ -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