From 3db1c3b8f406edf9e59714d0c65c2fdb37a18d65 Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Tue, 12 Nov 2019 11:52:49 -0800 Subject: [PATCH] Better support windows binaries. Signed-off-by: Lantao Liu --- Makefile | 12 ++++++++---- Makefile.windows | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index e98e85942..69a9a7d42 100644 --- a/Makefile +++ b/Makefile @@ -106,11 +106,11 @@ GO_GCFLAGS=$(shell \ echo "-gcflags=-trimpath=$${1}/src"; \ ) +BINARIES=$(addprefix bin/,$(COMMANDS)) + #include platform specific makefile -include Makefile.$(GOOS) -BINARIES=$(addprefix bin/,$(COMMANDS)) - # Flags passed to `go test` TESTFLAGS ?= $(TESTFLAGS_RACE) TESTFLAGS_PARALLEL ?= 8 @@ -178,10 +178,14 @@ benchmark: ## run benchmarks tests FORCE: +define BUILD_BINARY = +@echo "$(WHALE) $@" +@go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$< +endef + # Build a binary from a cmd. bin/%: cmd/% FORCE - @echo "$(WHALE) $@${BINARY_SUFFIX}" - @go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS} ./$< + $(BUILD_BINARY) bin/containerd-shim: cmd/containerd-shim FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220 @echo "$(WHALE) bin/containerd-shim" diff --git a/Makefile.windows b/Makefile.windows index 5dbb1f8a5..56164e424 100644 --- a/Makefile.windows +++ b/Makefile.windows @@ -17,9 +17,12 @@ WHALE = "+" ONI = "-" -BINARY_SUFFIX=".exe" - # amd64 supports go test -race ifeq ($(GOARCH),amd64) TESTFLAGS_RACE= -race endif + +BINARIES:=$(addsuffix .exe,$(BINARIES)) + +bin/%.exe: cmd/% FORCE + $(BUILD_BINARY)