BIN=gcrab
# Version comes from the git tag when available, so the binary can't drift from
# the release tag (a hand-edited constant once shipped as 0.1.0 under the v0.1.1
# and v0.1.2 tags). Falls back to the compiled-in default outside a git checkout.
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null)
LDFLAGS=-s -w $(if $(VERSION),-X main.version=$(VERSION))

.PHONY: build test vet release clean

build:
	CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BIN) ./cmd/gcrab

test:
	go vet ./... && go test ./...

release:
	mkdir -p dist
	CGO_ENABLED=0 GOOS=linux  GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o dist/gcrab-linux-amd64 ./cmd/gcrab
	CGO_ENABLED=0 GOOS=linux  GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o dist/gcrab-linux-arm64 ./cmd/gcrab
	CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o dist/gcrab-darwin-arm64 ./cmd/gcrab
	CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o dist/gcrab-windows-amd64.exe ./cmd/gcrab

clean:
	rm -rf $(BIN) dist
