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
|
#!/bin/sh
#
# Copyright (C) 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# include common function and variable definitions
. `dirname $0`/prebuilt-common.sh
. `dirname $0`/builder-funcs.sh
PROGRAM_PARAMETERS=""
PROGRAM_DESCRIPTION=\
"Rebuild compiler-rt for the Android NDK.
This requires a temporary NDK installation containing
toolchain binaries for all target architectures.
By default, this will try with the current NDK directory, unless
you use the --ndk-dir=<path> option.
The output will be placed in appropriate sub-directories of
<ndk>/$COMPILER_RT_SUBDIR, but you can override this with the --out-dir=<path>
option.
"
PACKAGE_DIR=
register_var_option "--package-dir=<path>" PACKAGE_DIR "Put prebuilt tarballs into <path>."
NDK_DIR=
register_var_option "--ndk-dir=<path>" NDK_DIR "Specify NDK root path for the build."
SRC_DIR=
register_var_option "--src-dir=<path>" SRC_DIR "Specify compiler-rt source dir."
BUILD_DIR=
OPTION_BUILD_DIR=
register_var_option "--build-dir=<path>" OPTION_BUILD_DIR "Specify temporary build dir."
OUT_DIR=
register_var_option "--out-dir=<path>" OUT_DIR "Specify output directory directly."
ABIS="$PREBUILT_ABIS"
register_var_option "--abis=<list>" ABIS "Specify list of target ABIs."
NO_MAKEFILE=
register_var_option "--no-makefile" NO_MAKEFILE "Do not use makefile to speed-up build"
GCC_VERSION=
register_var_option "--gcc-version=<ver>" GCC_VERSION "Specify GCC version"
LLVM_VERSION=
register_var_option "--llvm-version=<ver>" LLVM_VERSION "Specify LLVM version"
register_jobs_option
extract_parameters "$@"
ABIS=$(commas_to_spaces $ABIS)
# Handle NDK_DIR
if [ -z "$NDK_DIR" ] ; then
NDK_DIR=$ANDROID_NDK_ROOT
log "Auto-config: --ndk-dir=$NDK_DIR"
else
if [ ! -d "$NDK_DIR" ] ; then
echo "ERROR: NDK directory does not exists: $NDK_DIR"
exit 1
fi
fi
if [ -z "$OPTION_BUILD_DIR" ]; then
BUILD_DIR=$NDK_TMPDIR/build-compiler-rt
else
BUILD_DIR=$OPTION_BUILD_DIR
fi
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
fail_panic "Could not create build directory: $BUILD_DIR"
if [ -z "$SRC_DIR" -o ! -d "$SRC_DIR" ]; then
dump "Could not found compiler-rt source directory: $SRC_DIR"
dump "Use --src-dir=<dir> to specify source directory."
exit 1
fi
# Compiler flags we want to use
COMPILER_RT_CFLAGS="-fPIC -O2 -DANDROID -D__ANDROID__ -ffunction-sections"
COMPILER_RT_CFLAGS=$COMPILER_RT_CFLAGS" -I$SRC_DIR/include -I$SRC_DIR/lib"
COMPILER_RT_LDFLAGS="-nodefaultlibs"
# List of sources to compile
COMPILER_RT_GENERIC_SOURCES=$(cd $SRC_DIR && ls lib/*.c)
# filter out the sources we don't need
UNUSED_SOURCES="lib/apple_versioning.c lib/clear_cache.c lib/gcc_personality_v0.c"
COMPILER_RT_GENERIC_SOURCES=$(filter_out "$UNUSED_SOURCES" "$COMPILER_RT_GENERIC_SOURCES")
# ARM specific
COMPILER_RT_ARM_SOURCES="
lib/arm/aeabi_dcmp.S \
lib/arm/aeabi_fcmp.S \
lib/arm/aeabi_idivmod.S \
lib/arm/aeabi_ldivmod.S \
lib/arm/aeabi_memcmp.S \
lib/arm/aeabi_memcpy.S \
lib/arm/aeabi_memmove.S \
lib/arm/aeabi_memset.S \
lib/arm/aeabi_uidivmod.S \
lib/arm/aeabi_uldivmod.S \
lib/arm/comparesf2.S
lib/arm/divmodsi4.S
lib/arm/divsi3.S
lib/arm/modsi3.S
lib/arm/udivmodsi4.S
lib/arm/udivsi3.S
lib/arm/umodsi3.S"
# X86 specific
COMPILER_RT_X86_SOURCES="
lib/i386/ashldi3.S \
lib/i386/ashrdi3.S \
lib/i386/divdi3.S \
lib/i386/floatdidf.S \
lib/i386/floatdisf.S \
lib/i386/floatdixf.S \
lib/i386/floatundidf.S \
lib/i386/floatundisf.S \
lib/i386/floatundixf.S \
lib/i386/lshrdi3.S \
lib/i386/moddi3.S \
lib/i386/muldi3.S \
lib/i386/udivdi3.S \
lib/i386/umoddi3.S"
# Mips specific
COMPILER_RT_MIPS_SOURCES=
# If the --no-makefile flag is not used, we're going to put all build
# commands in a temporary Makefile that we will be able to invoke with
# -j$NUM_JOBS to build stuff in parallel.
#
if [ -z "$NO_MAKEFILE" ]; then
MAKEFILE=$BUILD_DIR/Makefile
else
MAKEFILE=
fi
# prepare_compiler_rt_source_for_abi
# $1: ABI
prepare_compiler_rt_source_for_abi ()
{
local ABI=$1
local ARCH_SOURCES GENERIC_SOURCES FOUND
if [ $ABI == "armeabi" -o $ABI == "armeabi-v7a" -o $ABI == "armeabi-v7a-hard" ]; then
ARCH_SOURCES="$COMPILER_RT_ARM_SOURCES"
elif [ $ABI == "x86" ]; then
ARCH_SOURCES="$COMPILER_RT_X86_SOURCES"
elif [ $ABI == "mips" ]; then
ARCH_SOURCES="$COMPILER_RT_MIPS_SOURCES"
fi
for SOURCE in $COMPILER_RT_GENERIC_SOURCES; do
FILENAME=`basename $SOURCE`
FILENAME=$"${FILENAME/\.c/}"
# if we have lib/$ABI/*.S, skip lib/*.c
FOUND=$(echo $ARCH_SOURCES | grep $FILENAME)
if [ -z "$FOUND" ]; then
GENERIC_SOURCES="$GENERIC_SOURCES $SOURCE"
fi
done
echo "$ARCH_SOURCES $GENERIC_SOURCES"
}
# build_compiler_rt_libs_for_abi
# $1: ABI
# $2: build directory
# $3: build type: "static" or "shared"
# $4: (optional) installation directory
build_compiler_rt_libs_for_abi ()
{
local ARCH BINPREFIX
local ABI=$1
local BUILDDIR="$2"
local TYPE="$3"
local DSTDIR="$4"
local GCCVER
mkdir -p "$BUILDDIR"
# If the output directory is not specified, use default location
if [ -z "$DSTDIR" ]; then
DSTDIR=$NDK_DIR/$COMPILER_RT_SUBDIR/libs/$ABI
fi
mkdir -p "$DSTDIR"
if [ -n "$GCC_VERSION" ]; then
GCCVER=$GCC_VERSION
else
ARCH=$(convert_abi_to_arch $ABI)
GCCVER=$(get_default_gcc_version_for_arch $ARCH)
fi
builder_begin_android $ABI "$BUILDDIR" "$GCCVER" "$LLVM_VERSION" "$MAKEFILE"
builder_set_srcdir "$SRC_DIR"
builder_set_dstdir "$DSTDIR"
builder_cflags "$COMPILER_RT_CFLAGS"
if [ $ABI == "armeabi" -o $ABI == "armeabi-v7a" -o $ABI == "armeabi-v7a-hard" ]; then
builder_cflags "-D__ARM_EABI__"
if [ $ABI == "armeabi-v7a-hard" ]; then
builder_cflags "-mhard-float -D_NDK_MATH_NO_SOFTFP=1"
fi
fi
builder_ldflags "$COMPILER_RT_LDFLAGS"
if [ $ABI == "armeabi-v7a-hard" ]; then
builder_cflags "-Wl,--no-warn-mismatch -lm_hard"
fi
builder_sources $(prepare_compiler_rt_source_for_abi $ABI)
if [ "$TYPE" = "static" ]; then
log "Building $DSTDIR/libcompiler_rt_static.a"
builder_static_library libcompiler_rt_static
else
log "Building $DSTDIR/libcompiler_rt_shared.so"
builder_ldflags "-lc"
if [ $ABI != "armeabi-v7a-hard" ]; then
builder_ldflags "-lm"
fi
builder_nodefaultlibs_shared_library libcompiler_rt_shared
fi
builder_end
}
for ABI in $ABIS; do
build_compiler_rt_libs_for_abi $ABI "$BUILD_DIR/$ABI/shared" "shared" "$OUT_DIR"
build_compiler_rt_libs_for_abi $ABI "$BUILD_DIR/$ABI/static" "static" "$OUT_DIR"
done
# If needed, package files into tarballs
if [ -n "$PACKAGE_DIR" ] ; then
for ABI in $ABIS; do
FILES=""
for LIB in libcompiler_rt_static.a libcompiler_rt_shared.so; do
FILES="$FILES $COMPILER_RT_SUBDIR/libs/$ABI/$LIB"
done
PACKAGE="$PACKAGE_DIR/compiler-rt-libs-$ABI.tar.bz2"
log "Packaging: $PACKAGE"
pack_archive "$PACKAGE" "$NDK_DIR" "$FILES"
fail_panic "Could not package $ABI compiler-rt binaries!"
dump "Packaging: $PACKAGE"
done
fi
if [ -z "$OPTION_BUILD_DIR" ]; then
log "Cleaning up..."
rm -rf $BUILD_DIR
else
log "Don't forget to cleanup: $BUILD_DIR"
fi
log "Done!"
|