Add build option "GODEBUG=1"
Make will generate GDB friendly binary with this build option. Signed-off-by: Hui Zhu <teawater@hyper.sh>
This commit is contained in:
		
							
								
								
									
										25
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								Makefile
									
									
									
									
									
								
							| @@ -50,6 +50,15 @@ else | |||||||
| 	endif | 	endif | ||||||
| endif | endif | ||||||
|  |  | ||||||
|  | ifndef GODEBUG | ||||||
|  | 	EXTRA_LDFLAGS += -s -w | ||||||
|  | 	DEBUG_GO_GCFLAGS := | ||||||
|  | 	DEBUG_TAGS := | ||||||
|  | else | ||||||
|  | 	DEBUG_GO_GCFLAGS := -gcflags=all="-N -l" | ||||||
|  | 	DEBUG_TAGS := static_build | ||||||
|  | endif | ||||||
|  |  | ||||||
| WHALE = "🇩" | WHALE = "🇩" | ||||||
| ONI = "👹" | ONI = "👹" | ||||||
|  |  | ||||||
| @@ -74,11 +83,15 @@ TEST_REQUIRES_ROOT_PACKAGES=$(filter \ | |||||||
| COMMANDS=ctr containerd containerd-stress containerd-release | COMMANDS=ctr containerd containerd-stress containerd-release | ||||||
| MANPAGES=ctr.1 containerd.1 containerd-config.1 containerd-config.toml.5 | MANPAGES=ctr.1 containerd.1 containerd-config.1 containerd-config.toml.5 | ||||||
|  |  | ||||||
|  | ifdef BUILDTAGS | ||||||
|  |     GO_BUILDTAGS = ${BUILDTAGS} | ||||||
|  | endif | ||||||
| # Build tags seccomp and apparmor are needed by CRI plugin. | # Build tags seccomp and apparmor are needed by CRI plugin. | ||||||
| BUILDTAGS ?= seccomp apparmor | GO_BUILDTAGS ?= seccomp apparmor | ||||||
| GO_TAGS=$(if $(BUILDTAGS),-tags "$(BUILDTAGS)",) | GO_BUILDTAGS += ${DEBUG_TAGS} | ||||||
| GO_LDFLAGS=-ldflags '-s -w -X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) $(EXTRA_LDFLAGS)' | GO_TAGS=$(if $(GO_BUILDTAGS),-tags "$(GO_BUILDTAGS)",) | ||||||
| SHIM_GO_LDFLAGS=-ldflags '-s -w -X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) -extldflags "-static"' | GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) $(EXTRA_LDFLAGS)' | ||||||
|  | SHIM_GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PKG) -extldflags "-static" $(EXTRA_LDFLAGS)' | ||||||
|  |  | ||||||
| #Replaces ":" (*nix), ";" (windows) with newline for easy parsing | #Replaces ":" (*nix), ";" (windows) with newline for easy parsing | ||||||
| GOPATHS=$(shell echo ${GOPATH} | tr ":" "\n" | tr ";" "\n") | GOPATHS=$(shell echo ${GOPATH} | tr ":" "\n" | tr ";" "\n") | ||||||
| @@ -143,7 +156,7 @@ proto-fmt: ## check format of proto files | |||||||
|  |  | ||||||
| build: ## build the go packages | build: ## build the go packages | ||||||
| 	@echo "$(WHALE) $@" | 	@echo "$(WHALE) $@" | ||||||
| 	@go build ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES} | 	@go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} ${EXTRA_FLAGS} ${GO_LDFLAGS} ${PACKAGES} | ||||||
|  |  | ||||||
| test: ## run tests, except integration tests and tests that require root | test: ## run tests, except integration tests and tests that require root | ||||||
| 	@echo "$(WHALE) $@" | 	@echo "$(WHALE) $@" | ||||||
| @@ -166,7 +179,7 @@ FORCE: | |||||||
| # Build a binary from a cmd. | # Build a binary from a cmd. | ||||||
| bin/%: cmd/% FORCE | bin/%: cmd/% FORCE | ||||||
| 	@echo "$(WHALE) $@${BINARY_SUFFIX}" | 	@echo "$(WHALE) $@${BINARY_SUFFIX}" | ||||||
| 	@go build ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS}  ./$< | 	@go build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@${BINARY_SUFFIX} ${GO_LDFLAGS} ${GO_TAGS}  ./$< | ||||||
|  |  | ||||||
| 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 | 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 | ||||||
| 	@echo "$(WHALE) bin/containerd-shim" | 	@echo "$(WHALE) bin/containerd-shim" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Hui Zhu
					Hui Zhu