forked from uos3/obc-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·237 lines (210 loc) · 5.35 KB
/
Copy pathbuild
File metadata and controls
executable file
·237 lines (210 loc) · 5.35 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
## Cross-Platform Embedded Toolchain
## Copyright (c) 2016 Phil Crump <phil@philcrump.co.uk>
## Freely distributable under the MIT license.
## hacked by Suzanna Lucarotti 2017 to assume uos3-proto folder if not specified (my code ain't gonna work with any other as it stands)
source_dir="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
cd $source_dir
opt_flash=false
opt_power=false
opt_debug=false
opt_quiet=false
opt_sound=false
opt_asm=false
opt_werror=false
opt_verbose=false
opt_osize=false
COLOUR_GREEN='\033[0;32m'
COLOUR_YELLOW='\033[1;33m'
COLOUR_PURPLE='\033[0;35m'
COLOUR_RED='\033[0;31m'
COLOUR_OFF='\033[0;00m'
CLEAR_LINE='\033[2K'
_ERROR_="$COLOUR_RED[ERROR]$COLOUR_OFF"
_INFO_="$COLOUR_PURPLE[INFO]$COLOUR_OFF"
_DEBUG_="$COLOUR_YELLOW[DEBUG]$COLOUR_OFF"
stdin="/proc/$$/fd/0"
stdout="/proc/$$/fd/1"
stderr="/proc/$$/fd/2"
stdnull="/dev/null"
usage() {
echo "Usage: build <board> <program> or build <program> to assume uos3-proto" >&2
}
print() {
if ! $opt_quiet
then
echo -e $@ >&$stdout
fi
}
print_err() {
if ! $opt_quiet
then
echo -e $@ >&$stderr
fi
}
hyphenjoin() {
str=""
while [ $# -gt 0 ]
do
str="$str$1-"
shift
done
if [ ! -z "$str" ]
then
str="${str::-1}"
fi
echo "$str"
}
flash() {
if $opt_flash; then
flash_args="";
if $opt_sound; then flash_args="$flash_args -S"; fi
if $opt_power; then flash_args="$flash_args -P"; fi
if $opt_verbose; then flash_args="$flash_args -v"; fi
${source_dir}/flash ${flash_args} ${outdir}/${filename};
fi
}
debug() {
if $opt_debug; then
debug_args="";
if $opt_verbose; then debug_args="$debug_args -v"; fi
${source_dir}/debug ${debug_args} ${outdir}/${filename};
fi
}
asmdump() {
if $opt_asm; then
arm-none-eabi-objdump -DSlx ${source_dir}/${outdir}/${filename} > ${source_dir}/${outdir}/${filename}.asm
print "$_INFO_$COLOUR_GREEN Machine code: ${outdir}/${filename}.asm$COLOUR_OFF"
fi
}
print_help() {
echo ""
echo " Usage: ./build [options] <board> <application> (board is assumed to be uos3-proto if omitted)"
echo ""
echo " Options:"
echo ""
echo " -h Display this help and exit."
echo " -q Hide all messages apart from errors."
echo " -v Compile (& Flash) verbosely."
echo " -m Also generate machine code output."
echo " -w Tell compiler to treat warnings as errors."
echo " -s Tell compiler to optimise for code size."
echo " -F Attempt to flash board if compile is successful."
echo " -S Play sound if flash is successful. [requires -F]"
echo " -P Enable power from programmer in Flash. [requires -F]"
echo ""
}
## Read Flags
OPTIND=1
while getopts ":hmdsqvFDSPw" opt; do
case "$opt" in
h) # Help
print_help
exit 0
;;
m) # ASM
opt_asm=true
;;
s) # Optimise for Size
opt_osize=true
;;
q) # Quiet
opt_quiet=true
;;
v) # Verbose
opt_verbose=true
;;
F) # Flash
opt_flash=true
;;
D) # Debug
opt_debug=true
;;
S) # Sound
opt_sound=true
;;
P) # Power
opt_power=true
;;
w) # Warnings as Errors
opt_werror=true
;;
?) # Illegal Option
print_err "$_ERROR_ Illegal option '$OPTARG'"
print_help
exit 3
;;
esac
done
for i in `seq 2 $OPTIND`; do shift; done
## Read Arguments
board=${1,,}
shift
program=${1,,}
shift
## Check <program> argument
if [ -z "$program" ]; then
program=$board
board="uos3-proto" ## insert default option here
fi
if [ ! -e "src/main/$program.c" ]; then
print_err "$_ERROR_ Main Program file \"$program\" not found"
print "$_INFO_ Available Main Program files are:"
for f in src/main/*.c
do
echo " $(basename $f)"
done
exit 1
fi
## Check <board> argument
if [ -z "$board" ]; then
print_err "$_ERROR_ A board must be specified"
usage
exit 1
fi
if [ ! -d "src/board/${board}" ]; then
print_err "$_ERROR_ Board \"${board}\" not found"
exit 1
fi
## Run <board>'s dependencies script if it exists
if [ -f "src/board/${board}/dependencies.sh" ]; then
src/board/${board}/dependencies.sh;
if [[ $? != 0 ]]; then
exit 1
fi
fi
## Set up Makefile Flags
githash="$(git describe --dirty --always)"
# Mark as dirty if untracked files exist
if [ -z "$(echo "$githash" | grep "dirty")" ] && [ ! -z "$(git status --porcelain | grep "^??")" ]; then
githash="$githash-dirty"
fi
outdir="builds"
filename="$(hyphenjoin $board $program $flags $githash)"
flags="BOARD=${board} MAIN=${program} OUTDIR=${outdir} OUTFILE=\"${filename}\""
if $opt_osize; then
print "$_INFO_ Compiler optimise for size (-Os):$COLOUR_RED ON $COLOUR_OFF"
flags="${flags} OSIZE_ON=true"
fi
if $opt_werror; then
print "$_INFO_ Compiler set Warnings as Errors:$COLOUR_RED ON $COLOUR_OFF"
flags="${flags} WERROR_ON=true"
fi
if $opt_verbose; then
print "$_INFO_ Compiler Verbose:$COLOUR_RED ON $COLOUR_OFF"
flags="${flags} VERBOSE_ON=true"
fi
## Change to board directory, make clean, make, then print summary message.
cd "src/board/$board"
make ${flags} clean \
&& make ${flags} \
&& {
print "$_INFO_$COLOUR_GREEN Built: ${outdir}/${filename}$COLOUR_OFF" \
&& asmdump \
&& flash \
&& debug \
&& exit 0
} || {
print "$_ERROR_$COLOUR_RED There were errors in the build process$COLOUR_OFF" \
&& exit 1
}