@@ 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: