From 54a90df1b382337cb3d98be78ff35131663756f6 Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 11 Jul 2017 20:10:23 +1200 Subject: [PATCH] makefile: support release builds and dist artefacts --- Makefile | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b3bca74..bdce0fe 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,73 @@ - -.PHONY: all clean +# +# Makefile for YATWiki3 +# -all: staticResources.go +VERSION:=3.0 + +SOURCES:=Makefile \ + static \ + cmd $(wildcard cmd/yatwiki-server/*.go) \ + $(wildcard *.go) + +GOFLAGS := -ldflags='-s -w' -gcflags='-trimpath=$(GOPATH)' -asmflags='-trimpath=$(GOPATH)' + +# +# Phony targets +# + +.PHONY: all dist clean + +all: build/linux64/yatwiki-server build/win32/yatwiki-server.exe + +dist: \ + _dist/yatwiki-$(VERSION)-linux64.tar.gz \ + _dist/yatwiki-$(VERSION)-win32.7z \ + _dist/yatwiki-$(VERSION)-src.zip clean: - rm staticResources.go + if [ -f ./staticResources.go ] ; then rm ./staticResources.go ; fi + if [ -d ./build ] ; then rm -r ./build ; fi + if [ -f ./yatwiki ] ; then rm ./yatwiki ; fi + +# +# Generated files +# staticResources.go: static/ static/* go-bindata -o staticResources.go -prefix static -pkg yatwiki3 static + + +# +# Release artefacts +# + +build/linux64/yatwiki-server: $(SOURCES) staticResources.go + mkdir -p build/linux64 + (cd cmd/yatwiki-server ; \ + CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \ + go build $(GOFLAGS) -o ../../build/linux64/yatwiki-server \ + ) + +build/win32/yatwiki-server.exe: $(SOURCES) staticResources.go + mkdir -p build/win32 + (cd cmd/yatwiki-server ; \ + PATH=/usr/lib/mxe/usr/bin:$(PATH) CC=i686-w64-mingw32.static-gcc \ + CGO_ENABLED=1 GOOS=windows GOARCH=386 \ + go build $(GOFLAGS) -o ../../build/win32/yatwiki-server.exe \ + ) + +_dist/yatwiki-$(VERSION)-linux64.tar.gz: build/linux64/yatwiki-server + mkdir -p _dist + tar caf _dist/yatwiki-$(VERSION)-linux64.tar.gz -C build/linux64 yatwiki-server --owner=0 --group=0 + +_dist/yatwiki-$(VERSION)-win32.7z: build/win32/yatwiki-server.exe + mkdir -p _dist + ( cd build/win32 ; \ + if [ -f dist.7z ] ; then rm dist.7z ; fi ; \ + 7z a dist.7z yatwiki-server.exe ; \ + mv dist.7z ../../_dist/yatwiki-$(VERSION)-win32.7z \ + ) + +_dist/yatwiki-$(VERSION)-src.zip: $(SOURCES) + git archive --format=zip HEAD > _dist/yatwiki-$(VERSION)-src.zip +