Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass DBG=1 to make to build for debug #607

Merged
merged 1 commit into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ VERSION ?= $(shell git describe --tags --always --dirty)
# This version-strategy uses a manual value to set the version string
#VERSION ?= 1.2.3

# Set this to 1 to build a debugger-friendly binary.
DBG ?=

# These are passed to docker when building and testing.
HTTP_PROXY ?=
HTTPS_PROXY ?=
Expand Down Expand Up @@ -129,6 +132,7 @@ $(OUTBIN): .go/$(OUTBIN).stamp
ARCH=$(ARCH) \
OS=$(OS) \
VERSION=$(VERSION) \
BUILD_DEBUG=$(DBG) \
./build/build.sh \
"
if ! cmp -s .go/$(OUTBIN) $(OUTBIN); then \
Expand Down
18 changes: 16 additions & 2 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,23 @@ fi
export CGO_ENABLED=0
export GOARCH="${ARCH}"
export GOOS="${OS}"
export GOFLAGS="-mod=vendor"

if [[ "${BUILD_DEBUG:-}" == 1 ]]; then
# Debugging - disable optimizations and inlining
gogcflags="all=-N -l"
goasmflags=""
goldflags=""
else
# Not debugging - trim paths, disable symbols and DWARF.
goasmflags="all=-trimpath=$(pwd)"
gogcflags="all=-trimpath=$(pwd)"
goldflags="-s -w"
fi

always_ldflags="-X $(go list -m)/pkg/version.VERSION=${VERSION}"
go install \
-installsuffix "static" \
-ldflags "-X $(go list -m)/pkg/version.VERSION=${VERSION}" \
-gcflags="${gogcflags}" \
-asmflags="${goasmflags}" \
-ldflags="${always_ldflags} ${goldflags}" \
./...