-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (53 loc) · 2.15 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
.PHONY: all clean generate fmt tidy
.PHONY: FORCE
GO ?= go
GOFMT ?= gofmt
GOFMT_FLAGS = -w -l -s
GOGENERATE_FLAGS = -v
GOPATH ?= $(shell $(GO) env GOPATH)
GOBIN ?= $(GOPATH)/bin
TOOLSDIR := $(CURDIR)/pkg/tools
TMPDIR ?= $(CURDIR)/.tmp
OUTDIR ?= $(TMPDIR)
REVIVE ?= $(GOBIN)/revive
REVIVE_CONF ?= $(TOOLSDIR)/revive.toml
REVIVE_RUN_ARGS ?= -config $(REVIVE_CONF) -formatter friendly
REVIVE_INSTALL_URL ?= github.com/mgechev/revive
GO_INSTALL_URLS = \
$(REVIVE_INSTALL_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 grep ^module go.mod | cut -d' ' -f2)
CMD_VERSION = $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
cat .version 2> /dev/null || echo v0)
CMD_COMMIT = $(shell git rev-parse --short HEAD)
CMD_BRANCH = $(shell git branch --show-current)
CMD_BUILDDATE = $(shell date -u +%s)
GO_VERSION_PACKAGE = $(MODULE)/pkg/version
GO_BUILD_CMD_LDFLAGS=-s -w \
-X $(GO_VERSION_PACKAGE).Version=$(CMD_VERSION) \
-X $(GO_VERSION_PACKAGE).Branch=$(CMD_BRANCH) \
-X $(GO_VERSION_PACKAGE).Commit=$(CMD_COMMIT) \
-X $(GO_VERSION_PACKAGE).BuildDate=$(CMD_BUILDDATE)
GO_BUILD = $(GO) build -v
GO_BUILD_CMD = $(GO_BUILD) -o "$(OUTDIR)" -ldflags "$(GO_BUILD_CMD_LDFLAGS)"
all: get generate tidy build
clean: ; $(info $(M) cleaning…)
rm -rf $(TMPDIR)
$(TMPDIR)/index: $(TOOLSDIR)/gen_index.sh Makefile FORCE ; $(info $(M) generating index…)
$Q mkdir -p $(@D)
$Q $< > $@~
$Q if cmp $@ $@~ 2> /dev/null >&2; then rm $@~; else mv $@~ $@; fi
$(TMPDIR)/gen.mk: $(TOOLSDIR)/gen_mk.sh $(TMPDIR)/index Makefile ; $(info $(M) generating subproject rules…)
$Q mkdir -p $(@D)
$Q $< $(TMPDIR)/index > $@~
$Q if cmp $@ $@~ 2> /dev/null >&2; then rm $@~; else mv $@~ $@; fi
include $(TMPDIR)/gen.mk
fmt: ; $(info $(M) reformatting sources…)
$Q find . -name '*.go' | xargs -r $(GOFMT) $(GOFMT_FLAGS)
tidy: fmt
generate: ; $(info $(M) running go:generate…)
$Q git grep -l '^//go:generate' | sort -uV | xargs -r -n1 $(GO) generate $(GOGENERATE_FLAGS)
$(REVIVE):
$Q $(GO) install -v $(REVIVE_INSTALL_URL)