-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·142 lines (123 loc) · 2.79 KB
/
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
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
#!/bin/sh
set -eu
BUILD_DIR="build"
REQUIRED_COMMANDS="
[
command
echo
exit
getopts
printf
test
meson
ninja
"
e_err() {
echo >&2 "ERROR: ${*}"
}
e_warn() {
echo "WARN: ${*}"
}
usage() {
echo "Usage: ${0} [OPTIONS]"
echo
echo "Helper script to build the Safety Controller software"
echo
echo " -h Print this help text and exit"
echo
echo "Optional arguments:"
echo " -b <board> Board to compile the software to, can be given"
echo " multiple times to compile for multiple boards"
echo " -c Clean before building"
echo " -t <buildtype> Build type: {plain, debug, debugoptimized, release, minsize, custom}"
echo " See http://mesonbuild.com/"
echo
echo "If you don't pass any argument, then all boards are built using the 'debugoptimized' build type"
}
check_requirements() {
for _cmd in ${REQUIRED_COMMANDS}; do
if ! _test_result="$(command -V "${_cmd}")"; then
_test_result_fail="${_test_result_fail:-}${_test_result}\n"
else
_test_result_pass="${_test_result_pass:-}${_test_result}\n"
fi
done
if [ -n "${_test_result_fail:-}" ]; then
e_err "Self-test failed, missing dependencies."
echo "======================================="
echo "Passed tests:"
# shellcheck disable=SC2059 # Interpret \n from variable
printf "${_test_result_pass:-none\n}"
echo "---------------------------------------"
echo "Failed tests:"
# shellcheck disable=SC2059 # Interpret \n from variable
printf "${_test_result_fail:-none\n}"
echo "======================================="
exit 1
fi
}
clean()
{
boards="${1}"
if [ "${boards}" = "all" ]; then
rm -rf "${BUILD_DIR:?}"
else
for board in ${boards}; do
rm -rf "${BUILD_DIR}/${board}"
done
fi
}
build()
{
boards="${1}"
buildtype="${2}"
if [ "${boards}" = "all" ]; then
boards="$(find "boards" \
-maxdepth 1 \
-type d \
\( ! -iname "boards" \) \
-exec basename {} \;)"
fi
for board in ${boards}; do
if [ -f "boards/${board}/meson.ini" ]; then
meson --cross-file="boards/${board}/meson.ini" \
--buildtype="${buildtype}" \
"${BUILD_DIR}/${board}"
ninja -C "${BUILD_DIR}/${board}"
fi
done
}
main()
{
check_requirements
while getopts ":b:cht:" options; do
case "${options}" in
b)
chosen_boards="${chosen_boards:-} ${OPTARG}"
;;
c)
clean="true"
;;
h)
usage
exit 0
;;
t)
buildtype="${OPTARG}"
;;
:)
e_err "Option -${OPTARG} requires an argument."
exit 1
;;
?)
e_err "Invalid option: -${OPTARG}"
exit 1
;;
esac
done
if [ -n "${clean:-}" ]; then
clean "${chosen_boards:-all}"
fi
build "${chosen_boards:-all}" "${buildtype:-debugoptimized}"
}
main "${@}"