This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
161 lines (132 loc) · 3.63 KB
/
Makefile
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# paths
makefile := $(realpath $(lastword $(MAKEFILE_LIST)))
cmd_dir := ./cmd/so
dist_dir := ./dist
# executables
CAT := cat
COLUMN := column
CTAGS := ctags
GO := go
GREP := grep
GZIP := gzip --best
LINT := revive
MKDIR := mkdir -p
RM := rm
SCC := scc
SED := sed
SORT := sort
ZIP := zip -m
# build flags
BUILD_FLAGS := -ldflags="-s -w" -mod vendor -trimpath
GOBIN :=
TMPDIR := /tmp
# release binaries
releases := \
$(dist_dir)/so-darwin-amd64 \
$(dist_dir)/so-linux-amd64 \
$(dist_dir)/so-linux-arm5 \
$(dist_dir)/so-linux-arm6 \
$(dist_dir)/so-linux-arm7 \
$(dist_dir)/so-windows-amd64.exe
## build: builds an executable for your architecture
.PHONY: build
build: $(dist_dir) clean vendor generate
$(GO) build $(BUILD_FLAGS) -o $(dist_dir)/so $(cmd_dir)
## build-release: builds release executables
.PHONY: build-release
build-release: $(releases)
## ci: builds a "release" executable for the current architecture (used in ci)
.PHONY: ci
ci: | setup prepare build
# so-darwin-amd64
$(dist_dir)/so-darwin-amd64: prepare
GOARCH=amd64 GOOS=darwin \
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
# so-linux-amd64
$(dist_dir)/so-linux-amd64: prepare
GOARCH=amd64 GOOS=linux \
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
# so-linux-arm5
$(dist_dir)/so-linux-arm5: prepare
GOARCH=arm GOOS=linux GOARM=5 \
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
# so-linux-arm6
$(dist_dir)/so-linux-arm6: prepare
GOARCH=arm GOOS=linux GOARM=6 \
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
# so-linux-arm7
$(dist_dir)/so-linux-arm7: prepare
GOARCH=arm GOOS=linux GOARM=7 \
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(GZIP) $@ && chmod -x $@.gz
# so-windows-amd64
$(dist_dir)/so-windows-amd64.exe: prepare
GOARCH=amd64 GOOS=windows \
$(GO) build $(BUILD_FLAGS) -o $@ $(cmd_dir) && $(ZIP) $@.zip $@
# ./dist
$(dist_dir):
$(MKDIR) $(dist_dir)
.PHONY: generate
generate:
$(GO) generate $(cmd_dir)
## install: builds and installs so on your PATH
.PHONY: install
install: build
$(GO) install $(BUILD_FLAGS) $(GOBIN) $(cmd_dir)
## clean: removes compiled executables
.PHONY: clean
clean: $(dist_dir)
$(RM) -f $(dist_dir)/*
## distclean: removes the tags file
.PHONY: distclean
distclean:
$(RM) -f tags
## setup: installs revive (linter) and scc (sloc tool)
.PHONY: setup
setup:
GO111MODULE=off $(GO) get -u github.com/boyter/scc github.com/mgechev/revive
## sloc: counts "semantic lines of code"
.PHONY: sloc
sloc:
$(SCC) --exclude-dir=vendor
## tags: builds a tags file
.PHONY: tags
tags:
$(CTAGS) -R --exclude=vendor --languages=go
## vendor: downloads, tidies, and verifies dependencies
.PHONY: vendor
vendor:
$(GO) mod vendor && $(GO) mod tidy && $(GO) mod verify
## fmt: runs go fmt
.PHONY: fmt
fmt:
$(GO) fmt ./...
## lint: lints go source files
.PHONY: lint
lint: vendor
$(LINT) -exclude vendor/... ./...
## vet: vets go source files
.PHONY: vet
vet:
$(GO) vet ./...
## test: runs unit-tests
.PHONY: test
test:
$(GO) test ./...
## coverage: generates a test coverage report
.PHONY: coverage
coverage:
$(GO) test ./... -coverprofile=$(TMPDIR)/so-coverage.out && \
$(GO) tool cover -html=$(TMPDIR)/so-coverage.out
## check: formats, lints, vets, vendors, and run unit-tests
.PHONY: check
check: | vendor fmt lint vet test
.PHONY: prepare
prepare: | $(dist_dir) clean generate vendor fmt lint vet test
## help: displays this help text
.PHONY: help
help:
@$(CAT) $(makefile) | \
$(SORT) | \
$(GREP) "^##" | \
$(SED) 's/## //g' | \
$(COLUMN) -t -s ':'