VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
LDFLAGS := -s -w -X main.version=$(VERSION)
TARGETS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64

.PHONY: build test dist release clean

build:
	go build -ldflags '$(LDFLAGS)' -o arr-tui ./cmd/arr-tui

test:
	go vet ./...
	go test ./...
	@if command -v shellcheck >/dev/null; then shellcheck scripts/*.sh dev/*.sh; else echo "shellcheck not installed, skipping shell script checks"; fi

# Cross-compiled binaries and checksums in dist/.
dist:
	rm -rf dist && mkdir dist
	@for t in $(TARGETS); do \
		os=$${t%/*}; arch=$${t#*/}; ext=; [ $$os = windows ] && ext=.exe; \
		echo "building $$os/$$arch"; \
		CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch go build -trimpath -ldflags '$(LDFLAGS)' \
			-o dist/arr-tui-$$os-$$arch$$ext ./cmd/arr-tui || exit 1; \
	done
	cd dist && sha256sum arr-tui-* > SHA256SUMS

# Publish the release for the tag at HEAD on Gitea (see scripts/release.sh).
release:
	scripts/release.sh

clean:
	rm -rf dist arr-tui
