forked from 3drobotics/ardupilot-solo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_binaries.sh
executable file
·304 lines (278 loc) · 7.9 KB
/
build_binaries.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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/bin/bash
# script to build the latest binaries for each vehicle type, ready to upload
# Andrew Tridgell, March 2013
export PATH=$PATH:/bin:/usr/bin
export TMPDIR=$PWD/build.tmp.$$
echo $TMDIR
rm -rf $TMPDIR
echo "Building in $TMPDIR"
date
git checkout -f master
githash=$(git rev-parse HEAD)
hdate=$(date +"%Y-%m/%Y-%m-%d-%H:%m")
mkdir -p binaries/$hdate
binaries=$PWD/../buildlogs/binaries
error_count=0
. config.mk
# checkout the right version of the tree
checkout() {
vehicle="$1"
tag="$2"
board="$3"
git stash
if [ "$tag" = "latest" ]; then
vtag="master"
vtag2="master"
else
vtag="$vehicle-$tag-$board"
vtag2="$vehicle-$tag"
fi
echo "FORCING NON-BOARD SPECIFIC BUILD"
vtag=$vtag2
echo "Checkout for $vehicle for $board with tag $tag"
git checkout -f "$vtag" || git checkout -f "$vtag2" || return 1
git log -1
pushd ../../PX4NuttX
git checkout -f "$vtag" || git checkout -f "$vtag2" || git checkout -f master || {
popd
return 1
}
git log -1
popd
pushd ../../PX4Firmware
git checkout -f "$vtag" || git checkout -f "$vtag2" || git checkout -f master || {
popd
return 1
}
git log -1
popd
return 0
}
# check if we should skip this build because we have already
# built this version
skip_build() {
[ "$FORCE_BUILD" = "1" ] && return 1
tag="$1"
ddir="$2"
bname=$(basename $ddir)
ldir=$(dirname $(dirname $(dirname $ddir)))/$tag/$bname
[ -d "$ldir" ] || {
echo "$ldir doesn't exist - building"
return 1
}
oldversion=$(cat "$ldir/git-version.txt" | head -1)
newversion=$(git log -1 | head -1)
[ "$oldversion" = "$newversion" ] && {
echo "Skipping build - version match $newversion"
return 0
}
echo "$ldir needs rebuild"
return 1
}
addfwversion() {
destdir="$1"
git log -1 > "$destdir/git-version.txt"
[ -f APM_Config.h ] && {
version=$(grep 'define.THISFIRMWARE' *.pde 2> /dev/null | cut -d'"' -f2)
echo >> "$destdir/git-version.txt"
echo "APMVERSION: $version" >> "$destdir/git-version.txt"
}
}
# copy the built firmware to the right directory
copyit() {
file="$1"
dir="$2"
tag="$3"
bname=$(basename $dir)
tdir=$(dirname $(dirname $(dirname $dir)))/$tag/$bname
if [ "$tag" = "latest" ]; then
mkdir -p "$dir"
/bin/cp "$file" "$dir"
addfwversion "$dir"
fi
echo "Copying $file to $tdir"
mkdir -p "$tdir"
addfwversion "$tdir"
rsync "$file" "$tdir"
}
# build plane binaries
build_arduplane() {
tag="$1"
echo "Building ArduPlane $tag binaries from $(pwd)"
pushd ArduPlane
for b in apm1 apm2; do
checkout ArduPlane $tag $b || {
echo "Failed checkout of ArduPlane $b $tag"
error_count=$((error_count+1))
continue
}
echo "Building ArduPlane $b binaries"
ddir=$binaries/Plane/$hdate/$b
skip_build $tag $ddir && continue
make clean || continue
make $b -j4 || {
echo "Failed build of ArduPlane $b $tag"
error_count=$((error_count+1))
continue
}
copyit $TMPDIR/ArduPlane.build/ArduPlane.hex $ddir $tag
touch $binaries/Plane/$tag
done
test -n "$PX4_ROOT" && {
echo "Building ArduPlane PX4 binaries"
ddir=$binaries/Plane/$hdate/PX4
checkout ArduPlane $tag PX4 || {
echo "Failed checkout of ArduPlane PX4 $tag"
error_count=$((error_count+1))
checkout ArduPlane "latest" ""
popd
return
}
skip_build $tag $ddir || {
make px4 || {
echo "Failed build of ArduPlane PX4 $tag"
error_count=$((error_count+1))
checkout ArduPlane "latest" ""
popd
return
}
copyit ArduPlane-v1.px4 $ddir $tag &&
copyit ArduPlane-v2.px4 $ddir $tag
if [ "$tag" = "latest" ]; then
copyit px4io-v1.bin $binaries/PX4IO/$hdate/PX4IO $tag
copyit px4io-v1.elf $binaries/PX4IO/$hdate/PX4IO $tag
copyit px4io-v2.bin $binaries/PX4IO/$hdate/PX4IO $tag
copyit px4io-v2.elf $binaries/PX4IO/$hdate/PX4IO $tag
fi
}
}
checkout ArduPlane "latest" ""
popd
}
# build copter binaries
build_arducopter() {
tag="$1"
echo "Building ArduCopter $tag binaries from $(pwd)"
pushd ArduCopter
frames="quad tri hexa y6 octa octa-quad heli"
test -n "$PX4_ROOT" && {
checkout ArduCopter $tag PX4 || {
echo "Failed checkout of ArduCopter PX4 $tag"
error_count=$((error_count+1))
checkout ArduCopter "latest" ""
popd
return
}
rm -rf ../Build.ArduCopter
for f in $frames; do
echo "Building ArduCopter PX4-$f binaries"
ddir="$binaries/Copter/$hdate/PX4-$f"
skip_build $tag $ddir && continue
make px4-$f || {
echo "Failed build of ArduCopter PX4 $tag"
error_count=$((error_count+1))
continue
}
copyit ArduCopter-v1.px4 $ddir $tag &&
copyit ArduCopter-v2.px4 $ddir $tag
done
}
checkout ArduCopter "latest" ""
popd
}
# build rover binaries
build_rover() {
tag="$1"
echo "Building APMrover2 $tag binaries from $(pwd)"
pushd APMrover2
for b in apm1 apm2; do
echo "Building APMrover2 $b binaries"
checkout APMrover2 $tag $b || continue
ddir=$binaries/Rover/$hdate/$b
skip_build $tag $ddir && continue
make clean || continue
make $b -j4 || {
echo "Failed build of APMrover2 $b $tag"
error_count=$((error_count+1))
continue
}
copyit $TMPDIR/APMrover2.build/APMrover2.hex $ddir $tag
touch $binaries/Rover/$tag
done
test -n "$PX4_ROOT" && {
echo "Building APMrover2 PX4 binaries"
ddir=$binaries/Rover/$hdate/PX4
checkout APMrover2 $tag PX4 || {
checkout APMrover2 "latest" ""
popd
return
}
skip_build $tag $ddir || {
make px4 || {
echo "Failed build of APMrover2 PX4 $tag"
error_count=$((error_count+1))
checkout APMrover2 "latest" ""
popd
return
}
copyit APMrover2-v1.px4 $binaries/Rover/$hdate/PX4 $tag &&
copyit APMrover2-v2.px4 $binaries/Rover/$hdate/PX4 $tag
}
}
checkout APMrover2 "latest" ""
popd
}
# build antenna tracker binaries
build_antennatracker() {
tag="$1"
echo "Building AntennaTracker $tag binaries from $(pwd)"
pushd AntennaTracker
for b in apm2; do
echo "Building AntennaTracker $b binaries"
checkout AntennaTracker $tag $b || continue
ddir=$binaries/AntennaTracker/$hdate/$b
skip_build $tag $ddir && continue
make clean || continue
make $b -j4 || {
echo "Failed build of AntennaTracker $b $tag"
error_count=$((error_count+1))
continue
}
copyit $TMPDIR/AntennaTracker.build/AntennaTracker.hex $ddir $tag
touch $binaries/AntennaTracker/$tag
done
test -n "$PX4_ROOT" && {
echo "Building AntennaTracker PX4 binaries"
ddir=$binaries/AntennaTracker/$hdate/PX4
checkout AntennaTracker $tag PX4 || {
checkout AntennaTracker "latest" ""
popd
return
}
skip_build $tag $ddir || {
make px4 || {
echo "Failed build of AntennaTracker PX4 $tag"
error_count=$((error_count+1))
checkout AntennaTracker "latest" ""
popd
return
}
copyit AntennaTracker-v1.px4 $binaries/AntennaTracker/$hdate/PX4 $tag &&
copyit AntennaTracker-v2.px4 $binaries/AntennaTracker/$hdate/PX4 $tag
}
}
checkout AntennaTracker "latest" ""
popd
}
# make sure PX4 is rebuilt from scratch
pushd ArduPlane
make px4-clean || exit 1
popd
for build in stable beta latest; do
build_arduplane $build
build_arducopter $build
build_rover $build
build_antennatracker $build
done
rm -rf $TMPDIR
exit $error_count