1 # Makefile used to build XDS daemon Web Server
6 # Syncthing version to install
7 SYNCTHING_VERSION = 0.14.28
8 SYNCTHING_INOTIFY_VERSION = 0.8.6
11 # Retrieve git tag/commit to set sub-version string
12 ifeq ($(origin SUB_VERSION), undefined)
13 SUB_VERSION := $(shell git describe --exact-match --tags 2>/dev/null | sed 's/^v//')
14 ifneq ($(SUB_VERSION), )
15 VERSION := $(firstword $(subst -, ,$(SUB_VERSION)))
16 SUB_VERSION := $(word 2,$(subst -, ,$(SUB_VERSION)))
18 SUB_VERSION := $(shell git rev-parse --short HEAD)
19 ifeq ($(SUB_VERSION), )
20 SUB_VERSION := unknown-dev
25 # for backward compatibility
26 ifneq ($(origin INSTALL_DIR), undefined)
27 DESTDIR := $(INSTALL_DIR)
29 ifneq ($(origin INSTALL_WEBAPP_DIR), undefined)
30 DESTDIR_WWW := $(INSTALL_WEBAPP_DIR)
33 # Configurable variables for installation (default /usr/local/...)
34 ifeq ($(origin DESTDIR), undefined)
35 DESTDIR := /usr/local/bin
37 ifeq ($(origin DESTDIR_WWW), undefined)
38 DESTDIR_WWW := $(DESTDIR)/www-xds-server
41 HOST_GOOS=$(shell go env GOOS)
42 HOST_GOARCH=$(shell go env GOARCH)
43 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
44 REPOPATH=github.com/iotbzh/xds-server
47 ifeq ($(HOST_GOOS), windows)
51 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
52 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
53 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
54 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
55 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
56 PACKAGE_DIR := $(ROOT_SRCDIR)/package
58 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
59 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
64 # Release or Debug mode
65 ifeq ($(filter 1,$(RELEASE) $(REL)),)
67 BUILD_MODE="Debug mode"
69 # optimized code without debug info
71 BUILD_MODE="Release mode"
74 ifeq ($(SUB_VERSION), )
75 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION).zip
77 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip
81 all: tools/syncthing build
84 build: vendor xds webapp
86 xds: scripts tools/syncthing/copytobin
87 @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION))";
88 @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)" .
91 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
94 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
97 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
99 run: build/xds tools/syncthing/copytobin
100 $(LOCAL_BINDIR)/xds-server$(EXT) --log info -c config.json.in
102 debug: build/xds webapp/debug tools/syncthing/copytobin
103 $(LOCAL_BINDIR)/xds-server$(EXT) --log debug -c config.json.in
107 rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
111 rm -rf $(LOCAL_BINDIR) $(ROOT_SRCDIR)/tools glide.lock vendor webapp/node_modules webapp/dist
113 webapp: webapp/install
114 (cd webapp && gulp build)
117 (cd webapp && gulp watch &)
120 (cd webapp && npm install)
121 @if [ -d ${DESTDIR}/usr/local/etc ]; then rm -rf ${DESTDIR}/usr; fi
125 @mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/xds-server-st*.sh scripts/xds-utils $(LOCAL_BINDIR)
130 | sed -e s,"webapp/dist","$(DESTDIR_WWW)",g \
131 | sed -e s,"\./bin","",g \
132 > $(DESTDIR)/config.json
136 @test -e $(LOCAL_BINDIR)/xds-server$(EXT) -a -d webapp/dist || { echo "Please execute first: make all\n"; exit 1; }
137 @test -e $(LOCAL_BINDIR)/xds-server-start.sh -a -d $(LOCAL_BINDIR)/xds-utils || { echo "Please execute first: make all\n"; exit 1; }
138 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
139 mkdir -p $(DESTDIR) \
140 && cp -a $(LOCAL_BINDIR)/* $(DESTDIR)
141 mkdir -p $(DESTDIR_WWW) \
142 && cp -a webapp/dist/* $(DESTDIR_WWW)
146 make -f $(ROOT_SRCDIR)/Makefile all install DESTDIR=$(PACKAGE_DIR)/xds-server
147 make -f $(ROOT_SRCDIR)/Makefile conffile DESTDIR=$(PACKAGE_DIR)/xds-server DESTDIR_WWW=www-xds-server
148 (cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
152 @echo "# Build linux amd64..."
153 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
154 @echo "# Build windows amd64..."
155 GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
157 vendor: tools/glide glide.yaml
158 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
162 @test -f $(LOCAL_TOOLSDIR)/glide || { \
163 echo "Downloading glide"; \
164 mkdir -p $(LOCAL_TOOLSDIR); \
165 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
168 .PHONY: tools/syncthing
170 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
171 mkdir -p $(LOCAL_TOOLSDIR); \
172 DESTDIR=$(LOCAL_TOOLSDIR) \
173 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
174 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
175 ./scripts/xds-utils/get-syncthing.sh; }
178 tools/syncthing/copytobin:
179 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
180 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
184 @echo "Main supported rules:"
185 @echo " all (default)"
191 @echo "Influential make variables:"
192 @echo " V - Build verbosity {0,1,2}."
193 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."