#!/usr/bin/env bash set -eo pipefail readonly SCRIPT="${BASH_SOURCE[0]}" fail() { printf "ERR - %s: %s\n" "$SCRIPT" "$1" >&2 exit 1 } DIR="${1:-$(pwd)}" if [[ ! -d "$DIR" ]]; then printf "Usage: %s \n" "$SCRIPT" exit 1 fi ( cd "$DIR" || fail "Couldn't enter directory: $DIR" if [[ -x "./run.sh" ]]; then ./run.sh || fail "run.sh failed" elif [[ -f "Cargo.toml" ]]; then cargo run || fail "Cargo execution failed" elif [[ -f "Makefile" ]]; then EXEC=$(awk -F '=' '/^TARGET[[:space:]]*=/ {print $2}' Makefile | xargs) if [[ -z "$EXEC" ]]; then fail "Makefile found, but no 'TARGET' variable defined." fi make && ./"$EXEC" || fail "Make build or execution failed" else fail "No recognized entry point (run.sh, Cargo.toml, or Makefile) found." fi )