Skip to content

Commit

Permalink
Makefile: Introduce GO_BUILD variable
Browse files Browse the repository at this point in the history
This allows users to overwrite the GO environment variable while still
using CGO_ENABLED=false. This for example is useful when testing
pre-releases of the Go compiler.

Signed-off-by: Sebastian Wicki <sebastian@isovalent.com>
  • Loading branch information
gandro committed May 27, 2021
1 parent b6e6c79 commit 0084a06
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GO := CGO_ENABLED=0 go
GO := go
GO_BUILD = CGO_ENABLED=0 $(GO) build
INSTALL = $(QUIET)install
BINDIR ?= /usr/local/bin
TARGET=hubble
Expand All @@ -17,7 +18,7 @@ TEST_TIMEOUT ?= 5s
all: hubble

hubble:
$(GO) build $(if $(GO_TAGS),-tags $(GO_TAGS)) -ldflags "-w -s -X 'github.com/cilium/hubble/pkg.GitBranch=${GIT_BRANCH}' -X 'github.com/cilium/hubble/pkg.GitHash=$(GIT_HASH)' -X 'github.com/cilium/hubble/pkg.Version=${VERSION}'" -o $(TARGET)
$(GO_BUILD) $(if $(GO_TAGS),-tags $(GO_TAGS)) -ldflags "-w -s -X 'github.com/cilium/hubble/pkg.GitBranch=${GIT_BRANCH}' -X 'github.com/cilium/hubble/pkg.GitHash=$(GIT_HASH)' -X 'github.com/cilium/hubble/pkg.Version=${VERSION}'" -o $(TARGET)

release:
docker run --env "RELEASE_UID=$(RELEASE_UID)" --env "RELEASE_GID=$(RELEASE_GID)" --rm --workdir /hubble --volume `pwd`:/hubble docker.io/library/golang:1.16.4-alpine3.13 \
Expand All @@ -42,7 +43,7 @@ local-release: clean
for ARCH in $$ARCHS; do \
echo Building release binary for $$OS/$$ARCH...; \
test -d release/$$OS/$$ARCH|| mkdir -p release/$$OS/$$ARCH; \
env GOOS=$$OS GOARCH=$$ARCH $(GO) build $(if $(GO_TAGS),-tags $(GO_TAGS)) -ldflags "-w -s -X 'github.com/cilium/hubble/pkg.Version=${VERSION}'" -o release/$$OS/$$ARCH/$(TARGET)$$EXT; \
env GOOS=$$OS GOARCH=$$ARCH $(GO_BUILD) $(if $(GO_TAGS),-tags $(GO_TAGS)) -ldflags "-w -s -X 'github.com/cilium/hubble/pkg.Version=${VERSION}'" -o release/$$OS/$$ARCH/$(TARGET)$$EXT; \
tar -czf release/$(TARGET)-$$OS-$$ARCH.tar.gz -C release/$$OS/$$ARCH $(TARGET)$$EXT; \
(cd release && sha256sum $(TARGET)-$$OS-$$ARCH.tar.gz > $(TARGET)-$$OS-$$ARCH.tar.gz.sha256sum); \
done; \
Expand All @@ -61,10 +62,10 @@ clean:
rm -rf ./release

test:
go test -timeout=$(TEST_TIMEOUT) -race -cover $$(go list ./...)
$(GO) test -timeout=$(TEST_TIMEOUT) -race -cover $$($(GO) list ./...)

bench:
go test -timeout=30s -bench=. $$(go list ./...)
$(GO) test -timeout=30s -bench=. $$($(GO) list ./...)

check: check-fmt ineffassign lint staticcheck vet

Expand All @@ -75,7 +76,7 @@ ineffassign:
./tools/ineffassign .

lint:
./tools/golint -set_exit_status $$(go list ./...)
./tools/golint -set_exit_status $$($(GO) list ./...)

# Ignored staticcheck warnings:
# - SA1019 deprecation warnings: https://staticcheck.io/docs/checks#SA1019
Expand All @@ -84,7 +85,7 @@ staticcheck:
./tools/staticcheck -checks="all,-SA1019,-ST1000" ./...

vet:
go vet $$(go list ./...)
$(GO) vet $$($(GO) list ./...)

image:
$(CONTAINER_ENGINE) build $(DOCKER_FLAGS) -t $(IMAGE_REPOSITORY)$(if $(IMAGE_TAG),:$(IMAGE_TAG)) .
Expand Down

0 comments on commit 0084a06

Please sign in to comment.