-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_android.sh
More file actions
executable file
·119 lines (92 loc) · 2.98 KB
/
build_android.sh
File metadata and controls
executable file
·119 lines (92 loc) · 2.98 KB
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
#!/bin/sh
#set -e
OPENSSL="openssl-3.6.0"
ANDROID_API=24
if [ -n "$ANDROID_NDK_ROOT" ]; then
echo "[INFO] Using global ANDROID_NDK_ROOT: $ANDROID_NDK_ROOT"
else
echo "[INFO] ANDROID_NDK_ROOT not set, setting to default value"
export ANDROID_NDK_ROOT="/Users/przemek/Library/Android/ndk-r27d"
fi
if [ ! -d "$ANDROID_NDK_ROOT" ]; then
echo "[ERROR] NDK not found in $ANDROID_NDK_ROOT"
exit 1
fi
archs=(armeabi-v7a arm64-v8a x86 x86_64)
#archs=(x86)
TOOLCHAIN_BIN="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin"
export PATH=$TOOLCHAIN_BIN:$PATH
WORKDIR=`pwd`"/work"
if [ ! -e "$WORKDIR" ]; then
echo "No such $WORKDIR directory"
exit 1
fi
LIBDIR=`pwd`"/libs"
cd $WORKDIR
OPENSSLURL="https://github.com/openssl/openssl/releases/download/${OPENSSL}/${OPENSSL}.tar.gz"
if [ ! -e "$OPENSSL.tar.gz" ]; then
echo "[INFO] OpenSSL not found, downloading using $OPENSSLURL"
curl -LO $OPENSSLURL
if [ "$?" -gt 0 ]; then
echo "[ERROR] Download failed."
exit 1
fi
fi
## https://developer.android.com/ndk/guides/abis
for arch in ${archs[@]}; do
case ${arch} in
"armeabi-v7a")
CONFIG_ARGS="android-arm"
CC="armv7a-linux-androideabi${ANDROID_API}-clang"
CXX="armv7a-linux-androideabi${ANDROID_API}-clang++"
;;
"arm64-v8a")
CONFIG_ARGS="android-arm64"
CC="aarch64-linux-android${ANDROID_API}-clang"
CXX="aarch64-linux-android${ANDROID_API}-clang++"
;;
"x86")
CONFIG_ARGS="android-x86 no-asm"
CC="i686-linux-android${ANDROID_API}-clang"
CXX="i686-linux-android${ANDROID_API}-clang++"
;;
"x86_64")
CONFIG_ARGS="android-x86_64"
CC="x86_64-linux-android${ANDROID_API}-clang"
CXX="x86_64-linux-android${ANDROID_API}-clang++"
;;
esac
export CPPFLAGS="-fPIC"
export CXXFLAGS="-fPIC"
echo "[INFO] Unziping OpenSSL $OPENSSL"
rm -rf $OPENSSL
tar zxf $OPENSSL.tar.gz
echo "[INFO] Configuring OpenSSL"
cd $OPENSSL
./Configure $CONFIG_ARGS -D__ANDROID_API__=$ANDROID_API no-tests
# SSL must be compilied for multi threading. If this check fails verify
# if multi threading is still properly configured.
CONF_FILE="include/openssl/configuration.h"
if ! grep -q "OPENSSL_THREADS" "$CONF_FILE"; then
echo "[ERROR] Configuration did not define OPENSSL_THREADS makro"
exit 1
fi
echo "[INFO] Building OpenSSL for arch: $arch"
make
cd ..
if [ ! -e "$OPENSSL/libssl.so" ]; then
echo No such file $OPENSSL/libssl.so
exit 1
fi
if [ ! -e "$OPENSSL/libcrypto.so" ]; then
echo No such file $OPENSSL/libcrypto.so
exit 1
fi
[ ! -e "$LIBDIR/$arch" ] && mkdir -p "$LIBDIR/$arch"
cp "$OPENSSL/libssl.so" "$LIBDIR/$arch/"
cp "$OPENSSL/libcrypto.so" "$LIBDIR/$arch/"
done
cd ..
[ -e ./include ] && rm -r ./include
cp -r ${WORKDIR}/${OPENSSL}/include ./include
echo "[INFO] OpenSSL built successfully!"