-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
108 lines (92 loc) · 2.7 KB
/
Makefile
File metadata and controls
108 lines (92 loc) · 2.7 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Pommel Makefile
# Variables
BINARY_CLI = pm
BINARY_DAEMON = pommeld
BUILD_DIR = bin
GO = go
GOFLAGS = -trimpath
TAGS = fts5
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS = -s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.date=$(DATE)
# Default target
.PHONY: all
all: build
# Build both binaries
.PHONY: build
build: build-cli build-daemon
.PHONY: build-cli
build-cli:
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -tags "$(TAGS)" -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_CLI) ./cmd/pm
.PHONY: build-daemon
build-daemon:
@mkdir -p $(BUILD_DIR)
$(GO) build $(GOFLAGS) -tags "$(TAGS)" -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_DAEMON) ./cmd/pommeld
# Run tests
.PHONY: test
test:
$(GO) test -tags "$(TAGS)" -v -race -cover ./...
# Run tests with coverage report
.PHONY: coverage
coverage:
$(GO) test -tags "$(TAGS)" -v -race -coverprofile=coverage.out ./...
$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
# Run linter
.PHONY: lint
lint:
@which golangci-lint > /dev/null || (echo "Installing golangci-lint..." && go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest)
golangci-lint run ./...
# Format code
.PHONY: fmt
fmt:
$(GO) fmt ./...
@which goimports > /dev/null || go install golang.org/x/tools/cmd/goimports@latest
goimports -w .
# Clean build artifacts
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
$(GO) clean -cache -testcache
# Install binaries to GOPATH/bin
.PHONY: install
install:
$(GO) install -tags "$(TAGS)" ./cmd/pm
$(GO) install -tags "$(TAGS)" ./cmd/pommeld
# Run the CLI (for development)
.PHONY: run-cli
run-cli:
$(GO) run -tags "$(TAGS)" ./cmd/pm $(ARGS)
# Run the daemon (for development)
.PHONY: run-daemon
run-daemon:
$(GO) run -tags "$(TAGS)" ./cmd/pommeld $(ARGS)
# Tidy dependencies
.PHONY: tidy
tidy:
$(GO) mod tidy
# Download dependencies
.PHONY: deps
deps:
$(GO) mod download
# Show help
.PHONY: help
help:
@echo "Pommel Build Targets:"
@echo " make build - Build both binaries"
@echo " make build-cli - Build CLI only"
@echo " make build-daemon - Build daemon only"
@echo " make test - Run tests with race detection"
@echo " make coverage - Generate coverage report"
@echo " make lint - Run golangci-lint"
@echo " make fmt - Format code"
@echo " make clean - Clean build artifacts"
@echo " make install - Install binaries to GOPATH/bin"
@echo " make tidy - Tidy go.mod"
@echo " make deps - Download dependencies"