11#! /usr/bin/env bash
2- set -e
2+ set -euo pipefail
33
44if [[ $# == 0 ]]; then
55 echo -e " \
@@ -8,6 +8,10 @@ Usage syntax: ./build.sh <TARGET>
88Notes:
99 * You can specify multiple targets.
1010 ./build.sh <TARGET_1> <TARGET_2> <TARGET_N>
11+ * To get a list of release targets use \" release_targets\"
12+ ./build.sh release_targets
13+ * To get a list of valid targets use \" valid_targets\"
14+ ./build.sh valid_targets
1115 * To get a list of all targets use \" help\" . Hint: pipe the output through a pager.
1216 ./build.sh help | less
1317 * To build all targets use \" all\"
@@ -19,10 +23,20 @@ Notes:
1923 exit 1
2024fi
2125
26+ run_docker () {
27+ docker run --rm -it -v " $( pwd) " :/src inav-build " $@ "
28+ }
29+
2230if [ -z " $( docker images -q inav-build) " ]; then
23- echo -e " *** Building image\n"
24- docker build -t inav-build --build-arg USER_ID=" $( id -u) " --build-arg GROUP_ID=" $( id -g) " .
25- echo -ne " \n"
31+ echo " *** Building Docker image"
32+ docker build -t inav-build \
33+ --build-arg USER_ID=" $( id -u) " \
34+ --build-arg GROUP_ID=" $( id -g) " .
35+ else
36+ docker build -q -t inav-build \
37+ --build-arg USER_ID=" $( id -u) " \
38+ --build-arg GROUP_ID=" $( id -g) " . > /dev/null ||
39+ { echo " *** Building Docker image: ERROR" ; exit 1; }
2640fi
2741
2842if [ ! -d ./build ]; then
@@ -40,10 +54,20 @@ if [ ! -d ./tools ]; then
4054 mkdir ./tools && chmod 777 ./tools
4155fi
4256
43- echo -e " *** Building targets [$@ ]\n"
44- docker run --rm -it -v " $( pwd) " :/src inav-build $@
57+ case " $1 " in
58+ release_targets)
59+ run_docker targets | sed -n ' s/^Release targets: \(.*\)/\1/p' | tr ' ' ' \n'
60+ ;;
61+ valid_targets)
62+ run_docker targets | sed -n ' s/^Valid targets: \(.*\)/\1/p' | tr ' ' ' \n'
63+ ;;
64+ * )
65+ echo -e " *** Building targets [$@ ]\n"
66+ run_docker " $@ "
67+ if ls ./build/* .hex & > /dev/null; then
68+ echo -e " \n*** Built targets in ./build:"
69+ stat -c " %n (%.19y)" ./build/* .hex
70+ fi
71+ ;;
72+ esac
4573
46- if [ -z " $( ls ./build/* .hex & > /dev/null) " ]; then
47- echo -e " \n*** Built targets in ./build:"
48- stat -c " %n (%.19y)" ./build/* .hex
49- fi
0 commit comments