Skip to content

Commit

Permalink
allow customising 'go' executable with GOEXE var (#2841)
Browse files Browse the repository at this point in the history
* allow customizing 'go' executable with GOEXE var

Signed-off-by: Dmitry S <dsavints@gmail.com>
---------

Signed-off-by: Dmitry S <dsavints@gmail.com>
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
Co-authored-by: Vincent Batts <vbatts@hashbangbash.com>
  • Loading branch information
dmitris and vbatts authored Mar 27, 2023
1 parent 653695a commit b41160e
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ else
SHELL = bash -x
endif

# allow overwriting the default `go` value with the custom path to the go executable
GOEXE ?= go

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
ifeq (,$(shell $(GOEXE) env GOBIN))
GOBIN=$(shell $(GOEXE) env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
GOBIN=$(shell $(GOEXE) env GOBIN)
endif

# Set version variables for LDFLAGS
Expand Down Expand Up @@ -76,20 +79,20 @@ log-%:
}'

cosign: $(SRCS)
CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o $@ ./cmd/cosign
CGO_ENABLED=0 $(GOEXE) build -trimpath -ldflags "$(LDFLAGS)" -o $@ ./cmd/cosign

cosign-pivkey-pkcs11key: $(SRCS)
CGO_ENABLED=1 go build -trimpath -tags=pivkey,pkcs11key -ldflags "$(LDFLAGS)" -o cosign ./cmd/cosign
CGO_ENABLED=1 $(GOEXE) build -trimpath -tags=pivkey,pkcs11key -ldflags "$(LDFLAGS)" -o cosign ./cmd/cosign

.PHONY: sget
sget: ## Build sget binary
go build -trimpath -ldflags "$(LDFLAGS)" -o $@ ./cmd/sget
$(GOEXE) build -trimpath -ldflags "$(LDFLAGS)" -o $@ ./cmd/sget

.PHONY: cross
cross:
$(foreach GOOS, $(PLATFORMS),\
$(foreach GOARCH, $(ARCHITECTURES), $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); \
go build -trimpath -ldflags "$(LDFLAGS)" -o cosign-$(GOOS)-$(GOARCH) ./cmd/cosign; \
$(GOEXE) build -trimpath -ldflags "$(LDFLAGS)" -o cosign-$(GOOS)-$(GOARCH) ./cmd/cosign; \
shasum -a 256 cosign-$(GOOS)-$(GOARCH) > cosign-$(GOOS)-$(GOARCH).sha256 ))) \

#####################
Expand All @@ -99,13 +102,13 @@ cross:
golangci-lint:
rm -f $(GOLANGCI_LINT_BIN) || :
set -e ;\
GOBIN=$(GOLANGCI_LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 ;\
GOBIN=$(GOLANGCI_LINT_DIR) $(GOEXE) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1 ;\

lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT_BIN) run -n

test:
go test $(shell go list ./... | grep -v third_party/)
$(GOEXE) test $(shell $(GOEXE) list ./... | grep -v third_party/)

clean:
rm -rf cosign
Expand Down Expand Up @@ -178,4 +181,4 @@ include test/ci.mk

.PHONY: docgen
docgen:
go run -tags pivkey,pkcs11key,cgo ./cmd/help/
$(GOEXE) run -tags pivkey,pkcs11key,cgo ./cmd/help/

0 comments on commit b41160e

Please sign in to comment.