blob: 2acc62fc16a0f8163a5b0812a10c3340faa250b2 (
plain) (
blame)
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
|
.POSIX:
# Standard GNU-ish install variables, so a packager can redirect everything:
# make install PREFIX=/usr DESTDIR=/tmp/pkg
DESTDIR ?=
PREFIX ?= $(HOME)/.local
BINDIR := $(DESTDIR)$(PREFIX)/bin
MANDIR := $(DESTDIR)$(PREFIX)/share/man/man1
BIN := prognosis
DIST := dist
MODULE := github.com/lukaszkasprzak/prognosis
# Version comes from git when there is a tag, "dev" otherwise, and is stamped
# into the binary so -version reports something meaningful.
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
GOFLAGS := -trimpath
LDFLAGS := -s -w -X main.version=$(VERSION)
PLATFORMS := linux/amd64 linux/arm64 android/arm64 darwin/amd64 darwin/arm64 freebsd/amd64
.PHONY: help build install uninstall test vet fmt lint ci cross release install-hooks clean
help: ## show this help
@grep -E '^[a-z-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[1m%-14s\033[0m %s\n", $$1, $$2}'
@echo
@echo " version: $(VERSION) prefix: $(PREFIX)"
build: ## build ./$(BIN)
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN) ./cmd/prognosis
install: build ## install the binary and man page
mkdir -p $(BINDIR) $(MANDIR)
# rm first: the target may be a symlink, and cp follows symlinks.
rm -f $(BINDIR)/$(BIN)
install -m 755 $(BIN) $(BINDIR)/$(BIN)
install -m 644 man/prognosis.1 $(MANDIR)/prognosis.1
@echo "installed $(BINDIR)/$(BIN) and $(MANDIR)/prognosis.1"
uninstall: ## remove the installed binary and man page
rm -f $(BINDIR)/$(BIN) $(MANDIR)/prognosis.1
test: ## run the tests
go test ./...
vet: ## go vet
go vet ./...
fmt: ## gofmt the tree
gofmt -w .
lint: ## check the man page renders without warnings
@out=$$(man --warnings -l man/prognosis.1 2>&1 >/dev/null); \
test -z "$$out" || { echo "man page warnings:"; echo "$$out"; exit 1; }
@echo "man page ok"
ci: ## the gate: gofmt, vet, tests, man page, and no third-party deps
@test -z "$$(gofmt -l .)" || { echo "gofmt needed:"; gofmt -l .; exit 1; }
go vet ./...
go test ./...
@$(MAKE) --no-print-directory lint
@deps=$$(go list -deps ./... | grep -E '^[a-z0-9-]+\.[a-z]+/' | grep -v '^$(MODULE)' || true); \
test -z "$$deps" || { echo "third-party dependencies crept in:"; echo "$$deps"; exit 1; }
@echo "ci ok"
cross: ## cross-compile every platform into $(DIST)/
@mkdir -p $(DIST)
@for p in $(PLATFORMS); do \
os=$${p%/*}; arch=$${p#*/}; \
echo " $$os/$$arch"; \
CGO_ENABLED=0 GOOS=$$os GOARCH=$$arch \
go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(DIST)/$(BIN)-$$os-$$arch ./cmd/prognosis || exit 1; \
done
@ls -la $(DIST)
release: ## tag a release: make release VERSION=0.2.0 (add its CHANGELOG entry first)
@test "$(VERSION)" != "dev" || { echo "give a version: make release VERSION=0.2.0"; exit 1; }
@grep -q "^## $(VERSION)" CHANGELOG.md || \
{ echo "CHANGELOG.md has no '## $(VERSION)' entry; write it first"; exit 1; }
@test -z "$$(git status --porcelain)" || { echo "working tree is dirty"; exit 1; }
@$(MAKE) --no-print-directory ci
git tag -a v$(VERSION) -m "prognosis v$(VERSION)"
@echo "tagged v$(VERSION); push it with: git push --tags"
install-hooks: ## install the pre-push hook that runs make ci
install -m 755 scripts/hooks/pre-push .git/hooks/pre-push
@echo "installed .git/hooks/pre-push"
clean: ## remove build artifacts
rm -rf $(BIN) $(DIST)
|