Skip to content

Commit 687e649

Browse files
committed
Makefile: update Makefile
1 parent 401421e commit 687e649

File tree

1 file changed

+16
-28
lines changed

1 file changed

+16
-28
lines changed

Makefile

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# ----------------------------------------------------------------------------
22
# global
33

4-
SHELL=/usr/bin/env bash
5-
.DEFAULT_GOAL=test
4+
.DEFAULT_GOAL := test
65
comma := ,
76
empty :=
87
space := $(empty) $(empty)
@@ -14,14 +13,14 @@ ifneq ($(shell command -v go),)
1413
GO_PATH ?= $(shell go env GOPATH)
1514
GO_OS ?= $(shell go env GOOS)
1615
GO_ARCH ?= $(shell go env GOARCH)
17-
TOOLS_BIN=${CURDIR}/bin
16+
TOOLS_BIN=${CURDIR}/tools/bin
1817

1918
PKG := $(subst $(GO_PATH)/src/,,$(CURDIR))
2019
GO_PKGS := $(shell go list ./... | grep -v -e '.pb.go')
2120
GO_TEST_PKGS := $(shell go list -f='{{if or .TestGoFiles .XTestGoFiles}}{{.ImportPath}}{{end}}' ./...)
2221

2322
export GOTESTSUM_FORMAT=pkgname-and-test-fails
24-
GO_TEST ?= go test
23+
GO_TEST ?= ${TOOLS_BIN}/gotestsum --
2524
GO_TEST_FUNC ?= .
2625
GO_TEST_FLAGS ?=
2726
GO_BENCH_FUNC ?= .
@@ -37,35 +36,29 @@ endif
3736
# ----------------------------------------------------------------------------
3837
# defines
3938

40-
GOPHER = ""
39+
GOPHER = ""
4140
define target
4241
@printf "$(GOPHER) \\x1b[1;32m$(patsubst ,$@,$(1))\\x1b[0m\\n"
4342
endef
4443

4544
# ----------------------------------------------------------------------------
4645
# target
4746

48-
.PHONY: all
49-
all: mod pkg/install
50-
51-
.PHONY: pkg/install
52-
pkg/install:
53-
$(call target)
54-
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GO_OS) GOARCH=$(GO_ARCH) go install -v $(shell go list -f '{{if and (or .GoFiles .CgoFiles) (ne .Name "main")}}{{.ImportPath}}{{end}}' ${PKG}/...)
55-
5647
##@ tools
5748

5849
.PHONY: tools
59-
tools: ## Install tools
50+
tools: ${TOOLS_BIN} ## Install tools
51+
52+
${TOOLS_BIN}:
6053
cd tools; \
61-
go mod vendor -v; \
6254
for t in $$(go list -f '{{ join .Imports " " }}' -tags=tools); do \
63-
GOBIN=${CURDIR}/bin go install -v -x -mod=vendor "$${t}" > /dev/null 2>&1; \
55+
GOBIN=${TOOLS_BIN} go install -v -mod=mod "$${t}"; \
6456
done
6557

66-
##@ test, bench and coverage
58+
##@ test, bench, coverage
6759

6860
.PHONY: test
61+
test: ${TOOLS_BIN}
6962
test: CGO_ENABLED=1
7063
test: ## Runs package test including race condition.
7164
$(call target)
@@ -81,7 +74,7 @@ bench: ## Take a package benchmark.
8174
CGO_ENABLED=$(CGO_ENABLED) $(GO_TEST) -run='^$$' -bench=$(GO_BENCH_FUNC) -benchmem $(strip $(GO_FLAGS)) $(GO_TEST_PKGS)
8275

8376
.PHONY: coverage
84-
coverage: GO_TEST=${TOOLS_BIN}/gotestsum --
77+
coverage: ${TOOLS_BIN}
8578
coverage: CGO_ENABLED=1
8679
coverage: ## Takes packages test coverage.
8780
$(call target)
@@ -95,8 +88,9 @@ coverage/gojay: coverage
9588
.PHONY: lint
9689
lint: lint/golangci-lint ## Run all linters.
9790

91+
9892
.PHONY: lint/golangci-lint
99-
lint/golangci-lint: tools .golangci.yml ## Run golangci-lint.
93+
lint/golangci-lint: ${TOOLS_BIN} .golangci.yml ## Run golangci-lint.
10094
$(call target)
10195
@${TOOLS_BIN}/golangci-lint run $(strip ${GO_LINT_FLAGS}) ./...
10296

@@ -106,24 +100,18 @@ lint/golangci-lint: tools .golangci.yml ## Run golangci-lint.
106100
.PHONY: clean
107101
clean: ## Cleanups binaries and extra files in the package.
108102
$(call target)
109-
@$(RM) $(APP) *.out *.test *.prof trace.log
103+
@rm -rf *.out *.test *.prof trace.log ${TOOLS_BIN}
110104

111105

112106
##@ miscellaneous
113107

114-
.PHONY: AUTHORS
115-
AUTHORS: ## Creates AUTHORS file.
116-
@$(file >$@,# This file lists all individuals having contributed content to the repository.)
117-
@$(file >>$@,# For how it is generated, see `make AUTHORS`.)
118-
@printf "$(shell git log --format="\n%aN <%aE>" | LC_ALL=C.UTF-8 sort -uf)" >> $@
119-
120108
.PHONY: todo
121109
TODO: ## Print the all of (TODO|BUG|XXX|FIXME|NOTE) in packages.
122-
@rg -e '(TODO|BUG|XXX|FIXME|NOTE)(\(.+\):|:)' --follow --hidden --glob='!.git' --glob='!vendor' --glob='!internal' --glob='!Makefile' --glob='!snippets' --glob='!indent'
110+
@grep -E '(TODO|BUG|XXX|FIXME|NOTE)(\(.+\):|:)' $(find . -type f -name '*.go' -and -not -iwholename '*vendor*')
123111

124112

125113
##@ help
126114

127115
.PHONY: help
128-
help: ## Show make target help.
116+
help: ## Show this help.
129117
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[33m<target>\033[0m\n"} /^[a-zA-Z_0-9\/_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

0 commit comments

Comments
 (0)