Skip to content

Commit ad11587

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`, adds a GNU debug link to the stripped binary, and strips the release binary. `make binary SEPARATE_DEBUG_SYMBOLS=1` passes `--debug-symbols` to `./configure`, strips the packaged `bin/nsolid`, adds a GNU debug link to it, 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 ad11587

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Makefile

Lines changed: 30 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,26 @@ 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+
endef
101+
102+
define add_debuglink
103+
$(OBJCOPY) --add-gnu-debuglink=$(2) $(1)
104+
endef
90105

91106
# Flags for packaging.
92107
BUILD_DOWNLOAD_FLAGS ?= --download=all
93108
BUILD_INTL_FLAGS ?= --with-intl=full-icu
94109
BUILD_RELEASE_FLAGS ?= $(BUILD_DOWNLOAD_FLAGS) $(BUILD_INTL_FLAGS)
110+
ifeq ($(SEPARATE_DEBUG_SYMBOLS),1)
111+
BUILD_RELEASE_FLAGS += --debug-symbols
112+
endif
95113

96114
# Default to quiet/pretty builds.
97115
# To do verbose builds, run `make V=1` or set the V environment variable.
@@ -630,6 +648,14 @@ build-ci: ## Build everything (CI).
630648
$(PYTHON) ./configure --verbose $(CONFIG_FLAGS)
631649
$(MAKE)
632650

651+
.PHONY: release-debug-artifacts
652+
release-debug-artifacts: ## Build Release with -g, save debug symbols, and strip the shipped binary.
653+
$(PYTHON) ./configure --verbose $(CONFIG_FLAGS) --debug-symbols
654+
$(RM) -r out/Release
655+
$(MAKE) $(NODE_EXE)
656+
$(call split_debug_symbols,$(RELEASE_NODE),$(RELEASE_DEBUG_SYMBOLS))
657+
$(call add_debuglink,$(RELEASE_NODE),$(RELEASE_DEBUG_SYMBOLS))
658+
633659
.PHONY: run-ci
634660
# Run by CI tests, exceptions:
635661
# - node-test-commit-arm-fanned (Raspberry Pis), where the binaries are
@@ -1325,6 +1351,10 @@ $(BINARYTAR): release-only
13251351
--release-urlbase=$(RELEASE_URLBASE) \
13261352
$(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
13271353
$(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
1354+
ifeq ($(SEPARATE_DEBUG_SYMBOLS),1)
1355+
$(call split_debug_symbols,$(BINARYNAME)/bin/$(NODE_EXE),$(BINARY_DEBUG_SYMBOLS))
1356+
$(call add_debuglink,$(BINARYNAME)/bin/$(NODE_EXE),$(BINARY_DEBUG_SYMBOLS))
1357+
endif
13281358
cp README.md $(BINARYNAME)
13291359
cp LICENSE $(BINARYNAME)
13301360
cp LICENSE_NSOLID $(BINARYNAME)

0 commit comments

Comments
 (0)