Skip to content

Commit 753c9a8

Browse files
author
helen
committed
Makefile support cross compilation, build_bin_path optimization
Signed-off-by: helen <[email protected]>
1 parent 57039ef commit 753c9a8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Diff for: Makefile

+9-10
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,18 @@ MAKEFLAGS += --no-print-directory
1616
GO ?= go
1717

1818
GOARCH ?= $(shell $(GO) env GOARCH)
19+
GOOS ?= $(shell $(GO) env GOOS)
20+
ifeq ($(GOOS),windows)
21+
BIN_EXT := .exe
22+
endif
1923

2024
# test for go module support
2125
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
22-
export GO_BUILD=GO111MODULE=on GOARCH=$(GOARCH) $(GO) build -mod=vendor
23-
export GO_TEST=GO111MODULE=on GOARCH=$(GOARCH) $(GO) test -mod=vendor
26+
export GO_BUILD=GO111MODULE=on GOARCH=$(GOARCH) GOOS=$(GOOS) $(GO) build -mod=vendor
27+
export GO_TEST=GO111MODULE=on GOARCH=$(GOARCH) GOOS=$(GOOS) $(GO) test -mod=vendor
2428
else
25-
export GO_BUILD=GOARCH=$(GOARCH) $(GO) build
26-
export GO_TEST=GOARCH=$(GOARCH) $(GO) test
27-
endif
28-
29-
GOOS := $(shell $(GO) env GOOS)
30-
ifeq ($(GOOS),windows)
31-
BIN_EXT := .exe
29+
export GO_BUILD=GOARCH=$(GOARCH) GOOS=$(GOOS) $(GO) build
30+
export GO_TEST=GOARCH=$(GOARCH) GOOS=$(GOOS) $(GO) test
3231
endif
3332

3433
PROJECT := github.com/kubernetes-sigs/cri-tools
@@ -39,7 +38,7 @@ VERSION := $(VERSION:v%=%)
3938
GO_LDFLAGS := -X $(PROJECT)/pkg/version.Version=$(VERSION)
4039

4140
BUILD_PATH := $(shell pwd)/build
42-
BUILD_BIN_PATH := $(BUILD_PATH)/bin
41+
BUILD_BIN_PATH := $(BUILD_PATH)/bin/$(GOOS)/$(GOARCH)
4342

4443
define go-build
4544
$(shell cd `pwd` && $(GO_BUILD) -o $(BUILD_BIN_PATH)/$(shell basename $(1)) $(1))

0 commit comments

Comments
 (0)