#!/bin/bash # SPDX-License-Identifier: Apache-2.0 # Copyright (c) 2012-2024 Scott Penrose and WII5 Buoy contributors # # This file is part of WII5 Buoy firmware. # See LICENSE for full terms. # Build a versioned firmware hex and (optionally) commit it into a separate # firmware-archive repo. # # Usage: build_version.sh [VERSION_TAG] # - With VERSION_TAG: checks out that tag, builds, names the hex # wii5_buoy_.hex, also creates wii5_buoy_latest.hex symlink. # - Without: builds the current HEAD as a 'dev' build. # # Configure via env vars: : "${WII5_BUILD_DIR:?set to your Arduino build dir}" : "${WII5_FIRMWARE_REPO:?path to firmware-archive git repo}" : "${WII5_ARDUINO_BIN:=arduino}" set -e VERSION=$1 SHORT=$(git log -1 --pretty=format:%h) VERSION_STRING="WII5Buoy_$VERSION" LINK="" INTVER="" if [[ $VERSION == '' ]] then # TODO: keep versions with SHORT and link "latest" -> latest dev VERSION_STRING="WII5Buoy_dev_$SHORT" VERSION="dev" INTVER="3" else git checkout $VERSION LINK="latest" INTVER=$(perl tools/integer_version.pl $VERSION) fi echo "Getting and Building $VERSION with $VERSION_STRING" "$WII5_ARDUINO_BIN" \ --pref compiler.cpp.extra_flags="-DWII5_SOFTWARE_VERSION=\"$VERSION_STRING\" -DWII5_SOFTWARE_COMMIT=\"$SHORT\" -DWII5_SOFTWARE_INTVER=$INTVER" \ --verify app/wii5_buoy/wii5_buoy.ino \ --board WII:avr:wii5_v2_2560_3V:cpu=atmega25603V3_11MHz230400 sleep 1 pushd "$WII5_FIRMWARE_REPO" git pull cp "$WII5_BUILD_DIR/wii5_buoy.ino.hex" "$WII5_FIRMWARE_REPO/wii5_buoy_$VERSION.hex" if [[ $LINK == '' ]] then echo "No link to DEV" else echo "Creating link to latest" touch wii5_buoy_$LINK.hex rm wii5_buoy_$LINK.hex ln -s wii5_buoy_$VERSION.hex wii5_buoy_$LINK.hex git add wii5_buoy_$LINK.hex fi git add wii5_buoy_$VERSION.hex git commit -am "Auto build $VERSION $VERSION_STRING" git push popd git checkout master