-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcross-build.sh
executable file
·104 lines (85 loc) · 2.83 KB
/
cross-build.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
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
#!/usr/bin/env bash
#
# © 2024 AO Kaspersky Lab
# Licensed under the OpenSSL License
set -e
EXAMPLE_DIR="$(dirname "$(realpath "${0}")")"
KOS_DIR="$(realpath "${EXAMPLE_DIR}/../..")"
ROOT_DIR="$(dirname ${KOS_DIR})"
BUILD="${EXAMPLE_DIR}/build"
BUILD_TARGET=
function PrintHelp () {
cat<<HELP
Script to build and run an example of using BoringSSL library for KasperskyOS.
USAGE:
cross-build.sh [BUILD_TARGET] [-h | --help]
BUILD_TARGET:
qemu - to build and run the example on QEMU (default value).
rpi - to create a file system image called rpi4kos.img for a bootable SD card.
This image can be directly copied onto an SD card using the dd utility,
allowing the example to be run on Raspberry Pi.
OPTIONS:
-h, --help
Help text.
HELP
}
# Parse arguments.
while [ -n "${1}" ]; do
case "${1}" in
-h | --help) PrintHelp
exit 0;;
qemu) BUILD_TARGET=sim;;
rpi) BUILD_TARGET=sd-image;;
*) echo "Unknown option -'${1}'."
PrintHelp
exit 1;;
esac
shift
done
if [ -z "${BUILD_TARGET}" ]; then
echo "Build target is not specified. Default build target is qemu."
BUILD_TARGET=sim
fi
# Prepare environment.
if [ -z "${SDK_PREFIX}" ]; then
echo "Can't get path to the installed KasperskyOS SDK."
echo "Please specify it via the SDK_PREFIX environment variable."
exit 1
fi
if [ -z "${TARGET}" ]; then
echo "Target platform is not specified. Try to autodetect..."
TARGETS=($(ls -d "${SDK_PREFIX}"/sysroot-* | sed 's|.*sysroot-\(.*\)|\1|'))
if [ ${#TARGETS[@]} -gt 1 ]; then
echo More than one target platform found: ${TARGETS[*]}.
echo Use the TARGET environment variable to specify exact platform.
exit 1
fi
export TARGET=${TARGETS[0]}
echo "Platform ${TARGET} will be used."
fi
export LANG=C
export PKG_CONFIG=""
export PATH="${SDK_PREFIX}/toolchain/bin:${PATH}"
export BUILD_WITH_CLANG=
export BUILD_WITH_GCC=
TOOLCHAIN_SUFFIX=""
if [ "${BUILD_WITH_CLANG}" == "y" ];then
TOOLCHAIN_SUFFIX="-clang"
fi
if [ "${BUILD_WITH_GCC}" == "y" ];then
TOOLCHAIN_SUFFIX="-gcc"
fi
# Copy BoringSSL sources to the third_party/boringssl directory if it is a git submodule.
BORINGSSL_THIRDP_DIR="${EXAMPLE_DIR}/third_party/boringssl"
if [ ! -d "${BORINGSSL_THIRDP_DIR}" ]; then
mkdir -p "${BORINGSSL_THIRDP_DIR}"
pushd "${ROOT_DIR}"
cp -r $(ls -I kos -I install) "${BORINGSSL_THIRDP_DIR}"
popd
fi
# Build example.
"${SDK_PREFIX}/toolchain/bin/cmake" -G "Unix Makefiles" -B "${BUILD}" \
-D CMAKE_BUILD_TYPE:STRING=Debug \
-D CMAKE_FIND_ROOT_PATH="${PREFIX_DIR}/sysroot-${TARGET}" \
-D CMAKE_TOOLCHAIN_FILE="${SDK_PREFIX}/toolchain/share/toolchain-${TARGET}${TOOLCHAIN_SUFFIX}.cmake" \
"${EXAMPLE_DIR}" && "${SDK_PREFIX}/toolchain/bin/cmake" --build "${BUILD}" -j`nproc` --target ${BUILD_TARGET}