@@ -23,14 +23,21 @@ LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)
2323
2424GOARCH := $(shell $(GO ) env GOARCH)
2525
26+ # -trimpath may be required on some platforms to create reproducible builds
27+ # on the other hand, it does strip out build information, like -ldflags, which
28+ # some tools use to infer the version, in the absence of go information,
29+ # which happens when you use `go build`.
30+ # This enables someone to override by doing `make runc TRIMPATH= ` etc.
31+ TRIMPATH := -trimpath
32+
2633GO_BUILDMODE :=
2734# Enable dynamic PIE executables on supported platforms.
2835ifneq (,$(filter $(GOARCH ) ,386 amd64 arm arm64 ppc64le riscv64 s390x) )
2936 ifeq (,$(findstring -race,$(EXTRA_FLAGS)))
3037 GO_BUILDMODE := "-buildmode=pie"
3138 endif
3239endif
33- GO_BUILD := $(GO ) build -trimpath $(GO_BUILDMODE ) \
40+ GO_BUILD := $(GO ) build $( TRIMPATH ) $(GO_BUILDMODE ) \
3441 $(EXTRA_FLAGS ) -tags "$(BUILDTAGS ) " \
3542 -ldflags "$(LDFLAGS_COMMON ) $(EXTRA_LDFLAGS ) "
3643
@@ -46,7 +53,7 @@ ifneq (,$(filter $(GOARCH),arm64 amd64))
4653 endif
4754endif
4855# Enable static PIE binaries on supported platforms.
49- GO_BUILD_STATIC := $(GO ) build -trimpath $(GO_BUILDMODE_STATIC ) \
56+ GO_BUILD_STATIC := $(GO ) build $( TRIMPATH ) $(GO_BUILDMODE_STATIC ) \
5057 $(EXTRA_FLAGS ) -tags "$(BUILDTAGS ) netgo osusergo" \
5158 -ldflags "$(LDFLAGS_COMMON ) $(LDFLAGS_STATIC ) $(EXTRA_LDFLAGS ) "
5259
0 commit comments