Skip to content

Commit 8fc5be4

Browse files
authored
Merge pull request #3908 from deitch/trimpath-optional
make trimpath optional
2 parents 7cce7e2 + 024c271 commit 8fc5be4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,21 @@ LDFLAGS_COMMON := -X main.gitCommit=$(COMMIT) -X main.version=$(VERSION)
2323

2424
GOARCH := $(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+
2633
GO_BUILDMODE :=
2734
# Enable dynamic PIE executables on supported platforms.
2835
ifneq (,$(filter $(GOARCH),386 amd64 arm arm64 ppc64le riscv64 s390x))
2936
ifeq (,$(findstring -race,$(EXTRA_FLAGS)))
3037
GO_BUILDMODE := "-buildmode=pie"
3138
endif
3239
endif
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
4754
endif
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

Comments
 (0)