aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-06-07 11:26:16 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-06-07 11:26:16 +0200
commit48ff51998e749dc1c8026e04948faad9d83cedd0 (patch)
treebe546c1f2393bc0bc57cdedbb8c001be7df86226
parent61cd1a97e20d58e77470610cb8ee0bd2d5b6d395 (diff)
Add windows and packaging build support.
-rw-r--r--.gitignore2
-rw-r--r--Makefile73
-rwxr-xr-xscripts/xds-utils/get-syncthing.sh31
3 files changed, 84 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore
index 500d93b..df22b67 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,7 @@ bin
tools
**/glide.lock
**/vendor
-
+package
debug
cmd/*/debug
diff --git a/Makefile b/Makefile
index 8b2df13..adc2995 100644
--- a/Makefile
+++ b/Makefile
@@ -12,9 +12,15 @@ SYNCTHING_INOTIFY_VERSION=master
# Retrieve git tag/commit to set sub-version string
ifeq ($(origin SUB_VERSION), undefined)
- SUB_VERSION := $(shell git describe --tags --always | sed 's/^v//')
- ifeq ($(SUB_VERSION), )
- SUB_VERSION=unknown-dev
+ SUB_VERSION := $(shell git describe --tags 2>/dev/null | sed 's/^v//')
+ ifneq ($(SUB_VERSION), )
+ VERSION := $(firstword $(subst -, ,$(SUB_VERSION)))
+ SUB_VERSION := $(word 2,$(subst -, ,$(SUB_VERSION)))
+ else
+ SUB_VERSION := $(shell git describe --tags --always | sed 's/^v//')
+ ifeq ($(SUB_VERSION), )
+ SUB_VERSION := unknown-dev
+ endif
endif
endif
@@ -28,13 +34,20 @@ endif
HOST_GOOS=$(shell go env GOOS)
HOST_GOARCH=$(shell go env GOARCH)
+ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
REPOPATH=github.com/iotbzh/xds-server
+EXT=
+ifeq ($(HOST_GOOS), windows)
+ EXT=.exe
+endif
+
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools
+PACKAGE_DIR := $(ROOT_SRCDIR)/package
export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
@@ -43,6 +56,22 @@ export PATH := $(PATH):$(LOCAL_TOOLSDIR)
VERBOSE_1 := -v
VERBOSE_2 := -v -x
+# Release or Debug mode
+ifeq ($(filter 1,$(RELEASE) $(REL)),)
+ GORELEASE=
+ BUILD_MODE="Debug mode"
+else
+ # optimized code without debug info
+ GORELEASE= -s -w
+ BUILD_MODE="Release mode"
+endif
+
+ifeq ($(SUB_VERSION), )
+ PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION).zip
+else
+ PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip
+endif
+
all: tools/syncthing build
@@ -51,7 +80,7 @@ build: xds webapp
xds:vendor scripts tools/syncthing/copytobin
@echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION))";
- @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-server -ldflags "-X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" .
+ @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-server$(EXT) -ldflags "$(GORELEASE) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" .
test: tools/glide
go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
@@ -63,14 +92,14 @@ fmt: tools/glide
go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
run: build/xds tools/syncthing/copytobin
- $(LOCAL_BINDIR)/xds-server --log info -c config.json.in
+ $(LOCAL_BINDIR)/xds-server$(EXT) --log info -c config.json.in
debug: build/xds webapp/debug tools/syncthing/copytobin
- $(LOCAL_BINDIR)/xds-server --log debug -c config.json.in
+ $(LOCAL_BINDIR)/xds-server$(EXT) --log debug -c config.json.in
.PHONY: clean
clean:
- rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH)
+ rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
.PHONY: distclean
distclean: clean
@@ -89,16 +118,36 @@ webapp/install:
scripts:
@mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/xds-server-st*.sh scripts/xds-utils $(LOCAL_BINDIR)
+.PHONY: conffile
+conffile:
+ cat config.json.in \
+ | sed -e s,"webapp/dist","$(INSTALL_WEBAPP_DIR)",g \
+ | sed -e s,"\./bin","",g \
+ > $(PACKAGE_DIR)/xds-server/config.json
+
.PHONY: install
install:
- @test -e $(LOCAL_BINDIR)/xds-server -a -d webapp/dist || { echo "Please execute first: make all\n"; exit 1; }
+ @test -e $(LOCAL_BINDIR)/xds-server$(EXT) -a -d webapp/dist || { echo "Please execute first: make all\n"; exit 1; }
@test -e $(LOCAL_BINDIR)/xds-server-start.sh -a -d $(LOCAL_BINDIR)/xds-utils || { echo "Please execute first: make all\n"; exit 1; }
- @test -e $(LOCAL_BINDIR)/syncthing -a -e $(LOCAL_BINDIR)/syncthing-inotify || { echo "Please execute first: make all\n"; exit 1; }
+ @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
mkdir -p $(INSTALL_DIR) \
&& cp -a $(LOCAL_BINDIR)/* $(INSTALL_DIR)
mkdir -p $(INSTALL_WEBAPP_DIR) \
&& cp -a webapp/dist/* $(INSTALL_WEBAPP_DIR)
+.PHONY: package
+package: clean
+ INSTALL_DIR=$(PACKAGE_DIR)/xds-server make -f $(ROOT_SRCDIR)/Makefile all install
+ INSTALL_DIR=$(PACKAGE_DIR)/xds-server INSTALL_WEBAPP_DIR=www-xds-server make -f $(ROOT_SRCDIR)/Makefile conffile
+ (cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
+
+.PHONY: package-all
+package-all:
+ @echo "# Build linux amd64..."
+ GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
+ @echo "# Build windows amd64..."
+ GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
+
vendor: tools/glide glide.yaml
$(LOCAL_TOOLSDIR)/glide install --strip-vendor
@@ -109,7 +158,7 @@ tools/glide:
.PHONY: tools/syncthing
tools/syncthing:
- @test -e $(LOCAL_TOOLSDIR)/syncthing -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify || { \
+ @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
mkdir -p $(LOCAL_TOOLSDIR); \
DESTDIR=$(LOCAL_TOOLSDIR) \
SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
@@ -118,8 +167,8 @@ tools/syncthing:
.PHONY:
tools/syncthing/copytobin:
- @test -e $(LOCAL_TOOLSDIR)/syncthing -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
- @cp -f $(LOCAL_TOOLSDIR)/syncthing* $(LOCAL_BINDIR)
+ @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
+ @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
.PHONY: help
help:
diff --git a/scripts/xds-utils/get-syncthing.sh b/scripts/xds-utils/get-syncthing.sh
index 54ca7e1..da06d15 100755
--- a/scripts/xds-utils/get-syncthing.sh
+++ b/scripts/xds-utils/get-syncthing.sh
@@ -8,6 +8,8 @@
[ -z "$SYNCTHING_INOTIFY_VERSION" ] && { SYNCTHING_INOTIFY_VERSION=master; SYNCTHING_INOTIFY_CMID=af6fbf9d63f95a0; }
[ -z "$DESTDIR" ] && DESTDIR=/usr/local/bin
[ -z "$TMPDIR" ] && TMPDIR=/tmp
+[ -z "$GOOS" ] && GOOS=$(go env GOOS)
+[ -z "$GOARCH" ] && GOARCH=$(go env GOARCH)
TEMPDIR=$TMPDIR/.get-st.$$
@@ -18,20 +20,28 @@ cleanExit ()
rm -rf ${TEMPDIR}
}
+TB_EXT="tar.gz"
+EXT=""
+[[ "$GOOS" = "windows" ]] && { TB_EXT="zip"; EXT=".exe"; }
+
echo "Get Syncthing..."
## Install Syncthing + Syncthing-inotify
## gpg: key 00654A3E: public key "Syncthing Release Management <release@syncthing.net>" imported
gpg -q --keyserver pool.sks-keyservers.net --recv-keys 37C84554E7E0A261E4F76E1ED26E6ED000654A3E || exit 1
-tarball="syncthing-linux-amd64-v${SYNCTHING_VERSION}.tar.gz" \
+tarball="syncthing-${GOOS}-${GOARCH}-v${SYNCTHING_VERSION}.${TB_EXT}" \
&& curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/${tarball}" -O \
&& curl -sfSL "https://github.com/syncthing/syncthing/releases/download/v${SYNCTHING_VERSION}/sha1sum.txt.asc" -O \
&& gpg -q --verify sha1sum.txt.asc \
&& grep -E " ${tarball}\$" sha1sum.txt.asc | sha1sum -c - \
- && rm sha1sum.txt.asc \
- && tar -xvf "$tarball" --strip-components=1 "$(basename "$tarball" .tar.gz)"/syncthing \
- && mv syncthing ${DESTDIR}/syncthing || exit 1
+ && rm sha1sum.txt.asc
+ if [ "${TB_EXT}" = "tar.gz" ]; then
+ tar -xvf "$tarball" --strip-components=1 "$(basename "$tarball" .tar.gz)"/syncthing \
+ && mv syncthing ${DESTDIR}/syncthing || exit 1
+ else
+ unzip "$tarball" && mv syncthing-windows-*/syncthing.exe ${DESTDIR}/syncthing.exe || exit 1
+ fi
echo "Get Syncthing-inotify..."
if [ "$SYNCTHING_INOTIFY_VERSION" = "master" ]; then
@@ -46,13 +56,16 @@ if [ "$SYNCTHING_INOTIFY_VERSION" = "master" ]; then
git status
export GOPATH=$(realpath `pwd`/../../../..)
version=$(git describe --tags --always | sed 's/^v//')__patch_165
- go build -v -i -ldflags "-w -X main.Version=$version" -o ${DESTDIR}/syncthing-inotify || exit 1
+ go build -v -i -ldflags "-w -X main.Version=$version" -o ${DESTDIR}/syncthing-inotify${EXT} || exit 1
else
-tarball="syncthing-inotify-linux-amd64-v${SYNCTHING_INOTIFY_VERSION}.tar.gz" \
- && curl -sfSL "https://github.com/syncthing/syncthing-inotify/releases/download/v${SYNCTHING_INOTIFY_VERSION}/${tarball}" -O \
- && tar -xvf "${tarball}" syncthing-inotify \
- && mv syncthing-inotify ${DESTDIR}/syncthing-inotify
+ tarball="syncthing-inotify-${GOOS}-${GOARCH}-v${SYNCTHING_INOTIFY_VERSION}.${TB_EXT}"
+ curl -sfSL "https://github.com/syncthing/syncthing-inotify/releases/download/v${SYNCTHING_INOTIFY_VERSION}/${tarball}" -O || exit 1
+ if [ "${TB_EXT}" = "tar.gz" ]; then
+ tar -xvf "${tarball}" syncthing-inotify && mv syncthing-inotify ${DESTDIR}/syncthing-inotify || exit 1
+ else
+ unzip "$tarball" && mv syncthing-inotify.exe ${DESTDIR}/syncthing-inotify.exe || exit 1
+ fi
fi
echo "DONE: syncthing and syncthing-inotify successfuly installed in ${DESTDIR}" \ No newline at end of file