-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild-so.sh
executable file
·221 lines (208 loc) · 11.1 KB
/
build-so.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
#!/bin/bash -e
#@author Aleksandar Gotev ([email protected])
#Hints and code taken also from http://stackoverflow.com/questions/11929773/compiling-the-latest-openssl-for-android
if [ "$#" -ne 6 ]
then
echo "Usage:"
echo "./openssl-build <ANDROID_NDK_PATH> <OPENSSL_SOURCES_PATH> <ANDROID_TARGET_API> \\"
echo " <ANDROID_TARGET_ABI> <GCC_VERSION> <OUTPUT_PATH>"
echo
echo "Supported target ABIs: armeabi, armeabi-v7a, x86, x86_64, arm64-v8a, mips, mips64"
echo
echo "Example using GCC 4.8, NDK 10e, OpenSSL 1.0.2d and Android API 21 for armeabi-v7a."
echo "./openssl-build /home/user/android-ndk-r10e \\"
echo " /home/user/openssl-1.0.2d \\"
echo " 21 \\"
echo " armeabi-v7a \\"
echo " 4.8 \\"
echo " /home/user/output/armeabi-v7a"
exit 1
fi
NDK_DIR=$1
OPENSSL_BASE_FOLDER=$2
OPENSSL_TARGET_API=$3
OPENSSL_TARGET_ABI=$4
OPENSSL_GCC_VERSION=$5
OPENSSL_OUTPUT_PATH=$6
NDK_MAKE_TOOLCHAIN="$NDK_DIR/build/tools/make-standalone-toolchain.sh"
OPENSSL_TMP_FOLDER="/tmp/openssl"
rm -rf "$OPENSSL_TMP_FOLDER"
mkdir -p "$OPENSSL_TMP_FOLDER"
cp -r ${OPENSSL_BASE_FOLDER}/* ${OPENSSL_TMP_FOLDER}
function build_library {
mkdir -p ${OPENSSL_OUTPUT_PATH}
export PATH=$TOOLCHAIN_PATH:$PATH
make && make install
rm -rf ${OPENSSL_TMP_FOLDER}
echo "Build completed! Check output libraries in ${OPENSSL_OUTPUT_PATH}"
}
if [ "$OPENSSL_TARGET_ABI" == "armeabi-v7a" ]
then
${NDK_MAKE_TOOLCHAIN} --platform=android-${OPENSSL_TARGET_API} \
--toolchain=arm-linux-androideabi-${OPENSSL_GCC_VERSION} \
--install-dir="${OPENSSL_TMP_FOLDER}/android-toolchain-arm"
export TOOLCHAIN_PATH="${OPENSSL_TMP_FOLDER}/android-toolchain-arm/bin"
export TOOL=arm-linux-androideabi
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export ARCH_FLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16"
export ARCH_LINK="-march=armv7-a -Wl,--fix-cortex-a8"
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
cd ${OPENSSL_TMP_FOLDER}
./Configure android-armv7 shared no-ssl2 no-ssl3 no-hw --openssldir=${OPENSSL_OUTPUT_PATH}
build_library
elif [ "$OPENSSL_TARGET_ABI" == "arm64-v8a" ]
then
${NDK_MAKE_TOOLCHAIN} --platform=android-${OPENSSL_TARGET_API} \
--toolchain=aarch64-linux-android-4.9 \
--install-dir="${OPENSSL_TMP_FOLDER}/android-toolchain-arm64"
export TOOLCHAIN_PATH="${OPENSSL_TMP_FOLDER}/android-toolchain-arm64/bin"
export TOOL=aarch64-linux-android
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export ARCH_FLAGS=
export ARCH_LINK=
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
cd ${OPENSSL_TMP_FOLDER}
./Configure android shared no-ssl2 no-ssl3 no-hw --openssldir=${OPENSSL_OUTPUT_PATH}
build_library
elif [ "$OPENSSL_TARGET_ABI" == "armeabi" ]
then
${NDK_MAKE_TOOLCHAIN} --platform=android-${OPENSSL_TARGET_API} \
--toolchain=arm-linux-androideabi-${OPENSSL_GCC_VERSION} \
--install-dir="${OPENSSL_TMP_FOLDER}/android-toolchain-arm"
export TOOLCHAIN_PATH="${OPENSSL_TMP_FOLDER}/android-toolchain-arm/bin"
export TOOL=arm-linux-androideabi
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export ARCH_FLAGS="-mthumb"
export ARCH_LINK=
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
cd ${OPENSSL_TMP_FOLDER}
./Configure android --openssldir=${OPENSSL_OUTPUT_PATH}
build_library
elif [ "$OPENSSL_TARGET_ABI" == "x86" ]
then
${NDK_MAKE_TOOLCHAIN} --platform=android-${OPENSSL_TARGET_API} \
--toolchain=x86-${OPENSSL_GCC_VERSION} \
--install-dir="${OPENSSL_TMP_FOLDER}/android-toolchain-x86"
export TOOLCHAIN_PATH="${OPENSSL_TMP_FOLDER}/android-toolchain-x86/bin"
export TOOL=i686-linux-android
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export ARCH_FLAGS="-march=i686 -msse3 -mstackrealign -mfpmath=sse"
export ARCH_LINK=
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
cd ${OPENSSL_TMP_FOLDER}
./Configure android-x86 --openssldir=${OPENSSL_OUTPUT_PATH}
build_library
elif [ "$OPENSSL_TARGET_ABI" == "x86_64" ]
then
${NDK_MAKE_TOOLCHAIN} --platform=android-${OPENSSL_TARGET_API} \
--toolchain=x86_64-4.9 \
--install-dir="${OPENSSL_TMP_FOLDER}/android-toolchain-x86_64"
export TOOLCHAIN_PATH="${OPENSSL_TMP_FOLDER}/android-toolchain-x86_64/bin"
export TOOL=x86_64-linux-android
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
cd ${OPENSSL_TMP_FOLDER}
./Configure linux-x86_64 shared no-ssl2 no-ssl3 no-hw --openssldir=${OPENSSL_OUTPUT_PATH}
build_library
elif [ "$OPENSSL_TARGET_ABI" == "mips" ]
then
${NDK_MAKE_TOOLCHAIN} --platform=android-${OPENSSL_TARGET_API} \
--toolchain=mipsel-linux-android-${OPENSSL_GCC_VERSION} \
--install-dir="${OPENSSL_TMP_FOLDER}/android-toolchain-mipsel"
export TOOLCHAIN_PATH="${OPENSSL_TMP_FOLDER}/android-toolchain-mipsel/bin"
export TOOL=mipsel-linux-android
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export ARCH_FLAGS=
export ARCH_LINK=
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
cd ${OPENSSL_TMP_FOLDER}
./Configure android-mips shared no-ssl2 no-ssl3 no-hw --openssldir=${OPENSSL_OUTPUT_PATH}
build_library
elif [ "$OPENSSL_TARGET_ABI" == "mips64" ]
then
${NDK_MAKE_TOOLCHAIN} --platform=android-${OPENSSL_TARGET_API} \
--toolchain=mips64el-linux-android-4.9 \
--install-dir="${OPENSSL_TMP_FOLDER}/android-toolchain-mips64el"
export TOOLCHAIN_PATH="${OPENSSL_TMP_FOLDER}/android-toolchain-mips64el/bin"
export TOOL=mips64el-linux-android
export NDK_TOOLCHAIN_BASENAME=${TOOLCHAIN_PATH}/${TOOL}
export CC=$NDK_TOOLCHAIN_BASENAME-gcc
export CXX=$NDK_TOOLCHAIN_BASENAME-g++
export LINK=${CXX}
export LD=$NDK_TOOLCHAIN_BASENAME-ld
export AR=$NDK_TOOLCHAIN_BASENAME-ar
export RANLIB=$NDK_TOOLCHAIN_BASENAME-ranlib
export STRIP=$NDK_TOOLCHAIN_BASENAME-strip
export ARCH_FLAGS=
export ARCH_LINK=
export CPPFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export CXXFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 -frtti -fexceptions "
export CFLAGS=" ${ARCH_FLAGS} -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-strict-aliasing -finline-limit=64 "
export LDFLAGS=" ${ARCH_LINK} "
cd ${OPENSSL_TMP_FOLDER}
./Configure android-mips64 shared no-ssl2 no-ssl3 no-hw --openssldir=${OPENSSL_OUTPUT_PATH}
build_library
else
echo "Unsupported target ABI: $OPENSSL_TARGET_ABI"
exit 1
fi