Skip to content

Commit 4414d0a

Browse files
committed
find GOPATH and use it
Signed-off-by: Andres Taylor <[email protected]>
1 parent 03ebcbc commit 4414d0a

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Makefile

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
.PHONY: all build test tidy clean pretty install-tools lint install-hooks
2+
.DEFAULT_GOAL := test_and_build
23

3-
GO := go
44
REQUIRED_GO_VERSION := 1.23
55
GOLANGCI_LINT_VERSION := v1.62.0
66

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+
715
# Version check
816
check_version:
9-
@GO_VERSION=$$($(GO) version | awk '{print $$3}' | sed 's/go//'); \
17+
@GO_VERSION=$$(go version | awk '{print $$3}' | sed 's/go//'); \
1018
MAJOR_VERSION=$$(echo $$GO_VERSION | cut -d. -f1); \
1119
MINOR_VERSION=$$(echo $$GO_VERSION | cut -d. -f2); \
1220
if [ "$$MAJOR_VERSION" -eq 1 ] && [ "$$MINOR_VERSION" -lt 23 ]; then \
@@ -19,16 +27,16 @@ check_version:
1927
default: check_version build
2028

2129
build:
22-
$(GO) build -o vt ./go/vt
30+
go build -o vt ./go/vt
2331

2432
test:
25-
$(GO) test -count=1 ./go/...
33+
go test -count=1 ./go/...
2634

2735
tidy:
28-
$(GO) mod tidy
36+
go mod tidy
2937

3038
clean:
31-
$(GO) clean -i ./...
39+
go clean -i ./...
3240
rm -f vt
3341

3442
# Pretty: formats the code using gofumpt and goimports-reviser
@@ -46,7 +54,8 @@ install-tools:
4654
go install github.com/incu6us/goimports-reviser/v3@latest
4755

4856
@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)
5059

5160
@echo "All tools installed successfully."
5261

0 commit comments

Comments
 (0)