forked from KDAB/android_openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_ssl.sh
executable file
·185 lines (159 loc) · 5.76 KB
/
build_ssl.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
#!/bin/bash
## Prerequisites
## On both Linux, macOS: 'patchelf' command is needed for OpenSSL 3+
## On macOS:
## - bash shell version 4+ is required
## - wget command
BUILD_DIR=$(pwd)
# Comment out the line for any configuration you don't want to build
declare -a params=(
''
'no-asm'
)
declare -A ssl_versions_output_dir=(
["ssl_1.1"]="1.1*"
["ssl_3"]="3*"
)
declare -A ssl_versions_ndk=(
["1.1.1u"]="$HOME/android/ndk/21.4.7075529"
["3.1.1"]="$HOME/android/ndk/25.2.9519653"
)
declare -A architectures=(
["x86_64"]="x86_64"
["x86"]="x86"
["arm64"]="arm64-v8a"
["arm"]="armeabi-v7a"
)
download_ssl_version() {
ssl_version=$1
echo "Downloading OpenSSL $ssl_version"
if [ ! -f "openssl-$ssl_version.tar.gz" ]; then
wget -q --show-progress "https://www.openssl.org/source/openssl-$ssl_version.tar.gz"
fi
}
extract_package() {
qt_arch=$1
version=$2
ssl_version=$3
echo "Extracting OpenSSL $ssl_version under $(pwd)"
rm -fr "$qt_arch" "$version/$qt_arch"
mkdir -p "$version/$qt_arch" || exit 1
rm -fr "openssl-$ssl_version"
tar xf "openssl-$ssl_version.tar.gz" || exit 1
}
configure_ssl() {
ndk=$1
param=$2
ssl_version=$3
version_out_dir=$4
arch=$5
log_file=$6
export ANDROID_NDK_HOME="${ndk}"
export ANDROID_NDK_ROOT="${ndk}"
declare hosts=("linux-x86_64" "linux-x86" "darwin-x86_64" "darwin-x86")
for host in "${hosts[@]}"; do
if [ -d "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$host/bin" ]; then
ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$host/bin"
export PATH="$ANDROID_TOOLCHAIN:$PATH"
break
fi
done
case $version_out_dir in
ssl_1.1)
ANDROID_API=21
;;
ssl_3)
ANDROID_API=23
;;
esac
config_params=( "${param}" "shared" "android-${arch}"
"-U__ANDROID_API__" "-D__ANDROID_API__=${ANDROID_API}" )
echo "Configuring OpenSSL $ssl_version with parameters: ${config_params[@]}"
./Configure "${config_params[@]}" 2>&1 1>${log_file} | tee -a ${log_file} || exit 1
make depend
}
build_ssl_1_1() {
# Qt up to 6.4 is using OpenSSL 1.1.x but the library is suffixed with _1_1.so
version_out_dir=$1
qt_arch=$2
log_file=$3
echo "Building..."
make -j$(nproc) SHLIB_VERSION_NUMBER= SHLIB_EXT=_1_1.so build_libs 2>&1 1>>${log_file} | tee -a ${log_file} || exit 1
llvm-strip --strip-all libcrypto_1_1.so
llvm-strip --strip-all libssl_1_1.so
cp libcrypto_1_1.so libssl_1_1.so "../$version_out_dir/$qt_arch" || exit 1
cp libcrypto.a libssl.a "../$version_out_dir/$qt_arch" || exit 1
ln -s "../$version_out_dir/$qt_arch/libcrypto_1_1.so" "../$version_out_dir/$qt_arch/libcrypto.so"
ln -s "../$version_out_dir/$qt_arch/libssl_1_1.so" "../$version_out_dir/$qt_arch/libssl.so"
ln -s "../$version_out_dir/include" "../$version_out_dir/$qt_arch/include"
}
build_ssl_3() {
# Qt 6.5.0+ is using OpenSSL 3.1.x but the library is suffixed with _3.so
version_out_dir=$1
qt_arch=$2
log_file=$3
echo "Building..."
make -j$(nproc) SHLIB_VERSION_NUMBER= build_libs 2>&1 1>>${log_file} | tee -a ${log_file} || exit 1
llvm-strip --strip-all libcrypto.so
llvm-strip --strip-all libssl.so
out_path="../$version_out_dir/$qt_arch"
cp libcrypto.a libssl.a "${out_path}" || exit 1
cp libcrypto.so "${out_path}/libcrypto_3.so" || exit 1
cp libssl.so "${out_path}/libssl_3.so" || exit 1
ln -s "${out_path}/libcrypto_3.so" "${out_path}/libcrypto.so"
ln -s "${out_path}/libssl_3.so" "${out_path}/libssl.so"
ln -s "../$version_out_dir/include" "../$version_out_dir/$qt_arch/include"
pushd ${out_path} || exit 1
patchelf --set-soname libcrypto_3.so libcrypto_3.so || exit 1
patchelf --set-soname libssl_3.so libssl_3.so || exit 1
patchelf --replace-needed libcrypto.so libcrypto_3.so libssl_3.so || exit 1
popd
}
for param in "${params[@]}"; do
if [ "${param}" ]; then
rm -fr "${param}"
mkdir "${param}"
pushd "${param}"
fi
for ssl_version in "${!ssl_versions_ndk[@]}"; do
download_ssl_version $ssl_version
for version_out_dir in "${!ssl_versions_output_dir[@]}"; do
if [[ $ssl_version != ${ssl_versions_output_dir[$version_out_dir]} ]]; then
continue
fi
echo "Build $ssl_version"
for arch in "${!architectures[@]}"; do
qt_arch="${architectures[$arch]}"
extract_package $qt_arch $version_out_dir $ssl_version
pushd "openssl-$ssl_version" || exit 1
log_file="build_${arch}_${ssl_version}.log"
ndk="${ssl_versions_ndk[$ssl_version]}"
configure_ssl "${ndk}" "${param}" ${ssl_version} ${version_out_dir} ${arch} ${log_file}
if [ "$arch" == "arm64" ] && [ ! -d "../$version_out_dir/include/openssl" ]; then
cp -a include "../$version_out_dir" || exit 1
fi
case $version_out_dir in
ssl_1.1)
build_ssl_1_1 ${version_out_dir} ${qt_arch} ${log_file}
;;
ssl_3)
build_ssl_3 ${version_out_dir} ${qt_arch} ${log_file}
;;
*)
echo "Unhandled OpenSSL version $version_out_dir"
exit 1
;;
esac
popd
done
done
rm -fr "openssl-$ssl_version"
rm "openssl-$ssl_version.tar.gz"
done
if [ "${param}" ]; then
popd
fi
done
# Clean include folder
find . -name "*.in" -delete
find . -name "*.def" -delete