Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·151 lines (134 loc) · 4.11 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·151 lines (134 loc) · 4.11 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
#! /usr/bin/env bash
# Copyright (c) 2025, Arm Limited.
# SPDX-License-Identifier: Apache-2.0
#
# Build script for the Zephyr Actuation Module
#
# This script builds the Zephyr Actuation Module for the specified target board.
#
# Usage: ./build.sh [OPTIONS]
# Color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
# Root directory
ROOT_DIR=$(dirname "$(realpath "$0")")
set -e
set -u
# Build options
BUILD_TEST_FLAG=0
ZEPHYR_TARGET_LIST=("fvp_baser_aemv8r_smp" "s32z270dc2_rtu0_r52@D")
ZEPHYR_TARGET=${ZEPHYR_TARGET_LIST[0]} # Default target is FVP
function usage() {
echo -e "${GREEN}Usage: $0 [OPTIONS]${NC}"
echo -e "------------------------------------------------"
echo -e "${GREEN} -t ${NC}Zephyr target board: ${ZEPHYR_TARGET_LIST[*]}"
echo -e "${GREEN} default: ${ZEPHYR_TARGET_LIST[0]} (FVP).${NC}"
echo -e "${GREEN} -c ${NC}Clean all builds and exit."
echo -e "${GREEN} -h ${NC}Display the usage and exit."
echo ""
echo -e "${GREEN} Optional arguments to build Zephyr test programs:${NC}"
echo -e "${GREEN} --unit-test ${NC}Build Zephyr unit test program."
echo -e "${GREEN} --dds-publisher ${NC}Build Zephyr DDS publisher."
echo -e "${GREEN} --dds-subscriber ${NC}Build Zephyr DDS subscriber."
}
function parse_args() {
new_args=()
for arg in "$@"; do
case $arg in
--help)
usage
exit 0
;;
--unit-test)
BUILD_TEST_FLAG=1
shift
;;
--dds-publisher)
BUILD_TEST_FLAG=2
shift
;;
--dds-subscriber)
BUILD_TEST_FLAG=3
shift
;;
*)
new_args+=("$arg")
;;
esac
done
set -- "${new_args[@]}" # Reset the positional parameters to the remaining arguments
while getopts "t:ch" opt; do
case ${opt} in
t )
ZEPHYR_TARGET=""
for t in "${ZEPHYR_TARGET_LIST[@]}"; do
if [ "${t}" = "${OPTARG}" ]; then
ZEPHYR_TARGET=${t}
break
fi
done
if [ -z "${ZEPHYR_TARGET}" ]; then
echo -e "${RED}Invalid Zephyr target: ${OPTARG}${NC}\n" 1>&2
echo -e "${YELLOW}Valid targets: ${ZEPHYR_TARGET_LIST[*]}${NC}" 1>&2
exit 1
fi
;;
c )
clean
exit 0
;;
h )
usage
exit 0
;;
\? )
echo -e "${RED}Invalid option: ${OPTARG}${NC}\n" 1>&2
usage
exit 1
;;
esac
done
shift $((OPTIND -1))
}
function clean() {
rm -rf "${ROOT_DIR}"/build "${ROOT_DIR}"/install
}
function build_cyclonedds_host() {
echo -e "${GREEN}Building CycloneDDS host tools...${NC}"
mkdir -p build/cyclonedds_host
pushd build/cyclonedds_host
cmake -DCMAKE_INSTALL_PREFIX="$(pwd)"/out -DENABLE_SECURITY=OFF -DENABLE_SSL=OFF -DBUILD_IDLC=ON -DBUILD_SHARED_LIBS=ON -DENABLE_SHM=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF -DBUILD_DDSPERF=OFF "${ROOT_DIR}"/cyclonedds
cmake --build . --target install -- -j"$(nproc)"
popd
}
function build_actuation_module() {
echo -e "${GREEN}Building Zephyr Actuation Module...${NC}"
typeset PATH="${ROOT_DIR}"/build/cyclonedds_host/out/bin:$PATH
typeset LD_LIBRARY_PATH="${ROOT_DIR}"/build/cyclonedds_host/out/lib
typeset CMAKE_PREFIX_PATH=""
typeset AMENT_PREFIX_PATH=""
# Build command with common arguments
local build_args=(
-DZEPHYR_TARGET="${ZEPHYR_TARGET}"
-DCYCLONEDDS_SRC="${ROOT_DIR}"/cyclonedds
-DEXTRA_CFLAGS="-Wno-error"
-DEXTRA_CXXFLAGS="-Wno-error"
-DBUILD_TEST=${BUILD_TEST_FLAG}
)
# Add device tree overlay only for ARM board variant
if [ "${ZEPHYR_TARGET}" = "s32z270dc2_rtu0_r52@D" ]; then
build_args+=(-DEXTRA_DTC_OVERLAY_FILE="${ROOT_DIR}"/actuation_module/boards/s32z270dc2_rtu0_r52@D.overlay)
fi
west build -p auto -d build/actuation_module -b "${ZEPHYR_TARGET}" actuation_module/ -- "${build_args[@]}"
}
## MAIN ##
parse_args "$@"
# Create build directory
cd "${ROOT_DIR}"
mkdir -p build
# Build CycloneDDS host tools
build_cyclonedds_host
# Build Zephyr Actuation Module
build_actuation_module