.PHONY: all build test vet clean run fmt

APP     := ratatoskr
CMD_DIR := ./cmd/ratatoskr
GO      ?= go
GOPATH  := $(shell $(GO) env GOPATH)
GIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null || echo dev)
UPDATE_TOKEN ?= ""
GOFLAGS ?= -ldflags="-s -w -X main.version=commit-$(GIT_SHA) -X main.updateToken=$(UPDATE_TOKEN)"

all: test build

build:
	$(GO) build $(GOFLAGS) -o $(APP) $(CMD_DIR)

test:
	$(GO) test ./... -v -count=1 -timeout 120s

vet:
	$(GO) vet ./...

fmt:
	$(GO) fmt ./...

run: build
	./$(APP) -config config.yaml

clean:
	rm -f $(APP)
	rm -rf /tmp/ratatoskr-*

.PHONY: bench
bench:
	$(GO) test ./... -bench=. -benchmem -count=1 -timeout 120s

.PHONY: cross
cross:
	GOOS=linux GOARCH=amd64 $(GO) build $(GOFLAGS) -o $(APP)-linux-amd64 $(CMD_DIR)
	GOOS=windows GOARCH=amd64 $(GO) build $(GOFLAGS) -o $(APP)-windows-amd64.exe $(CMD_DIR)