1
1
.PHONY : all build test tidy clean pretty install-tools lint install-hooks
2
+ .DEFAULT_GOAL := test_and_build
2
3
3
- GO := go
4
4
REQUIRED_GO_VERSION := 1.23
5
5
GOLANGCI_LINT_VERSION := v1.62.0
6
6
7
+ # Determine the Go binary directory
8
+ GOBIN_DIR := $(or $(GOBIN ) , $(shell go env GOBIN) )
9
+ ifeq ($(GOBIN_DIR ) ,)
10
+ GOBIN_DIR := $(shell go env GOPATH)/bin
11
+ endif
12
+
13
+ test_and_build : test build
14
+
7
15
# Version check
8
16
check_version :
9
- @GO_VERSION=$$($( GO ) version | awk '{print $$3}' | sed 's/go//') ; \
17
+ @GO_VERSION=$$(go version | awk '{print $$3}' | sed 's/go//' ) ; \
10
18
MAJOR_VERSION=$$(echo $$GO_VERSION | cut -d. -f1 ) ; \
11
19
MINOR_VERSION=$$(echo $$GO_VERSION | cut -d. -f2 ) ; \
12
20
if [ " $$ MAJOR_VERSION" -eq 1 ] && [ " $$ MINOR_VERSION" -lt 23 ]; then \
@@ -19,16 +27,16 @@ check_version:
19
27
default : check_version build
20
28
21
29
build :
22
- $( GO ) build -o vt ./go/vt
30
+ go build -o vt ./go/vt
23
31
24
32
test :
25
- $( GO ) test -count=1 ./go/...
33
+ go test -count=1 ./go/...
26
34
27
35
tidy :
28
- $( GO ) mod tidy
36
+ go mod tidy
29
37
30
38
clean :
31
- $( GO ) clean -i ./...
39
+ go clean -i ./...
32
40
rm -f vt
33
41
34
42
# Pretty: formats the code using gofumpt and goimports-reviser
@@ -46,7 +54,8 @@ install-tools:
46
54
go install github.com/incu6us/goimports-reviser/v3@latest
47
55
48
56
@echo "Installing golangci-lint..."
49
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION)
57
+ curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
58
+ sh -s -- -b $(GOBIN_DIR) $(GOLANGCI_LINT_VERSION)
50
59
51
60
@echo "All tools installed successfully."
52
61
0 commit comments