Don't hardcode go binary path in makefile

This commit is contained in:
Christoph Petrausch
2021-01-23 22:10:47 +01:00
parent 31cd757454
commit d02411db3b

View File

@@ -1,5 +1,9 @@
ifndef GOBINARY
GOBINARY:="go"
endif
ifndef GOPATH ifndef GOPATH
GOPATH:=$(shell go env GOPATH) GOPATH:=$(shell $(GOBINARY) env GOPATH)
endif endif
ifndef GOBIN ifndef GOBIN
@@ -7,15 +11,15 @@ ifndef GOBIN
endif endif
ifndef GOARCH ifndef GOARCH
GOARCH:=$(shell go env GOARCH) GOARCH:=$(shell $(GOBINARY) env GOARCH)
endif endif
ifndef GOOS ifndef GOOS
GOOS:=$(shell go env GOOS) GOOS:=$(shell $(GOBINARY) env GOOS)
endif endif
ifndef GOARM ifndef GOARM
GOARM:=$(shell go env GOARM) GOARM:=$(shell $(GOBINARY) env GOARM)
endif endif
ifndef TARGET_FILE ifndef TARGET_FILE
@@ -31,14 +35,14 @@ lint:
golangci-lint run golangci-lint run
test: test:
go test ./... $(GOBINARY) test ./...
go vet ./... $(GOBINARY) vet ./...
build: build:
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(TARGET_FILE) ./cmd GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBINARY) build -o $(TARGET_FILE) ./cmd
static_build: static_build:
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -o $(TARGET_FILE) -a -tags netgo -ldflags '-w -extldflags "-static"' ./cmd CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) $(GOBINARY) build -o $(TARGET_FILE) -a -tags netgo -ldflags '-w -extldflags "-static"' ./cmd
container: container:
docker build -t mqtt2prometheus:latest . docker build -t mqtt2prometheus:latest .