-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
94 lines (78 loc) · 2.31 KB
/
Copy pathMakefile
File metadata and controls
94 lines (78 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Cloak Makefile
# Build variables
BINARY_NAME := cloak
BUILD_DIR := ./bin
CMD_DIR := ./cmd/cloak
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
LDFLAGS := -ldflags "-s -w -X main.Version=$(VERSION) -X main.BuildTime=$(BUILD_TIME)"
# Go variables
GOCMD := go
GOBUILD := $(GOCMD) build
GOTEST := $(GOCMD) test
GOMOD := $(GOCMD) mod
GOFMT := gofmt
GOVET := $(GOCMD) vet
# Default target
.DEFAULT_GOAL := build
.PHONY: all build clean test test-verbose test-coverage lint fmt vet tidy install help
## build: Build the binary
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) $(CMD_DIR)
@echo "Binary built: $(BUILD_DIR)/$(BINARY_NAME)"
## install: Install the binary to GOPATH/bin
install:
@echo "Installing $(BINARY_NAME)..."
$(GOBUILD) $(LDFLAGS) -o $(GOPATH)/bin/$(BINARY_NAME) $(CMD_DIR)
@echo "Installed to $(GOPATH)/bin/$(BINARY_NAME)"
## clean: Remove build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR)
@rm -f coverage.out coverage.html
@echo "Clean complete"
## test: Run tests
test:
@echo "Running tests..."
$(GOTEST) -race ./...
## test-verbose: Run tests with verbose output
test-verbose:
@echo "Running tests (verbose)..."
$(GOTEST) -race -v ./...
## test-coverage: Run tests with coverage report
test-coverage:
@echo "Running tests with coverage..."
$(GOTEST) -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
## lint: Run linters (requires golangci-lint)
lint:
@echo "Running linters..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not installed. Install with: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"; \
exit 1; \
fi
## fmt: Format code
fmt:
@echo "Formatting code..."
$(GOFMT) -s -w .
## vet: Run go vet
vet:
@echo "Running go vet..."
$(GOVET) ./...
## tidy: Tidy go modules
tidy:
@echo "Tidying modules..."
$(GOMOD) tidy
## all: Run fmt, vet, test, and build
all: fmt vet test build
## help: Show this help message
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed 's/^/ /'