This repository was archived by the owner on Feb 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
134 lines (108 loc) · 2.92 KB
/
Makefile
File metadata and controls
134 lines (108 loc) · 2.92 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
MODULE := github.com/chimerical-llc/raven
CMDS := $(notdir $(wildcard ./cmd/*))
BINARIES := $(addprefix bin/,$(CMDS))
CMD ?= raven
GO := go
GOFMT := go fmt
GOVET := go vet
GOIMPORTS := go tool goimports
DEADCODE := go tool deadcode
GOVULNCHECK := go tool govulncheck
BUILDFLAGS := -buildvcs=true
PLATFORMS := linux/amd64
.PHONY: all build build-all buildinfo check clean deadcode deps fmt help \
imports install lint run test tidy tools uninstall verify vet \
vulncheck $(CMDS)
## Build all binaries (default target)
all: build
## Display this help screen
help:
@awk ' \
/^##/ { doc = substr($$0, 4); next } \
/^[a-zA-Z0-9_-]+:/ && doc { \
split($$1, target, ":"); \
printf "\033[36m%-20s\033[0m %s\n", target[1], doc; \
doc = "" \
} \
' $(MAKEFILE_LIST)
## Build all binaries to bin/
build: $(BINARIES)
## Build binaries for all defined platforms
build-all:
@for cmd in $(CMDS); do \
for platform in $(PLATFORMS); do \
echo "Building $$cmd for $$platform..."; \
out="bin/$$cmd-$${platform%/*}-$${platform#*/}"; \
GOOS=$${platform%/*} GOARCH=$${platform#*/} \
$(GO) build $(BUILDFLAGS) -o $$out ./cmd/$$cmd; \
done; \
done
## Build specific binaries (pattern rule)
bin/%: ./cmd/%
$(GO) build $(BUILDFLAGS) -o $@ ./$<
## Shortcut targets to build specific commands (e.g., 'make raven')
$(CMDS):
$(GO) build $(BUILDFLAGS) -o bin/$@ ./cmd/$@
## Show version info for built binaries
buildinfo: build
@for bin in $(BINARIES); do \
if [ -x $$bin ]; then \
echo "Info for $$bin:"; \
$(GO) version -m $$bin || true; \
fi; \
done
## Run tests with race detection and coverage
test:
$(GO) test -cover -race ./...
## Run all linters (fmt, vet, imports, deadcode, vulncheck)
lint: fmt vet imports deadcode vulncheck
## Format code using go fmt
fmt:
$(GOFMT) ./...
## Fix imports and format using goimports
imports:
$(GOIMPORTS) -w -local "$(MODULE)" .
## Run go vet
vet:
$(GOVET) ./...
## Find dead code
deadcode:
$(DEADCODE) ./...
## Check for vulnerabilities
vulncheck:
$(GOVULNCHECK) ./...
## Run integration checks (alias for lint)
check: lint
## Tidy go.mod dependencies
tidy:
$(GO) mod tidy
## Download dependencies
deps:
$(GO) mod download
## Verify dependencies
verify:
$(GO) mod verify
## Install development tools
tools:
go get -tool golang.org/x/tools/cmd/deadcode@latest
go get -tool golang.org/x/tools/cmd/goimports@latest
go get -tool golang.org/x/vuln/cmd/govulncheck@latest
## Run the default binary (use ARGS="..." to pass arguments)
run: bin/$(CMD)
./bin/$(CMD) $(ARGS)
## Clean build artifacts
clean:
$(GO) clean
rm -f bin/*
## Install binaries to $GOBIN
install:
$(GO) install $(BUILDFLAGS) ./cmd/...
## Uninstall binaries from $GOBIN
uninstall:
@for cmd in $(CMDS); do \
path=$$( $(GO) env GOBIN )/$$cmd; \
if [ -z "$$( $(GO) env GOBIN )" ]; \
then path=$$( $(GO) env GOPATH )/bin/$$cmd; fi; \
echo "Removing $$path"; \
rm -f $$path; \
done