-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathopenssl_build.sh
executable file
·88 lines (74 loc) · 3.31 KB
/
openssl_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
#!/bin/bash -e
################################################################################
# Copyright 2021-2025 217heidai<[email protected]>
#
# 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.
################################################################################
################################################################################
# build OpenSSL for Android armeabi mips mips64
# support Linux and macOS
################################################################################
WORK_PATH=$(cd "$(dirname "$0")";pwd)
ANDROID_TARGET_API=$1
ANDROID_TARGET_ABI=$2
OPENSSL_VERSION=$3
ANDROID_NDK_VERSION=$4
ANDROID_NDK_PATH=${WORK_PATH}/android-ndk-${ANDROID_NDK_VERSION}
OPENSSL_PATH=${WORK_PATH}/openssl-${OPENSSL_VERSION}
OUTPUT_PATH=${WORK_PATH}/openssl_${OPENSSL_VERSION}_${ANDROID_TARGET_ABI}
OPENSSL_OPTIONS="no-apps no-asm no-docs no-engine no-gost no-legacy no-shared no-ssl no-tests no-zlib"
if [ "$(uname -s)" == "Darwin" ]; then
echo "Build on macOS..."
PLATFORM="darwin"
export alias nproc="sysctl -n hw.logicalcpu"
else
echo "Build on Linux..."
PLATFORM="linux"
fi
function build(){
mkdir ${OUTPUT_PATH}
cd ${OPENSSL_PATH}
export ANDROID_NDK_ROOT=${ANDROID_NDK_PATH}
export PATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${PLATFORM}-x86_64/bin:$PATH
export CXXFLAGS="-fPIC -Os"
export CPPFLAGS="-DANDROID -fPIC -Os"
if [ "${ANDROID_TARGET_ABI}" == "armeabi" ]; then
export PATH=${ANDROID_NDK_ROOT}/toolchains/arm-linux-androideabi-4.9/prebuilt/${PLATFORM}-x86_64/bin:$PATH
./Configure android-arm -D__ANDROID_API__=${ANDROID_TARGET_API} -static ${OPENSSL_OPTIONS} --prefix=${OUTPUT_PATH}
elif [ "${ANDROID_TARGET_ABI}" == "mips" ]; then
export PATH=${ANDROID_NDK_ROOT}/toolchains/mipsel-linux-android-4.9/prebuilt/${PLATFORM}-x86_64/bin:$PATH
./Configure android-mips -D__ANDROID_API__=${ANDROID_TARGET_API} -static ${OPENSSL_OPTIONS} --prefix=${OUTPUT_PATH}
elif [ "${ANDROID_TARGET_ABI}" == "mips64" ]; then
export PATH=${ANDROID_NDK_ROOT}/toolchains/mips64el-linux-android-4.9/prebuilt/${PLATFORM}-x86_64/bin:$PATH
./Configure android-mips64 -D__ANDROID_API__=${ANDROID_TARGET_API} -static ${OPENSSL_OPTIONS} --prefix=${OUTPUT_PATH}
else
echo "Unsupported target ABI: ${ANDROID_TARGET_ABI}"
exit 1
fi
make -j$(nproc)
make install
echo "Build completed! Check output libraries in ${OUTPUT_PATH}"
}
function clean(){
if [ -d ${OUTPUT_PATH} ]; then
rm -rf ${OUTPUT_PATH}/bin
rm -rf ${OUTPUT_PATH}/share
rm -rf ${OUTPUT_PATH}/ssl
rm -rf ${OUTPUT_PATH}/lib/cmake
rm -rf ${OUTPUT_PATH}/lib/engines-3
rm -rf ${OUTPUT_PATH}/lib/ossl-modules
rm -rf ${OUTPUT_PATH}/lib/pkgconfig
fi
}
build
clean