Skip to content

Commit 1791b7c

Browse files
committed
build: add split-debug release and package targets
Add Makefile support for generating separate debug symbol artifacts from release builds while keeping distributed binaries stripped. `make release-debug-artifacts` builds `out/Release/nsolid`, writes `out/Release/nsolid.debug`, strips the release binary, and adds a debug link back to it. `make binary SEPARATE_DEBUG_SYMBOLS=1` passes `--debug-symbols` to `./configure`, strips the packaged `bin/nsolid`, and writes a separate `$(BINARYNAME).debug` artifact for upload to debuginfod. `make binary` keeps the previous behavior and does not generate a separate debug symbol artifact. Signed-off-by: Santiago Gimeno <santiago.gimeno@gmail.com>
1 parent 447b0e5 commit 1791b7c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ GCOV ?= gcov
2222
PWD = $(CURDIR)
2323
BUILD_WITH ?= make
2424
FIND ?= find
25+
OBJCOPY ?= objcopy
26+
STRIP ?= strip
27+
SEPARATE_DEBUG_SYMBOLS ?= 0
2528

2629
ifdef JOBS
2730
PARALLEL_ARGS = -j $(JOBS)
@@ -87,11 +90,23 @@ NODE ?= $(PWD)/$(NODE_EXE)
8790
# when generating coverage reports or running toolings as
8891
# debug build is be slower.
8992
OUT_NODE ?= $(PWD)/out/$(BUILDTYPE)/node$(EXEEXT)
93+
RELEASE_NODE ?= $(PWD)/out/Release/$(NODE_EXE)
94+
RELEASE_DEBUG_SYMBOLS ?= $(RELEASE_NODE).debug
95+
BINARY_DEBUG_SYMBOLS ?= $(BINARYNAME).debug
96+
97+
define split_debug_symbols
98+
$(OBJCOPY) --only-keep-debug $(1) $(2)
99+
$(STRIP) --strip-debug --strip-unneeded $(1)
100+
$(OBJCOPY) --add-gnu-debuglink=$(notdir $(2)) $(1)
101+
endef
90102

91103
# Flags for packaging.
92104
BUILD_DOWNLOAD_FLAGS ?= --download=all
93105
BUILD_INTL_FLAGS ?= --with-intl=full-icu
94106
BUILD_RELEASE_FLAGS ?= $(BUILD_DOWNLOAD_FLAGS) $(BUILD_INTL_FLAGS)
107+
ifeq ($(SEPARATE_DEBUG_SYMBOLS),1)
108+
BUILD_RELEASE_FLAGS += --debug-symbols
109+
endif
95110

96111
# Default to quiet/pretty builds.
97112
# To do verbose builds, run `make V=1` or set the V environment variable.
@@ -630,6 +645,13 @@ build-ci: ## Build everything (CI).
630645
$(PYTHON) ./configure --verbose $(CONFIG_FLAGS)
631646
$(MAKE)
632647

648+
.PHONY: release-debug-artifacts
649+
release-debug-artifacts: ## Build Release with -g, save debug symbols, and strip the shipped binary.
650+
$(PYTHON) ./configure --verbose $(CONFIG_FLAGS) --debug-symbols
651+
$(RM) -r out/Release
652+
$(MAKE) $(NODE_EXE)
653+
$(call split_debug_symbols,$(RELEASE_NODE),$(RELEASE_DEBUG_SYMBOLS))
654+
633655
.PHONY: run-ci
634656
# Run by CI tests, exceptions:
635657
# - node-test-commit-arm-fanned (Raspberry Pis), where the binaries are
@@ -1325,6 +1347,9 @@ $(BINARYTAR): release-only
13251347
--release-urlbase=$(RELEASE_URLBASE) \
13261348
$(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
13271349
$(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
1350+
ifeq ($(SEPARATE_DEBUG_SYMBOLS),1)
1351+
$(call split_debug_symbols,$(BINARYNAME)/bin/$(NODE_EXE),$(BINARY_DEBUG_SYMBOLS))
1352+
endif
13281353
cp README.md $(BINARYNAME)
13291354
cp LICENSE $(BINARYNAME)
13301355
cp LICENSE_NSOLID $(BINARYNAME)

0 commit comments

Comments
 (0)