-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
104 lines (83 loc) · 3.27 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
# Build flags
BUILD_FILES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
{{end}}' ./...)
VERSION := $(shell git describe --tags $(shell git rev-list --tags --max-count=1))
DATE_FMT = +%Y-%m-%d
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date "$(DATE_FMT)")
endif
REVISION := $(shell git rev-parse --short HEAD)
ifndef CGO_CPPFLAGS
export CGO_CPPFLAGS := $(CPPFLAGS)
endif
ifndef CGO_CFLAGS
export CGO_CFLAGS := $(CFLAGS)
endif
ifndef CGO_LDFLAGS
export CGO_LDFLAGS := $(LDFLAGS)
endif
GO_LDFLAGS := -X github.com/kmdkuk/goct/pkg/version.Revision=$(REVISION) $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/kmdkuk/goct/pkg/version.BuildDate=$(BUILD_DATE) $(GO_LDFLAGS)
DEV_LDFLAGS := $(GO_LDFLAGS)
GO_LDFLAGS := -X github.com/kmdkuk/goct/pkg/version.Version=$(VERSION) $(GO_LDFLAGS)
# Tools path
BIN_DIR := $(CURDIR)/bin
# Tools version
MDBOOK_VERSION = 0.4.19
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Build
build: $(BUILD_FILES) ## Build binary
go build -trimpath -ldflags "$(GO_LDFLAGS)" -o $(BIN_DIR)/ .
##@ Development
.PHONY: test
test: lint ## Run lint & test.
go test ./...
.PHONY: lint
lint: staticcheck golangci-lint ## Run lint
test -z "$$(gofmt -s -l . | tee /dev/stderr)"
$(STATICCHECK) ./...
$(GOLANGCI_LINT) run
go vet ./...
##@ Documentations
.PHONY: book
book: mdbook
rm -rf docs/book
cd docs; $(MDBOOK) build
.PHONY: serve-book
serve-book: mdbook
cd docs; $(MDBOOK) serve
##@ Tools
MDBOOK := $(BIN_DIR)/mdbook
.PHONY: mdbook
mdbook: $(MDBOOK) ## Donwload mdbook locally if necessary
$(MDBOOK):
mkdir -p $(BIN_DIR)
curl -fsL https://github.com/rust-lang/mdBook/releases/download/v$(MDBOOK_VERSION)/mdbook-v$(MDBOOK_VERSION)-x86_64-unknown-linux-gnu.tar.gz | tar -C $(BIN_DIR) -xzf -
STATICCHECK := $(BIN_DIR)/staticcheck
.PHONY: staticcheck
staticcheck: $(STATICCHECK)
$(STATICCHECK):
mkdir -p $(BIN_DIR)
GOBIN=$(BIN_DIR) go install honnef.co/go/tools/cmd/staticcheck@latest
GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
GOLANGCI_LINT_VERSION ?= v1.54.2
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) $(GOLANGCI_LINT_VERSION) ;\
}