From 4fd0290e0e0e585f302b9c2a3b2323020e0af4c7 Mon Sep 17 00:00:00 2001 From: Abhisek Banerjee Date: Fri, 16 Oct 2020 17:01:42 +0000 Subject: [PATCH] Add go ldflags using LDFLAGS at the time of compilation --- release-tools/build.make | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release-tools/build.make b/release-tools/build.make index c17a1c194..64f688727 100644 --- a/release-tools/build.make +++ b/release-tools/build.make @@ -69,12 +69,15 @@ endif # toolchain. BUILD_PLATFORMS = +# Add go ldflags using LDFLAGS at the time of compilation. +LDFLAGS = + # This builds each command (= the sub-directories of ./cmd) for the target platform(s) # defined by BUILD_PLATFORMS. $(CMDS:%=build-%): build-%: check-go-version-go mkdir -p bin echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix; do \ - if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '-X main.version=$(REV) -extldflags "-static"' -o "./bin/$*$$suffix" ./cmd/$*); then \ + if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '$(LDFLAGS) -X main.version=$(REV) -extldflags "-static"' -o "./bin/$*$$suffix" ./cmd/$*); then \ echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \ exit 1; \ fi; \