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 ifeq ($(SUB_VERSION), )
19 SUB_VERSION := $(shell git rev-parse --short HEAD)
20 ifeq ($(SUB_VERSION), )
21 SUB_VERSION := unknown-dev
26 # for backward compatibility
27 ifneq ($(origin INSTALL_DIR), undefined)
28 DESTDIR := $(INSTALL_DIR)
30 ifneq ($(origin INSTALL_WEBAPP_DIR), undefined)
31 DESTDIR_WWW := $(INSTALL_WEBAPP_DIR)
34 # Configurable variables for installation (default /opt/AGL/...)
35 ifeq ($(origin DESTDIR), undefined)
36 DESTDIR := /opt/AGL/xds/server
38 ifeq ($(origin DESTDIR_WWW), undefined)
39 DESTDIR_WWW := $(DESTDIR)/www
42 HOST_GOOS=$(shell go env GOOS)
43 HOST_GOARCH=$(shell go env GOARCH)
44 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
45 REPOPATH=github.com/iotbzh/xds-server
48 ifeq ($(HOST_GOOS), windows)
52 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
53 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
54 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
55 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
56 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
57 PACKAGE_DIR := $(ROOT_SRCDIR)/package
59 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
60 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
65 # Release or Debug mode
66 ifeq ($(filter 1,$(RELEASE) $(REL)),)
68 BUILD_MODE="Debug mode"
70 # optimized code without debug info
72 BUILD_MODE="Release mode"
75 ifeq ($(SUB_VERSION), )
76 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION).zip
78 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip
82 all: tools/syncthing build
85 build: vendor xds webapp
87 xds: scripts tools/syncthing/copytobin
88 @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION), $(BUILD_MODE))";
89 @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)" .
92 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
95 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
98 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
100 run: build/xds tools/syncthing/copytobin
101 $(LOCAL_BINDIR)/xds-server$(EXT) --log info -c config.json.in
103 debug: build/xds webapp/debug tools/syncthing/copytobin
104 $(LOCAL_BINDIR)/xds-server$(EXT) --log debug -c config.json.in
108 rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
112 rm -rf $(LOCAL_BINDIR) $(ROOT_SRCDIR)/tools glide.lock vendor webapp/node_modules webapp/dist webapp/assets/xds-agent-tarballs/*.zip
114 webapp: webapp/install
115 (cd webapp && gulp build)
118 (cd webapp && gulp watch &)
121 (cd webapp && npm install)
122 @if [ -d ${DESTDIR}/usr/local/etc ]; then rm -rf ${DESTDIR}/usr; fi
126 @mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/xds-server-st*.sh scripts/xds-utils $(LOCAL_BINDIR)
131 | sed -e s,"webapp/dist","$(DESTDIR_WWW)",g \
132 | sed -e s,"\./bin","",g \
133 > $(DESTDIR)/config.json.in
137 @test -e $(LOCAL_BINDIR)/xds-server$(EXT) -a -d webapp/dist || { echo "Please execute first: make all\n"; exit 1; }
138 @test -e $(LOCAL_BINDIR)/xds-server-start.sh -a -d $(LOCAL_BINDIR)/xds-utils || { echo "Please execute first: make all\n"; exit 1; }
139 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
140 mkdir -p $(DESTDIR) \
141 && cp -a $(LOCAL_BINDIR)/* $(DESTDIR)
142 mkdir -p $(DESTDIR_WWW) \
143 && cp -a webapp/dist/* $(DESTDIR_WWW)
147 make -f $(ROOT_SRCDIR)/Makefile all install DESTDIR=$(PACKAGE_DIR)/xds-server
148 make -f $(ROOT_SRCDIR)/Makefile conffile DESTDIR=$(PACKAGE_DIR)/xds-server DESTDIR_WWW=www
149 cp -r $(ROOT_SRCDIR)/conf.d $(PACKAGE_DIR)/xds-server
150 rm -f $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE)
151 (cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
153 # On support Linux for now
156 @echo "# Build linux amd64..."
157 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile _package
158 make -f $(ROOT_SRCDIR)/Makefile clean
163 vendor: tools/glide glide.yaml
164 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
167 (cd vendor/github.com/iotbzh && \
168 rm -rf xds-common && ln -s ../../../../xds-common )
172 @test -f $(LOCAL_TOOLSDIR)/glide || { \
173 echo "Downloading glide"; \
174 mkdir -p $(LOCAL_TOOLSDIR); \
175 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
178 .PHONY: tools/syncthing
180 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
181 mkdir -p $(LOCAL_TOOLSDIR); \
182 DESTDIR=$(LOCAL_TOOLSDIR) \
183 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
184 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
185 ./scripts/xds-utils/get-syncthing.sh; }
188 tools/syncthing/copytobin:
189 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
190 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
194 @echo "Main supported rules:"
195 @echo " all (default)"
201 @echo "Influential make variables:"
202 @echo " V - Build verbosity {0,1,2}."
203 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."