From ec9fd0fafce5e159173c8eaa1f1c3efac440d7df Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 7 Oct 2024 13:50:33 -0600 Subject: [PATCH] Create the `build-debug` make target. (#2172) * [2062]: Add chanelog entry. * [2062]: Create the build-debug make target. --- .../improvements/2062-build-debug.md | 1 + Makefile | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 .changelog/unreleased/improvements/2062-build-debug.md diff --git a/.changelog/unreleased/improvements/2062-build-debug.md b/.changelog/unreleased/improvements/2062-build-debug.md new file mode 100644 index 000000000..f2440a1d2 --- /dev/null +++ b/.changelog/unreleased/improvements/2062-build-debug.md @@ -0,0 +1 @@ +* Create the `build-debug` make target for building a provenanced binary that allows debugging [#2062](https://github.com/provenance-io/provenance/issues/2062). diff --git a/Makefile b/Makefile index e77c4948e..449bdf55f 100644 --- a/Makefile +++ b/Makefile @@ -112,22 +112,31 @@ whitespace += $(whitespace) comma := , build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) -ldflags = -w -s \ - -X github.com/cosmos/cosmos-sdk/version.Name=Provenance \ +base_ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=Provenance \ -X github.com/cosmos/cosmos-sdk/version.AppName=provenanced \ - -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \ -X github.com/cometbft/cometbft/version.TMCoreSemVer=$(CMTVERSION) +base_ldflags += $(LDFLAGS) +ver_var = github.com/cosmos/cosmos-sdk/version.Version -ldflags += $(LDFLAGS) +ldflags = -w -s $(base_ldflags) -X $(ver_var)=$(VERSION) ldflags := $(strip $(ldflags)) -build_flags = -mod=readonly -tags "$(build_tags)" -ldflags '$(ldflags)' -trimpath -build_flags += $(BUILD_FLAGS) +ldflags_debug = $(base_ldflags) -X $(ver_var)=$(VERSION)-debug +ldflags_debug := $(strip $(ldflags_debug)) + +base_build_flags := -mod=readonly -tags "$(build_tags)" $(BUILD_FLAGS) + +build_flags = $(base_build_flags) -trimpath -ldflags '$(ldflags)' build_flags := $(strip $(build_flags)) BUILD_FLAGS := $(build_flags) +GCFLAGS ?= all=-N -l +build_debug_flags = $(base_build_flags) -gcflags '$(GCFLAGS)' -ldflags '$(ldflags_debug)' +build_debug_flags := $(strip $(build_debug_flags)) +BUILD_DEBUG_FLAGS := $(build_debug_flags) + all: build format lint test .PHONY: all @@ -145,6 +154,10 @@ build: validate-go-version go.sum mkdir -p $(BUILDDIR) CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -o $(BUILDDIR)/ $(BUILD_FLAGS) ./cmd/provenanced +build-debug: validate-go-version go.sum + mkdir -p $(BUILDDIR) + CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -o $(BUILDDIR)/ $(BUILD_DEBUG_FLAGS) ./cmd/provenanced + build-linux: go.sum WITH_LEDGER=false GOOS=linux GOARCH=amd64 $(MAKE) build @@ -173,7 +186,7 @@ else $(BUILDDIR)/provenanced -t --home $(BUILDDIR)/run/provenanced start --custom-denom $(DENOM) endif -.PHONY: install build build-linux run +.PHONY: install build build-debug build-linux run ############################## # Release artifacts and plan #