forked from drodriguez/libiconv-libicu-android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·385 lines (285 loc) · 10.1 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#!/bin/sh
set -x
export BUILDDIR=`pwd`
if uname -s | grep -i 'linux' &> /dev/null; then
IS_LINUX=1
fi
if [ $IS_LINUX ]; then
NCPU=`cat /proc/cpuinfo | grep -c -i processor`
else
NCPU=8
fi
NDK=`which ndk-build`
NDK=`dirname $NDK`
if [ $IS_LINUX ]; then
NDK=`readlink -f $NDK`
fi
export CLANG=1
if [ ! $ARCHS ]; then
ARCHS='armeabi armeabi-v7a arm64-v8a x86 x86_64'
fi
for ARCH in $ARCHS; do
cd $BUILDDIR
GCCPREFIX="`./setCrossEnvironment-$ARCH.sh sh -c 'basename $STRIP | sed s/-strip//'`"
echo "ARCH $ARCH GCCPREFIX $GCCPREFIX"
mkdir -p $ARCH
cd $BUILDDIR/$ARCH
# =========== libiconv.so ===========
[ -e libiconv.so ] || [ $SKIP_ICONV ] || {
rm -rf libiconv-1.15
tar xvf ../libiconv-1.15.tar.gz
cd libiconv-1.15
cp -f $BUILDDIR/config.sub build-aux/
cp -f $BUILDDIR/config.guess build-aux/
cp -f $BUILDDIR/config.sub libcharset/build-aux/
cp -f $BUILDDIR/config.guess libcharset/build-aux/
sed -i,tmp 's/MB_CUR_MAX/1/g' lib/loop_wchar.h
env CFLAGS="-I$NDK/sources/android/support/include -D_IO_getc=getc" \
LDFLAGS="-L$BUILDDIR/$ARCH -landroid_support" \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
./configure \
--host=$GCCPREFIX \
--prefix=`pwd`/.. \
--enable-static --enable-shared \
|| exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 || echo "Libtool is a miserable pile of shit, linking libcharset.so manually"
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
sh -c '$LD $CFLAGS $LDFLAGS -shared libcharset/lib/.libs/*.o -o libcharset/lib/.libs/libcharset.so' || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 || echo "Libtool works worse than cat /dev/urandom | head 10000 > library.so, because this will at least generate a target file, linking libiconv.so manually"
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
sh -c '$LD $CFLAGS $LDFLAGS -shared lib/.libs/*.o -o lib/.libs/libiconv.so' || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 || echo "Did you know that libtool contributes to global warming by overheating your CPU?"
cp -f lib/.libs/libiconv.so preload/preloadable_libiconv.so
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 install || exit 1
cd ..
for f in libiconv libcharset; do
cp -f lib/$f.so ./
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
sh -c '$STRIP'" $f.so"
done
} || exit 1
# =========== libharfbuzz ===========
cd $BUILDDIR/$ARCH
[ -e libharfbuzz.a ] || [ $SKIP_HARFBUZZ ] || {
rm -rf harfbuzz-1.4.6
tar xvf ../harfbuzz-1.4.6.tar.bz2
cd harfbuzz-1.4.6
cp -f $BUILDDIR/config.sub .
cp -f $BUILDDIR/config.guess .
sed -i,tmp 's/ld_shlibs=no/ld_shlibs=yes/g' ./configure
env CFLAGS="-I$NDK/sources/android/support/include -frtti -fexceptions -I$BUILDDIR/$ARCH/include" \
LDFLAGS="-frtti -fexceptions -L$BUILDDIR/$ARCH/lib" \
LIBS="-L$BUILDDIR/$ARCH -landroid_support" \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
./configure \
--host=$GCCPREFIX \
--prefix=`pwd`/../ \
--enable-static --enable-shared \
--with-glib=no --with-gobject=no \
--with-cairo=no --with-fontconfig=no \
--with-icu=no --with-freetype=no \
|| exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make -j$NCPU V=1 || echo "Crappy libtool cannot link anything"
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
sh -c '$LD $CFLAGS $LDFLAGS -shared src/.libs/*.o src/hb-ucdn/.libs/*.o -o src/.libs/libharfbuzz.so' || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make -j$NCPU V=1 || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 install || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
sh -c '$AR rcs ../lib/libharfbuzz.a src/.libs/*.o src/hb-ucdn/.libs/*.o' || exit 1
cd ..
cp -f lib/libharfbuzz.a ./
}
# =========== libicuuc ===========
cd $BUILDDIR/$ARCH
[ -e libicuuc$LIBSUFFIX.a ] || [ -e libicuuc$LIBSUFFIX.so ] || [ $SKIP_ICUUC ] || {
rm -rf icu
tar xvf ../icu4c-59_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 [ $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 .
[ -d $BUILDDIR/cross ] || {
mkdir $BUILDDIR/cross
cd $BUILDDIR/cross
$BUILDDIR/$ARCH/icu/source/configure || exit 1
make -j$NCPU VERBOSE=1 || exit 1
cd $BUILDDIR/$ARCH/icu/source
} || exit 1
sed -i,tmp "s@LD_SONAME *=.*@LD_SONAME =@g" config/mh-linux
sed -i,tmp "s%ln -s *%cp -f \$(dir \$@)/%g" config/mh-linux
if [ $SHARED_ICU ]; then
libtype='--enable-shared --disable-static'
else
libtype='--enable-static --disable-shared'
fi
env CFLAGS="-I$NDK/sources/android/support/include -frtti -fexceptions" \
LDFLAGS="-frtti -fexceptions -L$BUILDDIR/$ARCH/lib" \
LIBS="-L$BUILDDIR/$ARCH `$BUILDDIR/setCrossEnvironment-$ARCH.sh sh -c 'echo $LDFLAGS'`" \
env ac_cv_func_strtod_l=no \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
./configure \
--host=$GCCPREFIX \
--prefix=`pwd`/../../ \
--with-library-suffix=$LIBSUFFIX \
--with-cross-build=$BUILDDIR/cross \
$libtype \
--with-data-packaging=library \
|| exit 1
# ICULEHB_CFLAGS="-I$BUILDDIR/$ARCH/include" \
# ICULEHB_LIBS="-licu-le-hb" \
# --enable-layoutex \
sed -i,tmp "s@^prefix *= *.*@prefix = .@" icudefs.mk || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make -j$NCPU VERBOSE=1 || exit 1
sed -i,tmp "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$LIBSUFFIX libicutest$LIBSUFFIX libicui18n$LIBSUFFIX libicuio$LIBSUFFIX libicutu$LIBSUFFIX libicuuc$LIBSUFFIX; do
if [ $SHARED_ICU ]; then
cp -f -H ../../lib/$f.so ../../
else
cp -f ../../lib/$f.a ../../
fi
#$BUILDDIR/setCrossEnvironment-$ARCH.sh \
# sh -c '$STRIP'" ../../$f.so"
done
} || exit 1
# =========== libicu-le-hb ===========
cd $BUILDDIR/$ARCH
[ -e libicu-le-hb.a ] || [ $SKIP_ICUUC ] || [ $SKIP_HARFBUZZ ] || [ $SKIP_ICULEHB ] || {
rm -rf icu-le-hb-1.0.3
tar xvf ../icu-le-hb-1.0.3.tar.gz
cd icu-le-hb-1.0.3
cp -f $BUILDDIR/config.sub .
cp -f $BUILDDIR/config.guess .
sed -i,tmp 's/ld_shlibs=no/ld_shlibs=yes/g' ./configure
env CFLAGS="-I$NDK/sources/android/support/include -frtti -fexceptions" \
CXXFLAGS="-std=c++11" \
LDFLAGS="-frtti -fexceptions" \
LIBS="-L$BUILDDIR/$ARCH -landroid_support" \
HARFBUZZ_CFLAGS="-I$BUILDDIR/$ARCH/include/harfbuzz" \
HARFBUZZ_LIBS="-L$BUILDDIR/$ARCH/lib -lharfbuzz" \
ICU_CFLAGS="-I$BUILDDIR/$ARCH/include" \
ICU_LIBS="-L$BUILDDIR/$ARCH/lib" \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
./configure \
--host=$GCCPREFIX \
--prefix=`pwd`/../ \
--enable-static --enable-shared \
|| exit 1
cmd='$LD $CFLAGS -shared src/.libs/*.o -o src/.libs/libicu-le-hb.so.0.0.0 -L../lib -lharfbuzz $LDFLAGS'
cmd="$cmd -licuuc$LIBSUFFIX"
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 || \
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
sh -c "$cmd" || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
sh -c '$AR rcs ../lib/libicu-le-hb.a src/.libs/*.o' || exit 1
cat > src/libicu-le-hb.la <<EOF
# libicu-le-hb.so - a libtool library file
# Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1.7ubuntu1
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libicu-le-hb.so.0'
# Names of this library.
library_names='libicu-le-hb.so.0.0.0 libicu-le-hb.so.0 libicu-le-hb.so'
# The name of the static archive.
old_library=''
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=''
# Libraries that this one depends upon.
dependency_libs=''
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libharfbuzz.
current=0
age=0
revision=0
# Is this an already installed library?
installed=no
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/lib'
EOF
cp -f src/libicu-le-hb.la src/.libs/libicu-le-hb.lai
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make V=1 install || exit 1
cd ..
cp -f lib/libicu-le-hb.a ./
}
# =========== We are building libicu twice, because libiculx depends on libicu-le-hb wcich depends on libicudata ===========
cd $BUILDDIR/$ARCH
[ -e libiculx.a ] || [ $SKIP_HARFBUZZ ] || [ $SKIP_ICUUC ] || [ $SKIP_ICULEHB ] || [ $SKIP_ICULX ] || {
cd icu/source
env CFLAGS="-I$NDK/sources/android/support/include -frtti -fexceptions" \
LDFLAGS="-frtti -fexceptions -L$BUILDDIR/$ARCH/lib" \
LIBS="-L$BUILDDIR/$ARCH `$BUILDDIR/setCrossEnvironment-$ARCH.sh sh -c 'echo $LDFLAGS'`" \
ICULEHB_CFLAGS="-I$BUILDDIR/$ARCH/include/icu-le-hb" \
ICULEHB_LIBS="-licu-le-hb" \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
./configure \
--host=$GCCPREFIX \
--prefix=`pwd`/../../ \
--with-cross-build=$BUILDDIR/cross \
--enable-static --disable-shared \
--with-data-packaging=archive \
--enable-layoutex \
|| exit 1
sed -i,tmp "s@^prefix *= *.*@prefix = .@" icudefs.mk || exit 1
env PATH=`pwd`:$PATH \
$BUILDDIR/setCrossEnvironment-$ARCH.sh \
make -j$NCPU VERBOSE=1 || exit 1
sed -i,tmp "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 libiculx; do
#cp -f -H ../../lib/$f.so ../../
cp -f ../../lib/$f.a ../../ || exit 1
#$BUILDDIR/setCrossEnvironment-$ARCH.sh \
# sh -c '$STRIP'" ../../$f.so"
done
} || exit 1
done # for ARCH in ...
exit 0