justfile (1557B)
1 # Standard recipes: build (debug), release, clean, test, install. 2 3 bin := "nativeaudio" 4 5 # `just` alone lists the recipes. 6 default: 7 @just --list --unsorted 8 9 # Debug build: symbols kept, for delve and stack traces. 10 build: 11 go build -o {{bin}} ./cmd/nativeaudio 12 13 # Optimised build: stripped, reproducible paths. 14 release: 15 go build -trimpath -ldflags='-s -w' -o {{bin}} ./cmd/nativeaudio 16 17 # Vet and run the tests. 18 test: 19 go vet ./... 20 go test ./... 21 22 # Remove build output and the Go build cache for this module. 23 clean: 24 rm -f {{bin}} 25 go clean 26 27 # Copy the release binary to a directory on PATH. An installed copy is replaced in 28 # place; otherwise ~/.local/bin, ~/bin, GOBIN, GOPATH/bin, /usr/local/bin, else the 29 # first writable PATH entry. 30 install: release 31 #!/usr/bin/env bash 32 set -euo pipefail 33 dest="" 34 if existing=$(command -v {{bin}} 2>/dev/null) && [[ -w ${existing%/*} ]]; then 35 dest=${existing%/*} 36 fi 37 gopath=$(go env GOPATH 2>/dev/null || true); gobin=$(go env GOBIN 2>/dev/null || true) 38 for d in "$HOME/.local/bin" "$HOME/bin" "$gobin" "${gopath:+$gopath/bin}" /usr/local/bin; do 39 [[ -z $dest && -n $d && -d $d && -w $d && ":$PATH:" == *":$d:"* ]] && dest=$d 40 done 41 if [[ -z $dest ]]; then 42 IFS=: read -ra dirs <<<"$PATH" 43 for d in "${dirs[@]}"; do [[ -d $d && -w $d ]] && { dest=$d; break; }; done 44 fi 45 [[ -n $dest ]] || { echo "install: no writable directory on PATH" >&2; exit 1; } 46 install -m 755 {{bin}} "$dest/{{bin}}" 47 echo "installed $dest/{{bin}}"