Skip to content

Commit 22c0395

Browse files
authored
Merge pull request #108 from bnrjee/master
Add go ldflags using LDFLAGS at the time of compilation
2 parents 16f4afb + b5b447b commit 22c0395

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: build.make

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,17 @@ endif
6969
# toolchain.
7070
BUILD_PLATFORMS =
7171

72+
# Add go ldflags using LDFLAGS at the time of compilation.
73+
IMPORTPATH_LDFLAGS = -X main.version=$(REV)
74+
EXT_LDFLAGS = -extldflags "-static"
75+
LDFLAGS =
76+
FULL_LDFLAGS = $(LDFLAGS) $(IMPORTPATH_LDFLAGS) $(EXT_LDFLAGS)
7277
# This builds each command (= the sub-directories of ./cmd) for the target platform(s)
7378
# defined by BUILD_PLATFORMS.
7479
$(CMDS:%=build-%): build-%: check-go-version-go
7580
mkdir -p bin
7681
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix; do \
77-
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 \
82+
if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*$$suffix" ./cmd/$*); then \
7883
echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
7984
exit 1; \
8085
fi; \

0 commit comments

Comments
 (0)