Skip to content

Commit 5abeeff

Browse files
Merge pull request #2647 from teawater/gdb
Add build option "GODEBUG=1"
2 parents f35c352 + c5a0c7f commit 5abeeff

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

Makefile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ else
5050
endif
5151
endif
5252

53+
ifndef GODEBUG
54+
EXTRA_LDFLAGS += -s -w
55+
DEBUG_GO_GCFLAGS :=
56+
DEBUG_TAGS :=
57+
else
58+
DEBUG_GO_GCFLAGS := -gcflags=all="-N -l"
59+
DEBUG_TAGS := static_build
60+
endif
61+
5362
WHALE = "🇩"
5463
ONI = "👹"
5564

@@ -74,11 +83,15 @@ TEST_REQUIRES_ROOT_PACKAGES=$(filter \
7483
COMMANDS=ctr containerd containerd-stress
7584
MANPAGES=ctr.1 containerd.1 containerd-config.1 containerd-config.toml.5
7685

86+
ifdef BUILDTAGS
87+
GO_BUILDTAGS = ${BUILDTAGS}
88+
endif
7789
# Build tags seccomp and apparmor are needed by CRI plugin.
78-
BUILDTAGS ?= seccomp apparmor
79-
GO_TAGS=$(if $(BUILDTAGS),-tags "$(BUILDTAGS)",)
80-
GO_LDFLAGS=-ldflags '-s -w -X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) $(EXTRA_LDFLAGS)'
81-
SHIM_GO_LDFLAGS=-ldflags '-s -w -X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) -extldflags "-static"'
90+
GO_BUILDTAGS ?= seccomp apparmor
91+
GO_BUILDTAGS += ${DEBUG_TAGS}
92+
GO_TAGS=$(if $(GO_BUILDTAGS),-tags "$(GO_BUILDTAGS)",)
93+
GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) $(EXTRA_LDFLAGS)'
94+
SHIM_GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) -extldflags "-static" $(EXTRA_LDFLAGS)'
8295

8396
#Replaces ":" (*nix), ";" (windows) with newline for easy parsing
8497
GOPATHS=$(shell echo ${GOPATH} | tr ":" "\n" | tr ";" "\n")
@@ -143,7 +156,7 @@ proto-fmt: ## check format of proto files
143156

144157
build: ## build the go packages
145158
@echo "$(WHALE) $@"
146-
@go build ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES}
159+
@go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES}
147160

148161
test: ## run tests, except integration tests and tests that require root
149162
@echo "$(WHALE) $@"
@@ -166,7 +179,7 @@ FORCE:
166179
# Build a binary from a cmd.
167180
bin/%: cmd/% FORCE
168181
@echo "$(WHALE) $@${BINARY_SUFFIX}"
169-
@go build ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS} ./$<
182+
@go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS} ./$<
170183

171184
bin/containerd-shim: cmd/containerd-shim FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220
172185
@echo "$(WHALE) bin/containerd-shim"

0 commit comments

Comments
 (0)