1313# limitations under the License.
1414
1515
16+ # Go command to use for build
17+ GO ?= go
18+
1619# Root directory of the project (absolute path).
1720ROOTDIR =$(dir $(abspath $(lastword $(MAKEFILE_LIST ) ) ) )
1821
@@ -26,9 +29,9 @@ REVISION=$(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet
2629PACKAGE =github.com/containerd/containerd
2730SHIM_CGO_ENABLED ?= 0
2831
29- ifneq "$(strip $(shell command -v go 2>/dev/null) ) " ""
30- GOOS ?= $(shell go env GOOS)
31- GOARCH ?= $(shell go env GOARCH)
32+ ifneq "$(strip $(shell command -v $( GO ) 2>/dev/null) ) " ""
33+ GOOS ?= $(shell $(GO) env GOOS)
34+ GOARCH ?= $(shell $(GO) env GOARCH)
3235else
3336 ifeq ($(GOOS),)
3437 # approximate GOOS for the platform if we don't have Go and GOOS isn't
@@ -85,7 +88,7 @@ GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revi
8588SHIM_GO_LDFLAGS =-ldflags '-X $(PKG ) /version.Version=$(VERSION ) -X $(PKG ) /version.Revision=$(REVISION ) -X $(PKG ) /version.Package=$(PACKAGE ) -extldflags "-static" $(EXTRA_LDFLAGS ) '
8689
8790# Project packages.
88- PACKAGES =$(shell go list ${GO_TAGS} ./... | grep -v /vendor/ | grep -v /integration)
91+ PACKAGES =$(shell $( GO ) list ${GO_TAGS} ./... | grep -v /vendor/ | grep -v /integration)
8992TEST_REQUIRES_ROOT_PACKAGES =$(filter \
9093 ${PACKAGES}, \
9194 $(shell \
@@ -122,7 +125,7 @@ TESTFLAGS ?= $(TESTFLAGS_RACE) $(EXTRA_TESTFLAGS)
122125TESTFLAGS_PARALLEL ?= 8
123126
124127# Use this to replace `go test` with, for instance, `gotestsum`
125- GOTEST ?= go test
128+ GOTEST ?= $( GO ) test
126129
127130OUTPUTDIR = $(join $(ROOTDIR ) , _output)
128131CRIDIR =$(OUTPUTDIR ) /cri
@@ -143,7 +146,7 @@ AUTHORS: .mailmap .git/HEAD
143146
144147generate : protos
145148 @echo " $( WHALE) $@ "
146- @PATH=" ${ROOTDIR} /bin:${PATH} " go generate -x ${PACKAGES}
149+ @PATH=" ${ROOTDIR} /bin:${PATH} " $( GO ) generate -x ${PACKAGES}
147150
148151protos : bin/protoc-gen-gogoctrd # # generate protobuf
149152 @echo " $( WHALE) $@ "
@@ -170,7 +173,7 @@ proto-fmt: ## check format of proto files
170173
171174build : # # build the go packages
172175 @echo " $( WHALE) $@ "
173- @go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES}
176+ @$( GO ) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES}
174177
175178test : # # run tests, except integration tests and tests that require root
176179 @echo " $( WHALE) $@ "
@@ -182,12 +185,12 @@ root-test: ## run tests, except integration tests
182185
183186integration : # # run integration tests
184187 @echo " $( WHALE) $@ "
185- @cd " ${ROOTDIR} /integration/client" && go mod download && $(GOTEST ) -v ${TESTFLAGS} -test.root -parallel ${TESTFLAGS_PARALLEL} .
188+ @cd " ${ROOTDIR} /integration/client" && $( GO ) mod download && $(GOTEST ) -v ${TESTFLAGS} -test.root -parallel ${TESTFLAGS_PARALLEL} .
186189
187190# TODO integrate cri integration bucket with coverage
188191bin/cri-integration.test :
189192 @echo " $( WHALE) $@ "
190- @go test -c ./integration -o bin/cri-integration.test
193+ @$( GO ) test -c ./integration -o bin/cri-integration.test
191194
192195cri-integration : binaries bin/cri-integration.test # # run cri integration tests
193196 @echo " $( WHALE) $@ "
@@ -196,13 +199,13 @@ cri-integration: binaries bin/cri-integration.test ## run cri integration tests
196199
197200benchmark : # # run benchmarks tests
198201 @echo " $( WHALE) $@ "
199- @go test ${TESTFLAGS} -bench . -run Benchmark -test.root
202+ @$( GO ) test ${TESTFLAGS} -bench . -run Benchmark -test.root
200203
201204FORCE :
202205
203206define BUILD_BINARY
204207@echo "$(WHALE ) $@ "
205- @go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$<
208+ @$( GO ) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$<
206209endef
207210
208211# Build a binary from a cmd.
@@ -211,15 +214,15 @@ bin/%: cmd/% FORCE
211214
212215bin/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
213216 @echo " $( WHALE) bin/containerd-shim"
214- @CGO_ENABLED=${SHIM_CGO_ENABLED} go build ${GO_BUILD_FLAGS} -o bin/containerd-shim ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim
217+ @CGO_ENABLED=${SHIM_CGO_ENABLED} $( GO ) build ${GO_BUILD_FLAGS} -o bin/containerd-shim ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim
215218
216219bin/containerd-shim-runc-v1 : cmd/containerd-shim-runc-v1 FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220
217220 @echo " $( WHALE) bin/containerd-shim-runc-v1"
218- @CGO_ENABLED=${SHIM_CGO_ENABLED} go build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v1 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v1
221+ @CGO_ENABLED=${SHIM_CGO_ENABLED} $( GO ) build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v1 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v1
219222
220223bin/containerd-shim-runc-v2 : cmd/containerd-shim-runc-v2 FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220
221224 @echo " $( WHALE) bin/containerd-shim-runc-v2"
222- @CGO_ENABLED=${SHIM_CGO_ENABLED} go build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v2 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v2
225+ @CGO_ENABLED=${SHIM_CGO_ENABLED} $( GO ) build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v2 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v2
223226
224227binaries : $(BINARIES ) # # build binaries
225228 @echo " $( WHALE) $@ "
@@ -235,11 +238,11 @@ genman: man/containerd.8 man/ctr.8
235238
236239man/containerd.8 : FORCE
237240 @echo " $( WHALE) $@ "
238- go run cmd/gen-manpages/main.go $(@F ) $(@D )
241+ $( GO ) run cmd/gen-manpages/main.go $(@F ) $(@D )
239242
240243man/ctr.8 : FORCE
241244 @echo " $( WHALE) $@ "
242- go run cmd/gen-manpages/main.go $(@F ) $(@D )
245+ $( GO ) run cmd/gen-manpages/main.go $(@F ) $(@D )
243246
244247man/% : docs/man/% .md FORCE
245248 @echo " $( WHALE) $@ "
@@ -365,9 +368,9 @@ endif
365368coverage : # # generate coverprofiles from the unit tests, except tests that require root
366369 @echo " $( WHALE) $@ "
367370 @rm -f coverage.txt
368- @go test -i ${TESTFLAGS} ${PACKAGES} 2> /dev/null
371+ @$( GO ) test -i ${TESTFLAGS} ${PACKAGES} 2> /dev/null
369372 @ ( for pkg in ${PACKAGES} ; do \
370- go test ${TESTFLAGS} \
373+ $( GO ) test ${TESTFLAGS} \
371374 -cover \
372375 -coverprofile=profile.out \
373376 -covermode=atomic $$ pkg || exit ; \
@@ -379,9 +382,9 @@ coverage: ## generate coverprofiles from the unit tests, except tests that requi
379382
380383root-coverage : # # generate coverage profiles for unit tests that require root
381384 @echo " $( WHALE) $@ "
382- @go test -i ${TESTFLAGS} ${TEST_REQUIRES_ROOT_PACKAGES} 2> /dev/null
385+ @$( GO ) test -i ${TESTFLAGS} ${TEST_REQUIRES_ROOT_PACKAGES} 2> /dev/null
383386 @ ( for pkg in ${TEST_REQUIRES_ROOT_PACKAGES} ; do \
384- go test ${TESTFLAGS} \
387+ $( GO ) test ${TESTFLAGS} \
385388 -cover \
386389 -coverprofile=profile.out \
387390 -covermode=atomic $$ pkg -test.root || exit ; \
@@ -393,8 +396,8 @@ root-coverage: ## generate coverage profiles for unit tests that require root
393396
394397vendor : # # vendor
395398 @echo " $( WHALE) $@ "
396- @go mod tidy
397- @go mod vendor
399+ @$( GO ) mod tidy
400+ @$( GO ) mod vendor
398401
399402help : # # this help
400403 @awk ' BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST ) | sort
0 commit comments