This repository has been archived by the owner on May 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
96 lines (67 loc) · 1.97 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
# add all your cmd/<things> in here that you want to build
TARGETS = executable
CMD_DIR := ./cmd
PKG_DIR := ./pkg
OUT_DIR := ./out
DIST_TAR := dist.tar.gz
COV_FILE := cover.out
DIST_OS += linux darwin
DIST_ARCH += amd64
GO_CMD ?= go
CGO_ENABLED ?= 0
EXTERNAL_TOOLS=\
github.com/client9/misspell/cmd/misspell \
github.com/golangci/golangci-lint/cmd/golangci-lint
GO111MODULE := on
GO_TEST_FLAGS := -v -count=1 -race -coverprofile=$(OUT_DIR)/$(COV_FILE) -covermode=atomic -parallel=16
.PHONY: deps
.PHONY: $(OUT_DIR) clean mod purge
.PHONY: test cover test-deps bench
.PHONY: lint-fmt lint-vet lint-misspell lint-ci lint
.PHONY: build dist
all: clean mod lint-fmt lint-vet test build
deps:
@for tool in $(EXTERNAL_TOOLS) ; do \
echo "Installing/Updating $$tool" ; \
GO111MODULE=off $(GO_CMD) get -u $$tool; \
done
$(OUT_DIR):
@mkdir -p $(OUT_DIR)
clean:
@rm -rf $(OUT_DIR)
purge: clean
$(GO_CMD) mod tidy
$(GO_CMD) clean -cache
$(GO_CMD) clean -testcache
$(GO_CMD) clean -modcache
dist: clean $(OUT_DIR)
@$(foreach arch, $(DIST_ARCH), \
$(foreach os,$(DIST_OS), \
$(foreach target, $(TARGETS), \
GOOS=$(os) GOARCH=$(arch) CGO_ENABLED=$(CGO_ENABLED) $(GO_CMD) build -o $(OUT_DIR)/$(target)_$(os)_$(arch) $(CMD_DIR)/$(target)/*.go && \
shasum $(OUT_DIR)/$(target)_$(os)_$(arch) > $(OUT_DIR)/$(target)_$(os)_$(arch).shasum; \
)))
@cd $(OUT_DIR) && \
tar -czvf $(DIST_TAR) --exclude $(DIST_TAR) *
build: $(OUT_DIR)
$(foreach target,$(TARGETS),go build -o $(OUT_DIR)/$(target) $(CMD_DIR)/$(target)/*.go;)
test: $(OUT_DIR)
$(GO_CMD) test $(GO_TEST_FLAGS) ./...
mod:
$(GO_CMD) mod tidy
$(GO_CMD) mod verify
cover: $(OUT_DIR)
$(GO_CMD) tool cover -html=$(OUT_DIR)/$(COV_FILE)
test-deps:
$(GO_CMD) test all
lint: lint-fmt lint-vet lint-misspell lint-ci
lint-fmt:
$(GO_CMD) fmt ./...
lint-vet:
$(GO_CMD) vet ./...
lint-ci:
golangci-lint run -v ./...
lint-misspell:
misspell -error ./...
bench:
$(GO_CMD) test -bench=. -benchmem -benchtime=10s ./...