-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-boringssl.sh
executable file
·79 lines (66 loc) · 2.56 KB
/
build-boringssl.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
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# --- Configuration ---
DEFAULT_ANDROID_API_LEVEL="android-29"
ANDROID_ABIS=("armeabi-v7a" "arm64-v8a" "x86" "x86_64")
# ---
# Get the directory of the script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
BORINGSSL_SRC_DIR="$SCRIPT_DIR" # Assuming the script is in the boringssl root
# --- Argument Parsing & NDK Setup ---
if [ -z "$1" ]; then
echo "Usage: $0 [<path_to_android_ndk>]"
echo "If <path_to_android_ndk> is not provided, the script will use the ANDROID_NDK environment variable."
if [ -z "$ANDROID_NDK" ]; then
echo "Error: Neither command-line argument nor ANDROID_NDK environment variable is set."
exit 1
else
echo "Using ANDROID_NDK from environment: $ANDROID_NDK"
# ANDROID_NDK is already set
fi
else
export ANDROID_NDK="$1" # Export it so CMake toolchain can potentially use it
echo "Using ANDROID_NDK from argument: $ANDROID_NDK"
fi
# Validate NDK path
if [ ! -d "$ANDROID_NDK" ]; then
echo "Error: Android NDK directory not found: $ANDROID_NDK"
exit 1
fi
# Validate CMake toolchain file
CMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake"
if [ ! -f "$CMAKE_TOOLCHAIN_FILE" ]; then
echo "Error: CMake toolchain file not found: $CMAKE_TOOLCHAIN_FILE"
exit 1
fi
# ---
ANDROID_API_LEVEL=${ANDROID_API_LEVEL:-$DEFAULT_ANDROID_API_LEVEL} # Allow override via env var
echo "Using Android API Level: ${ANDROID_API_LEVEL#android-}" # Print just the number
# Loop through each ABI and build
for ABI in "${ANDROID_ABIS[@]}"; do
BUILD_DIR="${BORINGSSL_SRC_DIR}/build_android_${ABI}"
echo ""
echo "--------------------------------------------------"
echo "Configuring for ABI: ${ABI}, API Level: ${ANDROID_API_LEVEL#android-}"
echo "Build directory: ${BUILD_DIR}"
echo "--------------------------------------------------"
# Clean previous build directory
rm -rf "${BUILD_DIR}"
mkdir -p "${BUILD_DIR}"
cmake -DANDROID_ABI=${ABI} \
-DANDROID_PLATFORM=${ANDROID_API_LEVEL} \
-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" \
-GNinja -B "${BUILD_DIR}" "${BORINGSSL_SRC_DIR}"
echo "Building for ABI: ${ABI}"
ninja -C "${BUILD_DIR}"
echo "Successfully built for ABI: ${ABI}"
done
echo ""
echo "--------------------------------------------------"
echo "Android builds for all ABIs completed successfully."
echo "Output directories:"
for ABI in "${ANDROID_ABIS[@]}"; do
echo "- ${BORINGSSL_SRC_DIR}/build_android_${ABI}"
done
echo "--------------------------------------------------"