diff --git a/Makefile b/Makefile index 8bbda6c..766f57c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,12 @@ # WireGuard Admin TUI .PHONY: help build clean install test fmt lint run deps +# Project root (where go.mod is located) +ROOTDIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) + # Binary name BINARY=wg-tui -CMD_PATH=./cmd/$(BINARY) +CMD_PATH=$(ROOTDIR)/cmd/$(BINARY) # Build directory BUILD_DIR=build @@ -24,12 +27,12 @@ help: ## Show this help message build: ## Build the binary @echo "Building $(BINARY)..." - @$(GOBUILD) -o $(BINARY) $(CMD_PATH)/main.go + @cd $(ROOTDIR) && $(GOBUILD) -o $(BINARY) $(CMD_PATH)/main.go @echo "Build complete: $(BINARY)" build-all: ## Build all binaries @echo "Building all binaries..." - @$(GOBUILD) -o $(BINARY) ./... + @cd $(ROOTDIR) && $(GOBUILD) -o $(BINARY) ./... clean: ## Clean build artifacts @echo "Cleaning..." @@ -39,25 +42,25 @@ clean: ## Clean build artifacts install: ## Install the binary to $GOPATH/bin @echo "Installing $(BINARY)..." - @$(GOBUILD) -o $$($(GOCMD) env GOPATH)/bin/$(BINARY) $(CMD_PATH)/main.go + @cd $(ROOTDIR) && $(GOBUILD) -o $$($(GOCMD) env GOPATH)/bin/$(BINARY) $(CMD_PATH)/main.go @echo "Install complete" test: ## Run tests @echo "Running tests..." - @$(GOTEST) -v ./... + @cd $(ROOTDIR) && $(GOTEST) -v ./... test-coverage: ## Run tests with coverage @echo "Running tests with coverage..." - @$(GOTEST) -v -coverprofile=coverage.out ./... - @$(GOCMD) tool cover -html=coverage.out -o coverage.html + @cd $(ROOTDIR) && $(GOTEST) -v -coverprofile=coverage.out ./... + @cd $(ROOTDIR) && $(GOCMD) tool cover -html=coverage.out -o coverage.html fmt: ## Format Go code @echo "Formatting code..." - @$(GOCMD) fmt ./... + @cd $(ROOTDIR) && $(GOCMD) fmt ./... lint: ## Run golangci-lint (if installed) @echo "Running linter..." - @if command -v golangci-lint > /dev/null; then \ + @cd $(ROOTDIR) && if command -v golangci-lint > /dev/null; then \ golangci-lint run; \ else \ echo "golangci-lint not found. Install from https://golangci-lint.run/usage/install/"; \ @@ -65,8 +68,8 @@ lint: ## Run golangci-lint (if installed) deps: ## Download dependencies @echo "Downloading dependencies..." - @$(GOMOD) download - @$(GOMOD) tidy + @cd $(ROOTDIR) && $(GOMOD) download + @cd $(ROOTDIR) && $(GOMOD) tidy run: build ## Build and run the binary @echo "Running $(BINARY)..."