-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathopenssl-build-target-archs
More file actions
executable file
·159 lines (119 loc) · 4.63 KB
/
Copy pathopenssl-build-target-archs
File metadata and controls
executable file
·159 lines (119 loc) · 4.63 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
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
#!/bin/bash -e
# @author Vincenzo Esposito (v.esposito@voismart.it)
# Hints and code taken also from https://proandroiddev.com/tutorial-compile-openssl-to-1-1-1-for-android-application-87137968fee
set -e
# Source variables from config.conf file
. config.conf
##############################################################################
############################ FUNCTIONS ##############################
##############################################################################
function initialSetup {
CUR_DIR="$(pwd)"
OPENSSL_SRC_PATH="$DOWNLOAD_DIR/${OPENSSL_DIR_NAME}"
OPENSSL_TMP_FOLDER="/tmp/openssl"
}
function setupPathsAndExports {
NDK_PATH="$DOWNLOAD_DIR/${NDK_DIR_NAME}"
LIB_PATH="${OPENSSL_BUILD_OUT_PATH}/libs"
LOG_PATH="${OPENSSL_BUILD_OUT_PATH}/logs"
# Required for OpenSSL + new NDK
export ANDROID_NDK_HOME="$NDK_PATH"
export ANDROID_NDK_ROOT="$NDK_PATH"
TOOLCHAIN_PATH="$NDK_PATH/toolchains/llvm/prebuilt/linux-x86_64/bin"
export PATH="$TOOLCHAIN_PATH:$PATH"
# Android API (needed by OpenSSL)
export ANDROID_API="${OPENSSL_TARGET_NDK_LEVEL}"
}
function clearBuildDirectory {
rm -rf "${OPENSSL_BUILD_OUT_PATH}"
mkdir -p "${LIB_PATH}"
mkdir -p "${LOG_PATH}"
}
function clearTmpDirectory {
rm -rf "$OPENSSL_TMP_FOLDER"
mkdir -p "$OPENSSL_TMP_FOLDER"
cp -r "${OPENSSL_SRC_PATH}"/* "${OPENSSL_TMP_FOLDER}"
}
function getArchitecture {
OPENSSL_TARGET_ABI=$1
case "$OPENSSL_TARGET_ABI" in
armeabi-v7a)
ARCHITECTURE="android-arm"
export CC="armv7a-linux-androideabi${ANDROID_API}-clang"
;;
arm64-v8a)
ARCHITECTURE="android-arm64"
export CC="aarch64-linux-android${ANDROID_API}-clang"
;;
x86)
ARCHITECTURE="android-x86 no-asm"
export CC="i686-linux-android${ANDROID_API}-clang"
;;
x86_64)
ARCHITECTURE="android-x86_64"
export CC="x86_64-linux-android${ANDROID_API}-clang"
;;
*)
echo "Unsupported ABI: $OPENSSL_TARGET_ABI"
exit 1
;;
esac
export AR="llvm-ar"
export RANLIB="llvm-ranlib"
}
##############################################################################
############################ INIT ############################
##############################################################################
# Initial variables setup
initialSetup
# Set final paths and exports
setupPathsAndExports
# Clear and recreate the build output directory
clearBuildDirectory
# Set clang compiler, instead of gcc by default
# No longer required with newer NDK versions, which use clang by default, but leaving it here for older NDK compatibility
# CC=clang
##############################################################################
############################ MAIN ############################
##############################################################################
# Build OpenSSL for each ARCH specified in config.conf
for arch in "${TARGET_ARCHS[@]}"
do
echo "======================================"
echo "Configuring OpenSSL for target arch $arch ..."
echo "======================================"
# Clear the tmp source directory
clearTmpDirectory
# Go to source files
cd ${OPENSSL_TMP_FOLDER}
OPENSSL_OUTPUT_PATH=$LIB_PATH/$arch
# Set the target architecture
# Can be android-arm, android-arm64, android-x86 etc
getArchitecture $arch
echo "Using:"
echo " ARCH=$ARCHITECTURE"
echo " CC=$CC"
# Create Makefile
./Configure $ARCHITECTURE -D__ANDROID_API__="$ANDROID_API" >> "${LOG_PATH}/${arch}.log" 2>&1
# Build Openssl
echo "Building OpenSSL Library for Android arch $arch"
make clean >> "${LOG_PATH}/${arch}.log" 2>&1
make -j$(nproc) >> "${LOG_PATH}/${arch}.log" 2>&1
# Output folders
mkdir -p "$OPENSSL_OUTPUT_PATH/lib"
mkdir -p "$OPENSSL_OUTPUT_PATH/include"
# Copy Headers
cp -RL include/openssl "$OPENSSL_OUTPUT_PATH/include"
# Copy Static libs
cp libssl.a "$OPENSSL_OUTPUT_PATH/lib"
cp libcrypto.a "$OPENSSL_OUTPUT_PATH/lib"
echo "Build completed for $arch"
done
##############################################################################
############################### CLEANUP ######################################
##############################################################################
rm -rf "$OPENSSL_TMP_FOLDER"
echo "======================================"
echo "Finished building OpenSSL!"
echo "Output: $OPENSSL_BUILD_OUT_PATH"
echo "======================================"