1- # # https://www.gnu.org/software/make/manual/html_node/Secondary-Expansion.html
2- # # in order for
3- # .SECONDEXPANSION:
4-
5- # # https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-not-intermediate-targets_002c-explicit
6- # # NOTINTERMEDIATE requires make >=4.4
7- .NOTINTERMEDIATE :
8-
91# https://www.gnu.org/software/make/manual/make.html#Automatic-Variables
102# https://www.gnu.org/software/make/manual/make.html#Prerequisite-Types
113
@@ -21,7 +13,9 @@ tools: \
2113 $(TOOLS_BIN ) /staticcheck \
2214 $(TOOLS_BIN ) /golangci-lint \
2315 $(TOOLS_BIN ) /gofumpt \
24- $(TOOLS_BIN ) /gojq
16+ $(TOOLS_BIN ) /gojq \
17+ $(TOOLS_BIN ) /shfmt \
18+ $(TOOLS_BIN ) /shellcheck
2519
2620.PHONY : clean-tools
2721clean-tools :
@@ -45,17 +39,24 @@ define go_install
4539 @echo ""
4640endef
4741
42+ # export GOMOD=$(shell pwd)/go_tools.mod
43+ # go get -modfile='go_tools.mod' -u ...
44+ define go_mod_ver
45+ $(shell go list -modfile='./tools/go.mod' -m $(1 ) | cut -d ' ' -f2)
46+ endef
47+
48+
4849.PHONY : vet
4950vet :
5051 go vet ` $( GO_PACKAGES) `
5152 @echo " "
5253
5354# # <staticcheck>
5455# https://github.com/dominikh/go-tools/releases https://staticcheck.io/c
55- STATICCHECK_CMD : =honnef.co/go/tools/cmd/staticcheck
56- STATICCHECK_VER: =2024.1.1
56+ STATICCHECK_MOD : =honnef.co/go/tools
57+ STATICCHECK_VER: =$( call go_mod_ver, $( STATICCHECK_MOD ) )
5758$(TOOLS_BIN ) /staticcheck : $(TOOLS_DB ) /staticcheck.$(STATICCHECK_VER ) .$(GO_VER ) .ver
58- $(call go_install,staticcheck,$(STATICCHECK_CMD ) ,$(STATICCHECK_VER ) )
59+ $(call go_install,staticcheck,$(STATICCHECK_MOD ) /cmd/staticcheck ,$(STATICCHECK_VER ) )
5960
6061.PHONY : staticcheck
6162staticcheck : $(TOOLS_BIN ) /staticcheck
@@ -65,52 +66,47 @@ staticcheck: $(TOOLS_BIN)/staticcheck
6566
6667# # <golangci-lint>
6768# https://github.com/golangci/golangci-lint/releases
68- GOLANGCI-LINT_CMD : =github.com/golangci/golangci-lint/cmd /golangci-lint
69- GOLANGCI-LINT_VER: =v1.63.4
69+ GOLANGCI-LINT_MOD : =github.com/golangci/golangci-lint
70+ GOLANGCI-LINT_VER: =$( call go_mod_ver, $( GOLANGCI-LINT_MOD ) )
7071$(TOOLS_BIN ) /golangci-lint : $(TOOLS_DB ) /golangci-lint.$(GOLANGCI-LINT_VER ) .$(GO_VER ) .ver
7172 @curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(TOOLS_BIN ) $(GOLANGCI-LINT_VER )
7273
7374.PHONY : golangci-lint
7475golangci-lint : $(TOOLS_BIN ) /golangci-lint
75- $(TOOLS_BIN ) /golangci-lint run
76- @echo ' '
77-
78- .PHONY : golangci-lint-github-actions
79- golangci-lint-github-actions : $(TOOLS_BIN ) /golangci-lint
8076 golangci-lint run --out-format colored-line-number
8177 @echo ' '
8278# # </golangci-lint>
8379
8480# # <goimports>
8581# https://pkg.go.dev/golang.org/x/tools?tab=versions
86- GOIMPORTS_CMD := golang.org/x/tools/cmd/goimports
87- GOIMPORTS_VER := v0.28.0
82+ GOIMPORTS_MOD: = golang.org/x/tools
83+ GOIMPORTS_VER: = $( call go_mod_ver, $( GOIMPORTS_MOD ) )
8884$(TOOLS_BIN ) /goimports : $(TOOLS_DB ) /goimports.$(GOIMPORTS_VER ) .$(GO_VER ) .ver
89- $(call go_install,goimports,$(GOIMPORTS_CMD ) ,$(GOIMPORTS_VER ) )
85+ $(call go_install,goimports,$(GOIMPORTS_MOD ) /cmd/goimports ,$(GOIMPORTS_VER ) )
9086
9187.PHONY : goimports
9288goimports : $(TOOLS_BIN ) /goimports
93- $( TOOLS_BIN ) / goimports -w ` $( GO_FILES) `
89+ goimports -w ` $( GO_FILES) `
9490
9591.PHONY : goimports.display
9692goimports.display : $(TOOLS_BIN ) /goimports
97- $( TOOLS_BIN ) / goimports -d ` $( GO_FILES) `
93+ goimports -d ` $( GO_FILES) `
9894# # </goimports>
9995
10096# # <gofumpt>
10197# https://github.com/mvdan/gofumpt/releases
102- GOFUMPT_CMD : =mvdan.cc/gofumpt
103- GOFUMPT_VER: =v0.7.0
98+ GOFUMPT_MOD : =mvdan.cc/gofumpt
99+ GOFUMPT_VER: =$( call go_mod_ver, $( GOFUMPT_MOD ) )
104100$(TOOLS_BIN ) /gofumpt : $(TOOLS_DB ) /gofumpt.$(GOFUMPT_VER ) .$(GO_VER ) .ver
105- $(call go_install,gofumpt,$(GOFUMPT_CMD ) ,$(GOFUMPT_VER ) )
101+ $(call go_install,gofumpt,$(GOFUMPT_MOD ) ,$(GOFUMPT_VER ) )
106102
107103.PHONY : gofumpt
108104gofumpt : $(TOOLS_BIN ) /gofumpt
109- $( TOOLS_BIN ) / gofumpt -w ` $( GO_FILES) `
105+ gofumpt -w ` $( GO_FILES) `
110106
111107.PHONY : gofumpt.display
112108gofumpt.display :
113- $( TOOLS_BIN ) / gofumpt -d ` $( GO_FILES) `
109+ gofumpt -d ` $( GO_FILES) `
114110# # </gofumpt>
115111
116112# # <gofmt>
@@ -125,21 +121,21 @@ gofmt.display:
125121
126122# # <gojq>
127123# https://github.com/itchyny/gojq/releases
128- GOJQ_CMD := github.com/itchyny/gojq/cmd /gojq
129- GOJQ_VER := v0.12.17
124+ GOJQ_MOD: = github.com/itchyny/gojq
125+ GOJQ_VER: = $( call go_mod_ver, $( GOJQ_MOD ) )
130126$(TOOLS_BIN ) /gojq : $(TOOLS_DB ) /gojq.$(GOJQ_VER ) .$(GO_VER ) .ver
131- $(call go_install,gojq,$(GOJQ_CMD ) ,$(GOJQ_VER ) )
127+ $(call go_install,gojq,$(GOJQ_MOD ) /cmd/gojq ,$(GOJQ_VER ) )
132128
133129.PHONY : gojq
134130gojq : $(TOOLS_BIN ) /gojq
135131# # </gojq>
136132
137133# # <air>
138134# https://github.com/air-verse/air/releases
139- AIR_CMD : =github.com/air-verse/air
140- AIR_VER: =v1.61.5
135+ AIR_MOD : =github.com/air-verse/air
136+ AIR_VER: =$( call go_mod_ver, $( AIR_MOD ) )
141137$(TOOLS_BIN ) /air : $(TOOLS_DB ) /air.$(AIR_VER ) .$(GO_VER ) .ver
142- $(call go_install,air,$(AIR_CMD ) ,$(AIR_VER ) )
138+ $(call go_install,air,$(AIR_MOD ) ,$(AIR_VER ) )
143139
144140.PHONY : air
145141air : $(TOOLS_BIN ) /air
@@ -148,10 +144,10 @@ air: $(TOOLS_BIN)/air
148144
149145# # <mockery>
150146# https://github.com/vektra/mockery/releases
151- MOCKERY_CMD : =github.com/vektra/mockery/v2
152- MOCKERY_VER: =v2.50.2
147+ MOCKERY_MOD : =github.com/vektra/mockery/v2
148+ MOCKERY_VER: =$( call go_mod_ver, $( MOCKERY_MOD ) )
153149$(TOOLS_BIN ) /mockery : $(TOOLS_DB ) /mockery.$(MOCKERY_VER ) .$(GO_VER ) .ver
154- $(call go_install,air,$(MOCKERY_CMD ) ,$(MOCKERY_VER ) )
150+ $(call go_install,air,$(MOCKERY_MOD ) ,$(MOCKERY_VER ) )
155151
156152.PHONY : mockery
157153mockery : $(TOOLS_BIN ) /mockery
@@ -179,14 +175,19 @@ proto: $(TOOLS_BIN)/protoc $(TOOLS_BIN)/protoc-gen-go
179175
180176# # <shfmt>
181177# https://github.com/mvdan/sh/releases
182- SHFMT_CMD := mvdan.cc/sh/v3/cmd/shfmt
183- SHFMT_VER := v3.10.0
178+ SHFMT_MOD: = mvdan.cc/sh/v3
179+ SHFMT_VER: = $( call go_mod_ver, $( SHFMT_MOD ) )
184180$(TOOLS_BIN ) /shfmt : $(TOOLS_DB ) /shfmt.$(SHFMT_VER ) .$(GO_VER ) .ver
185- $(call go_install,shfmt,$(SHFMT_CMD ) ,$(SHFMT_VER ) )
181+ $(call go_install,shfmt,$(SHFMT_MOD ) /cmd/shfmt ,$(SHFMT_VER ) )
186182
187183.PHONY : shfmt
188184shfmt : $(TOOLS_BIN ) /shfmt
189- @./scripts/foreach-script $(TOOLS_BIN ) /shfmt --simplify --language-dialect auto --case-indent --indent 2 --write
185+ ./scripts/foreach-script $(TOOLS_BIN ) /shfmt \
186+ --simplify \
187+ --language-dialect auto \
188+ --case-indent \
189+ --indent 2 \
190+ --write
190191# # </shfmt>
191192
192193# # <shellcheck>
@@ -197,5 +198,9 @@ $(TOOLS_BIN)/shellcheck: $(TOOLS_DB)/shellcheck.$(SHELLCHECK_VER).ver | $(TOOLS_
197198
198199.PHONY : shellcheck
199200shellcheck : $(TOOLS_BIN ) /shellcheck
200- @./scripts/foreach-script $(TOOLS_BIN ) /shellcheck --external-sources --format=tty --severity=info
201+ ./scripts/foreach-script $(TOOLS_BIN ) /shellcheck \
202+ --norc \
203+ --external-sources \
204+ --format=tty \
205+ --enable=require-variable-braces,add-default-case
201206# # </shellcheck>
0 commit comments