makefile: apply version, compress artefacts, trim gopath from release binaries

This commit is contained in:
mappu 2017-03-25 16:28:39 +13:00
parent a36a293dfa
commit 5667bd6cbb

View File

@ -1,24 +1,39 @@
.PHONY: all clean
OBJS := $(addprefix webcmd.,linux64 linux32 win64 win32)
VERSION := 1.0.0
OBJS := webcmd-$(VERSION)-linux64.tar.xz \
webcmd-$(VERSION)-linux32.tar.xz \
webcmd-$(VERSION)-win64.zip \
webcmd-$(VERSION)-win32.zip
XZ_OPTS=-9
all: $(OBJS)
define compile
/bin/bash -c 'GOARCH=$(1) GOOS=$(2) go build -o ./webcmd.$(3) -ldflags "-s -w" ./cmd/webcmd'
define compilelinux
/bin/bash -c 'GOARCH=$(1) GOOS=linux go build -a -o ./webcmd -ldflags "-s -w -X code.ivysaur.me/webcmd.APP_VERSION=$(VERSION)" -gcflags "-trimpath=$(GOPATH)" ./cmd/webcmd'
tar caf webcmd-$(2)-$(VERSION).tar.xz webcmd -C cmd/webcmd webcmd.conf-sample --owner=0 --group=0
rm webcmd
endef
webcmd.linux64:
$(call compile,amd64,linux,linux64)
define compilewin
/bin/bash -c 'GOARCH=$(1) GOOS=windows go build -a -o ./webcmd -ldflags "-s -w -X code.ivysaur.me/webcmd.APP_VERSION=$(VERSION)" -gcflags "-trimpath=$(GOPATH)" ./cmd/webcmd'
zip -j webcmd-$(2)-$(VERSION).zip webcmd cmd/webcmd/webcmd.conf-sample
rm webcmd
endef
webcmd.linux32:
$(call compile,386,linux,linux32)
webcmd-$(VERSION)-linux64.tar.xz:
$(call compilelinux,amd64,linux64)
webcmd-$(VERSION)-linux32.tar.xz:
$(call compilelinux,386,linux32)
webcmd.win64:
$(call compile,amd64,windows,win64)
webcmd-$(VERSION)-win64.zip:
$(call compilewin,amd64,win64)
webcmd.win32:
$(call compile,386,windows,win32)
webcmd-$(VERSION)-win32.zip:
$(call compilewin,386,win32)
clean:
rm $(OBJS)
rm $(OBJS)