#!/usr/bin/env bash # Builds (or flashes/monitors, if a serial port is actually attached) # the espresso_frame firmware for one board variant, via the project's # own firmware/build_for_board.sh -- this script just sources the # ESP-IDF environment first and auto-runs `set-target esp32c6` on a # board's very first build (a fresh clone has no generated sdkconfig # yet, same reasoning as CI's own build steps -- see firmware/README.md's # "Building for the Seeed XIAO ESP32-C6" section). # # Usage: # build.sh # build devkit (default) # build.sh devkit # build.sh xiao # build.sh both # build both board variants # build.sh xiao flash -p /dev/ttyUSB0 # only meaningful with real hardware attached set -euo pipefail script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" firmware_dir="$(git -C "$script_dir" rev-parse --show-toplevel)/firmware" IDF_DIR="$HOME/.espressif-idf/esp-idf" if [ ! -f "$IDF_DIR/export.sh" ]; then echo "ESP-IDF not found at $IDF_DIR -- run setup.sh first" >&2 exit 1 fi # export.sh is chatty and assumes an interactive shell prompt in spots; # redirect its own stdout, not ours, so build.sh's actual output (and a # real failure's stderr) stays visible. source "$IDF_DIR/export.sh" > /dev/null cd "$firmware_dir" build_one() { local board="$1" shift local sdkconfig case "$board" in devkit) sdkconfig="sdkconfig" ;; xiao) sdkconfig="sdkconfig.xiao_local" ;; *) echo "Unknown board '$board' -- expected 'devkit' or 'xiao'" >&2; exit 1 ;; esac if [ ! -f "$sdkconfig" ]; then echo "==> $board: no generated sdkconfig yet, setting target esp32c6" ./build_for_board.sh "$board" set-target esp32c6 fi local args=("$@") if [ ${#args[@]} -eq 0 ]; then args=(build) fi ./build_for_board.sh "$board" "${args[@]}" } board="${1:-devkit}" shift || true if [ "$board" = "both" ]; then build_one devkit "$@" build_one xiao "$@" else build_one "$board" "$@" fi