This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-openssl-android.sh
executable file
·85 lines (71 loc) · 2.5 KB
/
build-openssl-android.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
#! /usr/bin/env bash
set -eux
OPENSSL_FULL_VERSION="openssl-1.1.1h"
if [ ! -f "$OPENSSL_FULL_VERSION.tar.gz" ]; then
curl -O https://www.openssl.org/source/$OPENSSL_FULL_VERSION.tar.gz
fi
tar -xvzf $OPENSSL_FULL_VERSION.tar.gz
cd $OPENSSL_FULL_VERSION
if [ ! "${ANDROID_NDK_HOME}" ]; then
echo "ANDROID_NDK_HOME environment variable not set, set and rerun"
exit 1
fi
ANDROID_LIB_ROOT=$(pwd)/../libs/openssl-lib
OPENSSL_CONFIGURE_OPTIONS="no-shared"
rm -rf "${ANDROID_LIB_ROOT:?}/*"
for ANDROID_TARGET_PLATFORM in armeabi-v7a arm64-v8a x86 x86_64; do
echo "Building for libcrypto.a and libssl.a for ${ANDROID_TARGET_PLATFORM}"
case "${ANDROID_TARGET_PLATFORM}" in
armeabi-v7a)
PLATFORM_OUTPUT_DIR=armeabi-v7a
OPENSSL_CONFIGURE_ARCH=android-arm
NDK_PREFIX=armv7a-linux-androideabi
;;
arm64-v8a)
PLATFORM_OUTPUT_DIR=arm64-v8a
OPENSSL_CONFIGURE_ARCH=android-arm64
NDK_PREFIX=aarch64-linux-android
;;
x86)
PLATFORM_OUTPUT_DIR=x86
OPENSSL_CONFIGURE_ARCH=android-x86
NDK_PREFIX=i686-linux-android
;;
x86_64)
PLATFORM_OUTPUT_DIR=x86_64
OPENSSL_CONFIGURE_ARCH=android-x86_64
NDK_PREFIX=x86_64-linux-android
;;
*)
echo "Unsupported build platform:${ANDROID_TARGET_PLATFORM}"
exit 1
;;
esac
mkdir -p "${ANDROID_LIB_ROOT}/${ANDROID_TARGET_PLATFORM}"
export HOST_TAG="linux-x86_64"
export TOOLCHAIN=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$HOST_TAG
export AR=$TOOLCHAIN/bin/${NDK_PREFIX}-ar
export AS=$TOOLCHAIN/bin/${NDK_PREFIX}-as
export CC=$TOOLCHAIN/bin/${NDK_PREFIX}${ANDROID_API_VERSION}-clang
export CXX=$TOOLCHAIN/bin/${NDK_PREFIX}${ANDROID_API_VERSION}-clang++
export LD=$TOOLCHAIN/bin/${NDK_PREFIX}-ld
export RANLIB=$TOOLCHAIN/bin/${NDK_PREFIX}-ranlib
export STRIP=$TOOLCHAIN/bin/${NDK_PREFIX}-strip
export PATH=$TOOLCHAIN/bin/:$PATH
./Configure ${OPENSSL_CONFIGURE_ARCH} \
--prefix="${ANDROID_LIB_ROOT}/${PLATFORM_OUTPUT_DIR}" \
--openssldir="${ANDROID_LIB_ROOT}/${PLATFORM_OUTPUT_DIR}" \
-D__ANDROID_API__=${ANDROID_API_VERSION} \
${OPENSSL_CONFIGURE_OPTIONS}
if [ $? -ne 0 ]; then
echo "Error executing:./Configure ${CONFIGURE_ARCH} ${OPENSSL_CONFIGURE_OPTIONS}"
exit 1
fi
make clean
make
if [ $? -ne 0 ]; then
echo "Error executing make for platform:${ANDROID_TARGET_PLATFORM}"
exit 1
fi
make install
done