Fix Makefile: run go commands from project root
This commit is contained in:
25
Makefile
25
Makefile
@@ -1,9 +1,12 @@
|
|||||||
# WireGuard Admin TUI
|
# WireGuard Admin TUI
|
||||||
.PHONY: help build clean install test fmt lint run deps
|
.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 name
|
||||||
BINARY=wg-tui
|
BINARY=wg-tui
|
||||||
CMD_PATH=./cmd/$(BINARY)
|
CMD_PATH=$(ROOTDIR)/cmd/$(BINARY)
|
||||||
|
|
||||||
# Build directory
|
# Build directory
|
||||||
BUILD_DIR=build
|
BUILD_DIR=build
|
||||||
@@ -24,12 +27,12 @@ help: ## Show this help message
|
|||||||
|
|
||||||
build: ## Build the binary
|
build: ## Build the binary
|
||||||
@echo "Building $(BINARY)..."
|
@echo "Building $(BINARY)..."
|
||||||
@$(GOBUILD) -o $(BINARY) $(CMD_PATH)/main.go
|
@cd $(ROOTDIR) && $(GOBUILD) -o $(BINARY) $(CMD_PATH)/main.go
|
||||||
@echo "Build complete: $(BINARY)"
|
@echo "Build complete: $(BINARY)"
|
||||||
|
|
||||||
build-all: ## Build all binaries
|
build-all: ## Build all binaries
|
||||||
@echo "Building all binaries..."
|
@echo "Building all binaries..."
|
||||||
@$(GOBUILD) -o $(BINARY) ./...
|
@cd $(ROOTDIR) && $(GOBUILD) -o $(BINARY) ./...
|
||||||
|
|
||||||
clean: ## Clean build artifacts
|
clean: ## Clean build artifacts
|
||||||
@echo "Cleaning..."
|
@echo "Cleaning..."
|
||||||
@@ -39,25 +42,25 @@ clean: ## Clean build artifacts
|
|||||||
|
|
||||||
install: ## Install the binary to $GOPATH/bin
|
install: ## Install the binary to $GOPATH/bin
|
||||||
@echo "Installing $(BINARY)..."
|
@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"
|
@echo "Install complete"
|
||||||
|
|
||||||
test: ## Run tests
|
test: ## Run tests
|
||||||
@echo "Running tests..."
|
@echo "Running tests..."
|
||||||
@$(GOTEST) -v ./...
|
@cd $(ROOTDIR) && $(GOTEST) -v ./...
|
||||||
|
|
||||||
test-coverage: ## Run tests with coverage
|
test-coverage: ## Run tests with coverage
|
||||||
@echo "Running tests with coverage..."
|
@echo "Running tests with coverage..."
|
||||||
@$(GOTEST) -v -coverprofile=coverage.out ./...
|
@cd $(ROOTDIR) && $(GOTEST) -v -coverprofile=coverage.out ./...
|
||||||
@$(GOCMD) tool cover -html=coverage.out -o coverage.html
|
@cd $(ROOTDIR) && $(GOCMD) tool cover -html=coverage.out -o coverage.html
|
||||||
|
|
||||||
fmt: ## Format Go code
|
fmt: ## Format Go code
|
||||||
@echo "Formatting code..."
|
@echo "Formatting code..."
|
||||||
@$(GOCMD) fmt ./...
|
@cd $(ROOTDIR) && $(GOCMD) fmt ./...
|
||||||
|
|
||||||
lint: ## Run golangci-lint (if installed)
|
lint: ## Run golangci-lint (if installed)
|
||||||
@echo "Running linter..."
|
@echo "Running linter..."
|
||||||
@if command -v golangci-lint > /dev/null; then \
|
@cd $(ROOTDIR) && if command -v golangci-lint > /dev/null; then \
|
||||||
golangci-lint run; \
|
golangci-lint run; \
|
||||||
else \
|
else \
|
||||||
echo "golangci-lint not found. Install from https://golangci-lint.run/usage/install/"; \
|
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
|
deps: ## Download dependencies
|
||||||
@echo "Downloading dependencies..."
|
@echo "Downloading dependencies..."
|
||||||
@$(GOMOD) download
|
@cd $(ROOTDIR) && $(GOMOD) download
|
||||||
@$(GOMOD) tidy
|
@cd $(ROOTDIR) && $(GOMOD) tidy
|
||||||
|
|
||||||
run: build ## Build and run the binary
|
run: build ## Build and run the binary
|
||||||
@echo "Running $(BINARY)..."
|
@echo "Running $(BINARY)..."
|
||||||
|
|||||||
Reference in New Issue
Block a user