-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·103 lines (84 loc) · 2.4 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
#!/usr/bin/env bash
# Usage:
# build.sh --board nice_nano_v2 --left leeloo_left --right leeloo_right
#
set -eou pipefail
# TODO:
# - https://github.com/zmkfirmware/zmk/blob/main/.github/workflows/build-user-config.yml
# https://hub.docker.com/r/zmkfirmware/zmk-build-arm
ZMK_IMAGE="zmkfirmware/zmk-build-arm:stable"
main() {
local board='' shield_left='' shield_right='' script='' GID
GID="$(id -g)"
while true; do
case "${1:-}" in
--board)
board="$2"
shift 2
;;
--left)
shield_left="$2"
shift 2
;;
--right)
shield_right="$2"
shift 2
;;
*) break ;;
esac
done
if [[ -z "${board}${shield_left}${shield_right}" ]]; then
echo 'Specify --board <board> --left <shield> --right <shield>'
return 1
fi
rm -rf build/*.out
script="
cd /keeb
if [ ! -d .west ]; then
west init -l config
fi
if [ ! -d zmk ]; then
west update
fi
west zephyr-export
echo 'Building left'
west build --pristine -b $board zmk/app -- \
-DSHIELD=$shield_left \
-DZMK_CONFIG=/keeb/config
cp /keeb/build/zephyr/zmk.uf2 /build/${shield_left}-${board}-zmk.uf2.out
chown $UID:$GID /build/${shield_left}-${board}-zmk.uf2.out
chown $UID:$GID /build
"
if [[ -n "$shield_right" ]]; then
script="$script
echo 'Building right'
west build --pristine -b $board zmk/app -- \
-DSHIELD=$shield_right \
-DZMK_CONFIG=/keeb/config
cp /keeb/build/zephyr/zmk.uf2 /build/${shield_right}-${board}-zmk.uf2.out
chown $UID:$GID /build/${shield_right}-${board}-zmk.uf2.out
"
fi
docker run -it --rm \
-v "$(pwd)/.cache:/keeb" \
-v "$(pwd)/config:/keeb/config:ro" \
-v "$(pwd)/build:/build" \
"$ZMK_IMAGE" sh -c "$script"
if [[ ! -e "build/${shield_left}-${board}-zmk.uf2.out" ]]; then
echo ''
echo '-- Errors in building'
exit 1
fi
echo ''
echo '-- Done'
rm -f build/${shield_left}-${board}-zmk.uf2
mv build/${shield_left}-${board}-zmk.uf2{.out,}
ls -la build/${shield_left}-${board}-zmk.uf2
if [[ -f "build/${shield_right}_${board}.uf2.out" ]]; then
rm -f build/${shield_right}-${board}-zmk.uf2
mv build/${shield_right}-${board}-zmk.uf2{.out,}
ls -la build/${shield_right}-${board}-zmk.uf2
fi
}
main "$@"
# Thanks to https://git.lyte.dev/lytedev/keyboards/src/branch/master/zorne/build.fish