
# Project metadata
APP_NAME := hspguard
CMD_DIR := ./cmd/$(APP_NAME)
BIN_DIR := ./bin
BIN_PATH := $(BIN_DIR)/$(APP_NAME)
PKG := ./...
GO_FILES := $(shell find . -type f -name '*.go' -not -path "./vendor/*")

# Go tools
GO := go
GOLINT := golangci-lint
GOFMT := gofmt
GOTEST := go test

# Build flags
LD_FLAGS := -s -w
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")

.PHONY: all build clean fmt lint run

all: build

build:
	@mkdir -p $(BIN_DIR)
	$(GO) build -ldflags "-X main.buildTime=$(BUILD_TIME) -X main.commitHash=$(GIT_COMMIT) $(LD_FLAGS)" -o $(BIN_PATH) $(CMD_DIR)

run:
	$(GO) run $(CMD_DIR)

fmt:
	$(GOFMT) -s -w $(GO_FILES)

lint:
	$(GOLINT) run

test:
	$(GOTEST) -v $(PKG)

clean:
	@rm -rf $(BIN_DIR)

mod:
	$(GO) mod tidy

