~nesv/govern

00a2cc9c6d9c4baa1498d742c61ba34a3e9a8609 — Nick Saika 1 year, 1 month ago 0c30633 master
Shrink binaries

Since govern has the possibility of shipping a lot of binaries, it would
be prudent to shrink them down as much as possible.

To accomplish this, there are two sets of changes to the Makefile:

- Pass `-ldflags="-s -w"` to go build, which will strip debugging
  symbols;
- If present on the host, use upx(1) to shrink the binaries even further.

upx(1) is kind of a neat tool. It works by compressing a binary, and
having it unpack itself at execution time, then using a JMP instruction
to jump to the extracted binary.
1 files changed, 27 insertions(+), 7 deletions(-)

M Makefile
M Makefile => Makefile +27 -7
@@ 14,30 14,50 @@ SOURCES	:= $(wildcard internal/agent/*.go) \
	$(wildcard internal/runner/*.go) \
	$(wildcard internal/server/*.go) \
	$(wildcard internal/state/*.go)
UPX		:= $(shell command -v upx)
ifneq (${UPX},)
	UPX += -9 -qq
endif

GC_FLAGS	?=
ifneq (${TAGS},"")
	GC_FLAGS += -tags="${TAGS}"
endif

GO_BUILD	:= go build ${GC_FLAGS}
GO_LDFLAGS		:= -s -w
GO_BUILDFLAGS	:= ${GC_FLAGS} -ldflags="${GO_LDFLAGS}"
GO_BUILD		:= go build

all: ${TARGETS}

${DESTDIR}/bin/${NAME}: $(wildcard *.go) ${SOURCES}
	${GO_BUILD} -o $@
	${GO_BUILD} -o $@ ${GO_BUILDFLAGS}
ifneq (${UPX},)
	${UPX} $@
endif

${DESTDIR}/libexec/${NAME}/runner/%: $(wildcard runners/%/*.go) $(wildcard runner/*.go)
	${GO_BUILD} -o $@ ${PACKAGE}/runners/$*
	${GO_BUILD} -o $@ ${GO_BUILDFLAGS} ${PACKAGE}/runners/$*
ifneq (${UPX},)
	${UPX} $@
endif

${DESTDIR}/libexec/${NAME}/runner/pkg: $(wildcard runners/pkg/*.go) $(wildcard runner/*.go)
	${GO_BUILD} -o $@ ${PACKAGE}/runners/pkg
	${GO_BUILD} -o $@ ${GO_BUILDFLAGS} ${PACKAGE}/runners/pkg
ifneq (${UPX},)
	${UPX} $@
endif

${DESTDIR}/libexec/${NAME}/runner/file: $(wildcard runners/file/*.go) $(wildcard runner/*.go)
	${GO_BUILD} -o $@ ${PACKAGE}/runners/file
	${GO_BUILD} -o $@ ${GO_BUILDFLAGS} ${PACKAGE}/runners/file
ifneq (${UPX},)
	${UPX} $@
endif

${DESTDIR}/libexec/${NAME}/runner/service: $(wildcard runners/service/*.go) $(wildcard runner/*.go)
	${GO_BUILD} -o $@ ${PACKAGE}/runners/file
	${GO_BUILD} -o $@ ${GO_BUILDFLAGS} ${PACKAGE}/runners/file
ifneq (${UPX},)
	${UPX} $@
endif

.PHONY: clean
clean: