Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
67 lines (54 loc) · 2.18 KB
/
Copy pathMakefile
File metadata and controls
67 lines (54 loc) · 2.18 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
VERSION := $(shell git describe --tags --always 2>/dev/null || echo "dev")
COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
DATE := $(shell date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u)
PKG := github.com/PatchMon/termd/internal/version
LDFLAGS := -ldflags "-X '$(PKG).Version=$(VERSION)' -X '$(PKG).Commit=$(COMMIT)' -X '$(PKG).Date=$(DATE)'"
# Every target published by .goreleaser.yaml. Kept in step with it so that
# `make crosscheck` proves a release will build before a tag is pushed.
PLATFORMS := \
linux/amd64 linux/arm64 linux/arm linux/386 linux/riscv64 \
darwin/amd64 darwin/arm64 \
windows/amd64 windows/arm64 windows/386 \
freebsd/amd64 freebsd/arm64 freebsd/386 freebsd/arm
.PHONY: build install test lint run clean crosscheck snapshot tidy fmt help
build: ## Build ./termd with version metadata
go build $(LDFLAGS) -o termd .
install: ## Install into $GOBIN
go install $(LDFLAGS) .
test: ## Run the test suite with the race detector
go test -race -count=1 ./...
fmt: ## Format all Go source
gofmt -w .
tidy: ## Tidy go.mod/go.sum
go mod tidy
lint: ## Run golangci-lint, falling back to go vet
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run ./...; \
else \
echo "golangci-lint not found; running go vet..."; \
go vet ./...; \
fi
crosscheck: ## Compile every release target
@fail=0; \
for p in $(PLATFORMS); do \
os=$${p%/*}; arch=$${p#*/}; \
if GOOS=$$os GOARCH=$$arch CGO_ENABLED=0 go build -o /dev/null . 2>/tmp/termd-cc.log; then \
printf ' ok %s\n' "$$p"; \
else \
printf ' FAIL %s\n' "$$p"; sed 's/^/ /' /tmp/termd-cc.log; fail=1; \
fi; \
done; \
rm -f /tmp/termd-cc.log; \
exit $$fail
snapshot: ## Full local release build (requires goreleaser)
@command -v goreleaser >/dev/null 2>&1 || { \
echo "goreleaser not found: https://goreleaser.com/install/"; exit 1; }
goreleaser release --snapshot --clean --skip=publish
run: build ## Build and run: make run ARGS=file.md
./termd $(ARGS)
clean: ## Remove build output
rm -f termd
rm -rf dist/
help: ## List targets
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " %-12s %s\n", $$1, $$2}'