|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# ================================================== |
| 5 | +# FUNCTIONS |
| 6 | +# ================================================== |
| 7 | +arch_is_invalid() { |
| 8 | + local valid=( arm arm64 x86 x86_64 ) |
| 9 | + local value=$1 |
| 10 | + for elem in "${valid[@]}"; do |
| 11 | + [[ $value == $elem ]] && return 1 |
| 12 | + done |
| 13 | + return 0 |
| 14 | +} |
| 15 | +# ================================================== |
| 16 | + |
| 17 | +if [ "$#" -ne 1 ]; then |
| 18 | + echo "❌ Illegal number of parameters ($#). Expected 1." |
| 19 | +fi |
| 20 | + |
| 21 | +TARGET_ARCH=${1} |
| 22 | + |
| 23 | +if arch_is_invalid "${TARGET_ARCH}"; then |
| 24 | + echo "❌ Architecture NOT supported: ${TARGET_ARCH}. Exiting." |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +echo "==================================================" |
| 29 | +echo "⚙️ Building OpenSSL for Android > ${TARGET_ARCH} <" |
| 30 | +echo "==================================================" |
| 31 | + |
| 32 | +set -x |
| 33 | + |
| 34 | +# Set directory |
| 35 | +SCRIPTPATH=`realpath .` |
| 36 | + |
| 37 | +# If OPENSSL_DIR is not set, then fallback to a default value |
| 38 | +OPENSSL_DIR=${OPENSSL_DIR:-"../openssl"} |
| 39 | + |
| 40 | +# Find the toolchain for your build machine |
| 41 | +toolchains_path=$(python3 toolchains_path.py --ndk ${ANDROID_NDK_HOME}) |
| 42 | + |
| 43 | +# Configure the OpenSSL environment, refer to NOTES.ANDROID in OPENSSL_DIR |
| 44 | +# Set compiler clang, instead of gcc by default |
| 45 | +CC=clang |
| 46 | + |
| 47 | +# Add toolchains bin directory to PATH |
| 48 | +PATH=$toolchains_path/bin:$PATH |
| 49 | + |
| 50 | +# Set the Android API levels |
| 51 | +# ANDROID_API=21 |
| 52 | + |
| 53 | +# Set the target architecture |
| 54 | +# Can be android-arm, android-arm64, android-x86, android-x86 etc |
| 55 | +architecture=android-${TARGET_ARCH} |
| 56 | + |
| 57 | +# Create the make file |
| 58 | +cd ${OPENSSL_DIR} |
| 59 | +# ./Configure ${architecture} -D__ANDROID_API__=$ANDROID_API |
| 60 | +./Configure ${architecture} |
| 61 | + |
| 62 | +# Build |
| 63 | +make |
| 64 | + |
| 65 | +# Copy the outputs |
| 66 | +OUTPUT_INCLUDE=$SCRIPTPATH/output/include |
| 67 | +OUTPUT_LIB=$SCRIPTPATH/output/lib/${TARGET_ARCH} |
| 68 | +mkdir -p $OUTPUT_INCLUDE |
| 69 | +mkdir -p $OUTPUT_LIB |
| 70 | +cp -RL include/crypto $OUTPUT_INCLUDE |
| 71 | +cp -RL include/internal $OUTPUT_INCLUDE |
| 72 | +cp -RL include/openssl $OUTPUT_INCLUDE |
| 73 | +cp libcrypto.so $OUTPUT_LIB |
| 74 | +cp libcrypto.a $OUTPUT_LIB |
| 75 | +cp libssl.so $OUTPUT_LIB |
| 76 | +cp libssl.a $OUTPUT_LIB |
0 commit comments