From 664ef74fb9dccd857f1e1a3eba1a150b9763264b Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 18 Apr 2023 19:34:34 +0200 Subject: [PATCH 1/4] Allow setting custom version but use git by default Makefile: Allow using `VERSION` to provide a version override when building the project. This allows for building using a tarball, without requiring git. --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1b4bed6e0a..f667b7bd19 100644 --- a/Makefile +++ b/Makefile @@ -33,8 +33,7 @@ endif PROJECT := github.com/kubernetes-sigs/cri-tools BINDIR ?= /usr/local/bin -VERSION := $(shell git describe --tags --dirty --always) -VERSION := $(VERSION:v%=%) +VERSION ?= $(shell git describe --tags --dirty --always | sed 's/^v//') GO_LDFLAGS := -X $(PROJECT)/pkg/version.Version=$(VERSION) BUILD_PATH := $(shell pwd)/build From e64d6e378f8fd5edec5528b3c840cb23c9526cec Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 18 Apr 2023 19:40:21 +0200 Subject: [PATCH 2/4] Allow providing (additional) custom GO_LDFLAGS Makefile: Allow providing `GO_LDFLAGS` externally (e.g. via export of the variable in the build environment), which is what downstream distributions use to build with their linker flags (e.g. for external link mode and/or debug packages). This prepends externally provided `GO_LDFLAGS` to the version declaration. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f667b7bd19..8dc4ecd3f4 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ PROJECT := github.com/kubernetes-sigs/cri-tools BINDIR ?= /usr/local/bin VERSION ?= $(shell git describe --tags --dirty --always | sed 's/^v//') -GO_LDFLAGS := -X $(PROJECT)/pkg/version.Version=$(VERSION) +GO_LDFLAGS := $(GO_LDFLAGS) -X $(PROJECT)/pkg/version.Version=$(VERSION) BUILD_PATH := $(shell pwd)/build BUILD_BIN_PATH := $(BUILD_PATH)/bin/$(GOOS)/$(GOARCH) From 464d645290c1c434291daf624c6b70afc25484e1 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 18 Apr 2023 19:49:44 +0200 Subject: [PATCH 3/4] Allow overriding GOFLAGS Makefile: Allow providing `GOFLAGS` in the build environment to set go compiler flags and set the default to `-trimpath`. This is required for downstream distributions to be able to build position independent executables and working debug symbols. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 8dc4ecd3f4..e36e4470b7 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ PROJECT := github.com/kubernetes-sigs/cri-tools BINDIR ?= /usr/local/bin VERSION ?= $(shell git describe --tags --dirty --always | sed 's/^v//') +GOFLAGS ?= -trimpath GO_LDFLAGS := $(GO_LDFLAGS) -X $(PROJECT)/pkg/version.Version=$(VERSION) BUILD_PATH := $(shell pwd)/build @@ -65,7 +66,7 @@ critest: $(CRITEST): CGO_ENABLED=0 $(GO_TEST) -c -o $@ \ -ldflags '$(GO_LDFLAGS)' \ - -trimpath \ + $(GOFLAGS) \ $(PROJECT)/cmd/critest crictl: @@ -74,7 +75,7 @@ crictl: $(CRICTL): CGO_ENABLED=0 $(GO_BUILD) -o $@ \ -ldflags '$(GO_LDFLAGS)' \ - -trimpath \ + $(GOFLAGS) \ $(PROJECT)/cmd/crictl clean: From ae7a5eb76780448c19be9d21fd138ddddb37de92 Mon Sep 17 00:00:00 2001 From: David Runge Date: Tue, 18 Apr 2023 20:08:24 +0200 Subject: [PATCH 4/4] Allow setting CGO_ENABLED Makefile: Allow setting CGO_ENABLED (defaults to 0). --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e36e4470b7..1210d1f185 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ PROJECT := github.com/kubernetes-sigs/cri-tools BINDIR ?= /usr/local/bin VERSION ?= $(shell git describe --tags --dirty --always | sed 's/^v//') +CGO_ENABLED ?= 0 GOFLAGS ?= -trimpath GO_LDFLAGS := $(GO_LDFLAGS) -X $(PROJECT)/pkg/version.Version=$(VERSION) @@ -64,7 +65,7 @@ critest: @$(MAKE) -B $(CRITEST) $(CRITEST): - CGO_ENABLED=0 $(GO_TEST) -c -o $@ \ + CGO_ENABLED=$(CGO_ENABLED) $(GO_TEST) -c -o $@ \ -ldflags '$(GO_LDFLAGS)' \ $(GOFLAGS) \ $(PROJECT)/cmd/critest @@ -73,7 +74,7 @@ crictl: @$(MAKE) -B $(CRICTL) $(CRICTL): - CGO_ENABLED=0 $(GO_BUILD) -o $@ \ + CGO_ENABLED=$(CGO_ENABLED) $(GO_BUILD) -o $@ \ -ldflags '$(GO_LDFLAGS)' \ $(GOFLAGS) \ $(PROJECT)/cmd/crictl