-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_icu
executable file
·294 lines (238 loc) · 7.15 KB
/
build_icu
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
#!/bin/bash
usage() {
cat <<EOE
Cross compile icu4c for Android, see README.md for details.
Options: -h, --help Print this message and exit
-c, --clean Clear all build files
Usage:
First make sure you have ndk installed, currently only support linux* and darwin*
like OS.
Run the following commands to build:
chmod +x build_icu
./build_icu <TARGET_ARCH>
<TARGET_ARCH> is the target abi-architecture you want to build, you can specify
it with 'arm' that corresponding to 'armabi-v7a' or 'arm64' that corresponding
to 'arm64-v8a', the default is 'arm'.
EOE
exit 0
}
# Clean all build files
clean() {
while true; do
read -p "Do you wish to clean all build files (Y/N)? " yn
case $yn in
[Yy]* )
rm -rf build
rm -rf *-toolchain
break;;
[Nn]* )
break;;
* ) ;;
esac
done
exit 0
}
case "$1" in
'-h'|'--help' )
usage
;;
'-c'|'--clean' )
clean
;;
esac
# Check if ndk is installed
ndk_dir=`dirname $(which ndk-build)`
if [ $? -ne 0 ]; then
echo -e "${ERR_COLOR}NDK not installed, exit.${NO_COLOR}"
exit 1
fi
if [ -z $ndk_dir -o ! -d $ndk_dir ]; then
echo -e "${ERR_COLOR}NDK not found, exit.${NO_COLOR}"
exit 1
fi
ERR_COLOR='\033[1;31m'
SUCESS_COLOR='\033[1;32m'
WARNING_COLOR='\033[1;33m'
NO_COLOR='\033[0m'
os_name=linux
build_type=Linux
include_dir=/usr/local/include
lib_dir=/usr/local/lib
case $OSTYPE in
darwin*)
os_name=darwin
build_type=MacOSX/GCC
;;
linux*)
os_name=linux
build_type=Linux
;;
*)
echo -e "${ERR_COLOR}${OSTYPE} is not supported, currently only support darwin* and linux*, exit.${NO_COLOR}"
exit 1
;;
esac
working_dir=`pwd`
build_dir=$working_dir/build
if [ ! -d "$build_dir" ]; then
mkdir $build_dir
fi
########################################## Build for host #####################################
host_build=$build_dir/host
build_host() {
cd $host_build
export ICU_SOURCES=$working_dir/icu
export CPPFLAGS="-Os -fno-short-wchar -fno-short-enums \
-DU_USING_ICU_NAMESPACE=1 \
-DU_HAVE_NL_LANGINFO_CODESET=0 \
-D__STDC_INT64__ -DU_TIMEZONE=0 \
-DUCONFIG_NO_LEGACY_CONVERSION=1 \
-ffunction-sections -fdata-sections -fvisibility=hidden"
if [ $os_name = "linux" ]; then
export LDFLAGS="-Wl,--gc-sections"
elif [ $os_name = "darwin" ]; then
# gcc on OSX does not support --gc-sections
export LDFLAGS="-Wl,-dead_strip"
fi
# Set --prefix option to disable install to the system,
# since we only need the libraries and header files
(exec $ICU_SOURCES/source/runConfigureICU $build_type \
--prefix=$host_build/icu_build --enable-extras=no \
--enable-strict=no -enable-static --enable-shared=no --enable-tests=no \
--enable-samples=no --enable-dyload=no)
make -j16
make install
if [ ! -d $host_build/icu_build/include/unicode ]; then
echo -e "${ERR_COLOR}Host build failed, exit.${NO_COLOR}"
exit 1
fi
cd $working_dir
return 0
}
copy_include() {
from=$host_build/icu_build/include/unicode
if [ ! -d $from ]; then
echo -e "${ERR_COLOR}Host not build, exit.${NO_COLOR}"
exit 1
fi
target=$include_dir/unicode
if [ ! -d $target ]; then
echo "No icu includes found, copy..."
cp -r $from $include_dir
else
echo "Icu includes already exists."
fi
}
copy_lib() {
from=$host_build/lib
if [ ! -d $from ]; then
echo -e "${ERR_COLOR}Host not build, exit.${NO_COLOR}"
exit 1
fi
test_one=$lib_dir/libicui18n.a
if [ ! -f $test_one ]; then
echo "No icu libs found, copy..."
cp -R $from/. $lib_dir/
else
echo "Icu libs already exists."
fi
}
if [ -d $host_build/icu_build ]; then
echo "Host build already exists, use this one."
else
echo "Build for host:"
mkdir $host_build
cd $host_build
build_host
if test $? -ne 0; then
rm -r $host_build
echo -e "${ERR_COLOR}Can not build for host, exit.${NO_COLOR}"
exit 1
fi
fi
copy_include; copy_lib
###################################### Make standalone-toolchain #################################
# See: https://developer.android.com/ndk/guides/standalone_toolchain
# TODO upgrade: https://developer.android.com/ndk/guides/other_build_systems
arch=$1
if [ -z $arch ]; then
echo -e "${WARNING_COLOR}No arch specified, use arm.${NO_COLOR}"
arch='arm'
fi
toolchain=''
if [ $arch = 'arm' ]; then
toolchain='arm-linux-androideabi-4.9'
elif [ $arch = 'arm64' ]; then
toolchain='aarch64-linux-android-4.9'
else
echo -e "${ERR_COLOR}$arch is not supported, exit.${NO_COLOR}"
exit 1
fi
toolchain_install_dir=$working_dir/$arch-toolchain/
make_toolchain=$ndk_dir/build/tools/make-standalone-toolchain.sh
# Check if toolchain is already exists
if [ -d $toolchain_install_dir ]; then
echo "Use the toolchain already exists."
else
echo "Install toolchain to ${toolchain_install_dir}"
(exec $make_toolchain \
--platform=android-21 \
--install_dir=$toolchain_install_dir \
--toolchain=$toolchain \
--arch=$arch \
--stl=gnustl)
fi
########################################## Build for Android #####################################
android_build=$build_dir/android
build_android() {
arch_build=$android_build/$arch
target=$android_build/$arch/lib
if [ -d $target ]; then
echo "Arch '$arch' already builded, use this one."
return 0
fi
if [ ! -d $arch_build ]; then
mkdir $arch_build
fi
cd $arch_build
export ICU_SOURCES=$working_dir/icu
export ANDROIDVER=22
export AR=/usr/bin/ar
export ICU_CROSS_BUILD=$host_build
export NDK_STANDARD_ROOT=$toolchain_install_dir
export CPPFLAGS="-I$NDK_STANDARD_ROOT/sysroot/usr/include/ \
-Os -fno-short-wchar -DU_USING_ICU_NAMESPACE=1 -fno-short-enums \
-DU_HAVE_NL_LANGINFO_CODESET=0 -D__STDC_INT64__ -DU_TIMEZONE=0 \
-DUCONFIG_NO_LEGACY_CONVERSION=1 \
-ffunction-sections -fdata-sections -fvisibility=hidden"
export LDFLAGS="-lc -lstdc++ -Wl,--gc-sections,-rpath-link=$NDK_STANDARD_ROOT/sysroot/usr/lib/"
export PATH=$PATH:$NDK_STANDARD_ROOT/bin
host=''
if [ $arch = 'arm' ]; then
host='arm-linux-androideabi'
else
host='aarch64-linux-android'
fi
(exec $ICU_SOURCES/source/configure --with-cross-build=$ICU_CROSS_BUILD \
--enable-extras=no --enable-strict=no -enable-static --enable-shared=no \
--enable-tests=no --enable-samples=no --enable-dyload=no \
--host=$host --prefix=$PWD/icu_build)
make -j16
make install
if [ $? -ne 0 ]; then
return 1
fi
cd $working_dir
return 0
}
if [ ! -d $android_build ]; then
mkdir $android_build
fi
build_android
if [ $? -ne 0 ]; then
echo -e "${ERR_COLOR}Cross build for Android failed, exit.${NO_COLOR}"
exit 1
else
echo -e "${SUCESS_COLOR}Build success, congradulations!${NO_COLOR}"
echo -e "${SUCESS_COLOR}The libraries can be found at: $android_build/$arch/lib/${NO_COLOR}"
fi