forked from nikialeksey/pjsip-android-builder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
openssl-build-target-archs
executable file
·125 lines (102 loc) · 4.01 KB
/
openssl-build-target-archs
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
#!/bin/bash -e
# @author Vincenzo Esposito ([email protected])
# 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 {
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"
# Export ANDROID_NDK_ROOT env var
export ANDROID_NDK_ROOT=$NDK_PATH
export CFLAGS="-fPIC"
# Add toolchains bin directory to PATH
# for more info check https://github.com/openssl/openssl/blob/master/NOTES-ANDROID.md
PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
}
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
if [ "$OPENSSL_TARGET_ABI" == "armeabi-v7a" ]
then
ARCHITECTURE="android-arm"
elif [ "$OPENSSL_TARGET_ABI" == "arm64-v8a" ]
then
ARCHITECTURE="android-arm64"
elif [ "$OPENSSL_TARGET_ABI" == "x86" ]
then
# Use "no-asm" arg as specified in Merge Request #28 --- Use Only for x86 ARCH
ARCHITECTURE="android-x86 no-asm"
elif [ "$OPENSSL_TARGET_ABI" == "x86_64" ]
then
ARCHITECTURE="android-x86_64"
else
echo "Unsupported target ABI: $OPENSSL_TARGET_ABI"
exit 1
fi
}
##############################################################################
############################ INIT ############################
##############################################################################
# Initial variables setup
initialSetup
# Set final paths and exports
setupPathsAndExports
# Clear and recreate the build output directory
clearBuildDirectory
##############################################################################
############################ MAIN ############################
##############################################################################
# Build OpenSSL for each ARCH specified in config.conf
for arch in "${TARGET_ARCHS[@]}"
do
echo "Configuring OpenSSL for target arch $arch ..."
# 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
ARCHITECTURE="android-arm"
getArchitecture $arch
# Create Makefile
./Configure $ARCHITECTURE -D__ANDROID_API__=${OPENSSL_TARGET_NDK_LEVEL} >> "${LOG_PATH}/${arch}.log" 2>&1
# Build Openssl
echo "Building OpenSSL Library for Android arch $arch"
make >> "${LOG_PATH}/${arch}.log" 2>&1
mkdir -p $OPENSSL_OUTPUT_PATH
OUTPUT_LIB=$OPENSSL_OUTPUT_PATH/lib
mkdir -p $OUTPUT_LIB
OUTPUT_INCLUDE=${OPENSSL_OUTPUT_PATH}/include
mkdir -p $OUTPUT_INCLUDE
cp -RL include/openssl $OUTPUT_INCLUDE
# Copy libs to final destination folder
cp libssl.a $OUTPUT_LIB
cp libcrypto.a $OUTPUT_LIB
# Uncomment if you want .so libs (pjsip only needs the static libs)
# cp libssl.so $OUTPUT_LIB
# cp libcrypto.so $OUTPUT_LIB
echo "Build completed! Check output libraries in ${OPENSSL_OUTPUT_PATH}"
done
# Remove tmp folder
rm -rf ${OPENSSL_TMP_FOLDER}
echo "Finished building OpenSSL! Check output folder: ${OPENSSL_BUILD_OUT_PATH}"
set +e