Skip to content

Commit 1a77edc

Browse files
dssengGusted
authored andcommitted
chore: add a make option to disable stripping binaries for debug builds (go-gitea#6965)
Stripped binaries without symbols cannot be debugged and some developers might want to use a debugger. Make it configurable by STRIP make parameter. Signed-off-by: Dmitrii Sharshakov <[email protected]> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6965 Reviewed-by: Gusted <[email protected]> Co-authored-by: Dmitrii Sharshakov <[email protected]> Co-committed-by: Dmitrii Sharshakov <[email protected]>
1 parent bc31f06 commit 1a77edc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ FORGEJO_VERSION_API ?= ${FORGEJO_VERSION}
127127
show-version-api:
128128
@echo ${FORGEJO_VERSION_API}
129129

130+
# Strip binaries by default to reduce size, allow overriding for debugging
131+
STRIP ?= 1
132+
ifeq ($(STRIP),1)
133+
LDFLAGS := $(LDFLAGS) -s -w
134+
endif
130135
LDFLAGS := $(LDFLAGS) -X "main.ReleaseVersion=$(RELEASE_VERSION)" -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(FORGEJO_VERSION)" -X "main.Tags=$(TAGS)" -X "main.ForgejoVersion=$(FORGEJO_VERSION_API)"
131136

132137
LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
@@ -827,7 +832,7 @@ check: test
827832

828833
.PHONY: install $(TAGS_PREREQ)
829834
install: $(wildcard *.go)
830-
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
835+
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)'
831836

832837
.PHONY: build
833838
build: frontend backend
@@ -855,13 +860,13 @@ merge-locales:
855860
@echo "NOT NEEDED: THIS IS A NOOP AS OF Forgejo 7.0 BUT KEPT FOR BACKWARD COMPATIBILITY"
856861

857862
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
858-
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
863+
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@
859864

860865
forgejo: $(EXECUTABLE)
861866
ln -f $(EXECUTABLE) forgejo
862867

863868
static-executable: $(GO_SOURCES) $(TAGS_PREREQ)
864-
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags 'netgo osusergo $(TAGS)' -ldflags '-s -w -linkmode external -extldflags "-static" $(LDFLAGS)' -o $(EXECUTABLE)
869+
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -o $(EXECUTABLE)
865870

866871
.PHONY: release
867872
release: frontend generate release-linux release-copy release-compress vendor release-sources release-check

0 commit comments

Comments
 (0)