-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
90 lines (72 loc) · 2.96 KB
/
Makefile
File metadata and controls
90 lines (72 loc) · 2.96 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
BINARY := gitgogit
PREFIX ?= /usr/local
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
DIST := dist
# Strip debug info (symbol table and DWARF) and embed version
GO_FLAGS += -ldflags="-s -w -X 'main.version=$(VERSION)'"
# Avoid embedding build path in executable
GO_FLAGS += -trimpath
.PHONY: build install system-install system-uninstall test clean platform-all platform-unixlike platform-darwin-arm64 platform-darwin-amd64 platform-linux-amd64 platform-linux-arm64 release
build:
go build -o $(BINARY) .
## install puts the binary on PATH via GOPATH/bin (no sudo required).
install:
go install .
## system-install copies the binary to $(PREFIX)/bin (may require sudo).
system-install: build
install -d $(PREFIX)/bin
install -m 755 $(BINARY) $(PREFIX)/bin/$(BINARY)
## system-uninstall removes the binary from $(PREFIX)/bin.
system-uninstall:
rm -f $(PREFIX)/bin/$(BINARY)
test:
go test ./...
clean:
rm -f $(BINARY)
rm -rf $(DIST)
##################
# Platform Build #
##################
platform-all:
@echo "Building all platform binaries..."
@mkdir -p $(DIST)
@$(MAKE) --no-print-directory -j4 \
platform-darwin-arm64 \
platform-darwin-amd64 \
platform-linux-amd64 \
platform-linux-arm64
platform-unixlike:
@test -n "$(TGOOS)" || (echo "GOOS must be set" && false)
@test -n "$(TGOARCH)" || (echo "GOARCH must be set" && false)
CGO_ENABLED=0 GOOS="$(TGOOS)" GOARCH="$(TGOARCH)" \
go build $(GO_FLAGS) -o "$(DIST)/$(BINARY)-$(TGOOS)-$(TGOARCH)"
platform-darwin-arm64:
@$(MAKE) --no-print-directory TGOOS=darwin TGOARCH=arm64 platform-unixlike
platform-darwin-amd64:
@$(MAKE) --no-print-directory TGOOS=darwin TGOARCH=amd64 platform-unixlike
platform-linux-amd64:
@$(MAKE) --no-print-directory TGOOS=linux TGOARCH=amd64 platform-unixlike
platform-linux-arm64:
@$(MAKE) --no-print-directory TGOOS=linux TGOARCH=arm64 platform-unixlike
###########
# Release #
###########
release: platform-all
@echo "Checking for gh CLI..." && gh --version > /dev/null
@echo "Checking for a version tag..." && \
git describe --tags --exact-match HEAD > /dev/null 2>&1 || \
(echo "HEAD is not tagged — run: git tag vX.Y.Z" && false)
@echo "Checking for uncommitted changes..." && \
test -z "`git status --porcelain`" || \
(echo "Cannot release with uncommitted changes:" && git status --porcelain && false)
@echo "Checking for main branch..." && \
test main = "`git rev-parse --abbrev-ref HEAD`" || \
(echo "Cannot release from non-main branch" && false)
@echo "Checking for unpushed commits..." && git fetch && \
test "" = "`git cherry`" || (echo "Cannot release with unpushed commits" && false)
@echo "Checking that tag $(VERSION) exists on remote..." && \
git ls-remote --tags origin "refs/tags/$(VERSION)" | grep -q "$(VERSION)" || \
(echo "Tag $(VERSION) has not been pushed — run: git push origin $(VERSION)" && false)
gh release create "$(VERSION)" $(DIST)/$(BINARY)-* \
--title "$(VERSION)" \
--generate-notes