|
| 1 | +default: |
| 2 | + @just --list --unsorted |
| 3 | + |
| 4 | +config := absolute_path('config') |
| 5 | +build := absolute_path('.build') |
| 6 | +out := absolute_path('firmware') |
| 7 | + |
| 8 | +# parse combos.dtsi and adjust settings to not run out of slots |
| 9 | +_parse_combos: |
| 10 | + #!/usr/bin/env bash |
| 11 | + set -euo pipefail |
| 12 | + cconf="{{ config / 'combos.dtsi' }}" |
| 13 | + if [[ -f $cconf ]]; then |
| 14 | + # set MAX_COMBOS_PER_KEY to the most frequent combos count |
| 15 | + count=$( |
| 16 | + tail -n +10 $cconf | |
| 17 | + grep -Eo '[LR][TMBH][0-9]' | |
| 18 | + sort | uniq -c | sort -nr | |
| 19 | + awk 'NR==1{print $1}' |
| 20 | + ) |
| 21 | + sed -Ei "/CONFIG_ZMK_COMBO_MAX_COMBOS_PER_KEY/s/=.+/=$count/" "{{ config }}"/*.conf |
| 22 | + echo "Setting MAX_COMBOS_PER_KEY to $count" |
| 23 | + |
| 24 | + # set MAX_KEYS_PER_COMBO to the most frequent key count |
| 25 | + count=$( |
| 26 | + tail -n +10 $cconf | |
| 27 | + grep -o -n '[LR][TMBH][0-9]' | |
| 28 | + cut -d : -f 1 | uniq -c | sort -nr | |
| 29 | + awk 'NR==1{print $1}' |
| 30 | + ) |
| 31 | + sed -Ei "/CONFIG_ZMK_COMBO_MAX_KEYS_PER_COMBO/s/=.+/=$count/" "{{ config }}"/*.conf |
| 32 | + echo "Setting MAX_KEYS_PER_COMBO to $count" |
| 33 | + fi |
| 34 | + |
| 35 | +# parse build.yaml and filter targets by expression |
| 36 | +_parse_targets $expr: |
| 37 | + #!/usr/bin/env bash |
| 38 | + attrs="[.board, .shield]" |
| 39 | + filter=".include[] | [.board, .shield] | join(\",\")" |
| 40 | + echo "$(yq -r "$filter" build.yaml | grep -i "${expr/#all/.*}")" |
| 41 | + |
| 42 | +# build firmware for single board & shield combination |
| 43 | +_build_single $board $shield *west_args: |
| 44 | + #!/usr/bin/env bash |
| 45 | + set -euo pipefail |
| 46 | + artifact="${shield:+$shield-}${board}" |
| 47 | + build_dir="{{ build / '$artifact' }}" |
| 48 | + |
| 49 | + echo "Building firmware for $artifact..." |
| 50 | + west build -s zmk/app -d "$build_dir" -b $board {{ west_args }} -- \ |
| 51 | + ${shield:+-DSHIELD="$shield"} \ |
| 52 | + -DZMK_CONFIG="{{ config }}" \ |
| 53 | + |
| 54 | + if [[ -f "$build_dir/zephyr/zmk.uf2" ]]; then |
| 55 | + mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.uf2" "{{ out }}/$artifact.uf2" |
| 56 | + else |
| 57 | + mkdir -p "{{ out }}" && cp "$build_dir/zephyr/zmk.bin" "{{ out }}/$artifact.bin" |
| 58 | + fi |
| 59 | + |
| 60 | +# build firmware for matching targets |
| 61 | +build expr *west_args: _parse_combos |
| 62 | + #!/usr/bin/env bash |
| 63 | + set -euo pipefail |
| 64 | + targets=$(just _parse_targets {{ expr }}) |
| 65 | + |
| 66 | + [[ -z $targets ]] && echo "No matching targets found. Aborting..." >&2 && exit 1 |
| 67 | + echo "$targets" | while IFS=, read -r board shield; do |
| 68 | + just _build_single "$board" "$shield" {{ west_args }} |
| 69 | + done |
| 70 | + |
| 71 | +# clear build cache and artifacts |
| 72 | +clean: |
| 73 | + rm -rf {{ build }} {{ out }} |
| 74 | + |
| 75 | +# initialize west |
| 76 | +init: |
| 77 | + west init -l config |
| 78 | + west update |
| 79 | + west zephyr-export |
| 80 | + |
| 81 | +# update west |
| 82 | +update: |
| 83 | + west update |
| 84 | + |
| 85 | +# list build targets |
| 86 | +list: |
| 87 | + @just _parse_targets all | sed 's/,$//' | sort | column |
0 commit comments