-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (44 loc) · 1.55 KB
/
Copy pathMakefile
File metadata and controls
60 lines (44 loc) · 1.55 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
.PHONY: all clean fmt tidy install get build
.PHONY: FORCE
GO ?= go
GOFMT ?= gofmt
GOFMT_FLAGS = -w -l -s
GOPATH ?= $(shell $(GO) env GOPATH)
GOBIN ?= $(GOPATH)/bin
export GOPATH GOBIN
TMPDIR ?= $(CURDIR)/.tmp
OUTDIR ?= $(TMPDIR)
REVIVE_VERSION ?= v1.5.1
REVIVE_CONF ?= revive.toml
REVIVE_RUN_ARGS ?= -config $(REVIVE_CONF) -formatter friendly
REVIVE_URL ?= github.com/mgechev/revive@$(REVIVE_VERSION)
REVIVE ?= $(GO) run $(REVIVE_URL)
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell if [ "$$(tput colors 2> /dev/null || echo 0)" -ge 8 ]; then printf "\033[34;1m▶\033[0m"; else printf "▶"; fi)
MODULE = $(shell $(GO) list)
DATE ?= $(shell date +%F)
VERSION ?= $(shell git describe --tags --always --dirty=-dev --match=v* 2> /dev/null || \
cat .version 2> /dev/null || echo v0)
GO_BUILD_CMD_LDFLAGS = \
-X $(MODULE)/version.Version=$(VERSION) \
-X $(MODULE)/version.BuildDate=$(DATE)
GO_BUILD_CMD_FLAGS = -o "$(OUTDIR)/$(BINARY_NAME)" -ldflags "$(GO_BUILD_CMD_LDFLAGS)"
GO_BUILD = $(GO) build -v
GO_BUILD_CMD = $(GO_BUILD) $(GO_BUILD_CMD_FLAGS)
all: get tidy build
clean: ; $(info $(M) cleaning…)
rm -rf $(TMPDIR)
fmt: ; $(info $(M) reformatting sources…)
$Q find . -name '*.go' | xargs -r $(GOFMT) $(GOFMT_FLAGS)
install:
$Q $(GO) install -v -ldflags "$(GO_BUILD_CMD_LDFLAGS)" ./cmd/...
get: ; $(info $(M) getting dependencies…)
$Q $(GO) mod tidy
$Q $(GO) mod download
build: ; $(info $(M) building…)
$Q $(GO_BUILD_CMD)
tidy: | fmt ; $(info $(M) tidy: root)
$(Q) $(GO) mod tidy
$(Q) $(GO) vet ./...
$(Q) $(REVIVE) $(REVIVE_RUN_ARGS) ./...