Skip to content

Commit

Permalink
(makefile) Dynamically set GOARCH flag while building binaries (#2871)
Browse files Browse the repository at this point in the history
The GOARCH flag was hardcoded to "386", which causes the binaries to not
work properly on machines with arm64 arch. This PR dynamically sets the
GOARCH flag to arm64 if the machine arch is arm64, or to 386 for all other
arch.

Signed-off-by: anik120 <anikbhattacharya93@gmail.com>

Signed-off-by: anik120 <anikbhattacharya93@gmail.com>
  • Loading branch information
anik120 committed Oct 12, 2022
1 parent caab6c5 commit a8edd5c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ GO := GO111MODULE=on GOFLAGS="$(MOD_FLAGS)" go
GINKGO := $(GO) run github.com/onsi/ginkgo/v2/ginkgo
BINDATA := $(GO) run github.com/go-bindata/go-bindata/v3/go-bindata
GIT_COMMIT := $(shell git rev-parse HEAD)

ifeq ($(shell arch), arm64)
ARCH := arm64
else
ARCH := 386
endif
# Phony prerequisite for targets that rely on the go build cache to determine staleness.
.PHONY: build test clean vendor \
coverage coverage-html e2e \
Expand Down Expand Up @@ -82,15 +86,15 @@ build-coverage: build_cmd=test -c -covermode=count -coverpkg ./pkg/controller/..
build-coverage: clean $(CMDS)

build-linux: build_cmd=build
build-linux: arch_flags=GOOS=linux GOARCH=386
build-linux: arch_flags=GOOS=linux GOARCH=$(ARCH)
build-linux: clean $(CMDS)

build-wait: clean bin/wait

bin/wait: FORCE
GOOS=linux GOARCH=386 go build $(MOD_FLAGS) -o $@ $(PKG)/test/e2e/wait
GOOS=linux GOARCH=$(ARCH) go build $(MOD_FLAGS) -o $@ $(PKG)/test/e2e/wait

build-util-linux: arch_flags=GOOS=linux GOARCH=386
build-util-linux: arch_flags=GOOS=linux GOARCH=$(ARCH)
build-util-linux: build-util

build-util: bin/cpb
Expand Down

0 comments on commit a8edd5c

Please sign in to comment.