BINARY  := v4d
GOFLAGS := -trimpath
LDFLAGS := -s -w -X main.version=$(shell git describe --tags --always --dirty 2>/dev/null || echo dev)

.PHONY: build test lint clean install

build:
	go build $(GOFLAGS) -ldflags '$(LDFLAGS)' -o bin/$(BINARY) ./cmd/v4d

test:
	go test ./... -v -count=1

test-cover:
	go test ./... -coverprofile=coverage.out
	go tool cover -html=coverage.out -o coverage.html

lint:
	golangci-lint run ./...

clean:
	rm -rf bin/ coverage.out coverage.html

install: build
	sudo install -m 0755 bin/$(BINARY) /usr/local/bin/$(BINARY)
	sudo mkdir -p /etc/v4d /var/lib/v4d /var/log/v4d
	@echo "Installed $(BINARY) to /usr/local/bin/$(BINARY)"

deps:
	go mod tidy
