1 # Makefile used to build XDS Server
3 # Syncthing version to install
4 SYNCTHING_VERSION = 0.14.38
5 SYNCTHING_INOTIFY_VERSION = 0.8.7
8 # Retrieve git tag/commit to set version & sub-version strings
9 GIT_DESC := $(shell git describe --always --tags)
10 VERSION := $(firstword $(subst -, ,$(GIT_DESC)))
11 SUB_VERSION := $(subst $(VERSION)-,,$(GIT_DESC))
13 VERSION := unknown-dev
15 ifeq ($(SUB_VERSION), )
16 SUB_VERSION := $(shell date +'%Y-%m-%d_%H%M%S')
19 # for backward compatibility
20 ifneq ($(origin INSTALL_DIR), undefined)
21 DESTDIR := $(INSTALL_DIR)
23 ifneq ($(origin INSTALL_WEBAPP_DIR), undefined)
24 DESTDIR_WWW := $(INSTALL_WEBAPP_DIR)
27 # Configurable variables for installation (default /opt/AGL/...)
28 ifeq ($(origin DESTDIR), undefined)
29 DESTDIR := /opt/AGL/xds/server
31 ifeq ($(origin DESTDIR_WWW), undefined)
32 DESTDIR_WWW := $(DESTDIR)/www
35 HOST_GOOS=$(shell go env GOOS)
36 HOST_GOARCH=$(shell go env GOARCH)
37 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
38 REPOPATH=github.com/iotbzh/xds-server
41 ifeq ($(HOST_GOOS), windows)
45 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
46 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
47 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
48 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
49 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
50 PACKAGE_DIR := $(ROOT_SRCDIR)/package
52 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
53 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
56 GOVERSION := $(shell go version |grep -o '[0-9\.]*'|head -n 1)
57 GOVERMAJ := $(shell echo $(GOVERSION) |cut -f1 -d.)
58 GOVERMIN := $(shell echo $(GOVERSION) |cut -f2 -d.)
59 CHECKGOVER := $(shell [ $(GOVERMAJ) -gt 1 -o \( $(GOVERMAJ) -eq 1 -a $(GOVERMIN) -ge 8 \) ] && echo true)
60 CHECKERRMSG := "ERROR: Go version 1.8.1 or higher is requested (current detected version: $(GOVERSION))."
66 # Release or Debug mode
67 ifeq ($(filter 1,$(RELEASE) $(REL)),)
69 # disable compiler optimizations and inlining
71 BUILD_MODE="Debug mode"
73 # optimized code without debug info
76 BUILD_MODE="Release mode"
79 ifeq ($(SUB_VERSION), )
80 PACKAGE_ZIPFILE := xds-server_$(ARCH)-$(VERSION).zip
82 PACKAGE_ZIPFILE := xds-server_$(ARCH)-$(VERSION)_$(SUB_VERSION).zip
86 all: tools/syncthing build
89 build: checkgover vendor xds webapp
91 xds: scripts tools/syncthing/copytobin
92 @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION), $(BUILD_MODE))";
93 @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-server$(EXT) -ldflags "$(GO_LDFLAGS) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" -gcflags "$(GO_GCFLAGS)" .
96 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
99 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
102 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
104 run: build/xds tools/syncthing/copytobin
105 $(LOCAL_BINDIR)/xds-server$(EXT) --log info -c config.json.in
107 debug: build/xds tools/syncthing/copytobin
108 $(LOCAL_BINDIR)/xds-server$(EXT) --log debug -c config.json.in
112 rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
116 rm -rf $(LOCAL_BINDIR) $(ROOT_SRCDIR)/tools glide.lock vendor $(ROOT_SRCDIR)/webapp/dist $(ROOT_SRCDIR)/webapp/node_modules
118 webapp: webapp/install
119 mkdir -p $(ROOT_SRCDIR)/webapp/dist $(ROOT_SRCDIR)/webapp/dist/fonts
120 (cd $(ROOT_SRCDIR)/webapp && cp -a ./assets ./src/index.html ./node_modules/font-awesome/css/font-awesome.min.css ./dist/)
121 (cd $(ROOT_SRCDIR)/webapp && cp -a ./node_modules/font-awesome/fonts/* ./dist/fonts/)
124 (cd webapp && npm install)
128 @mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/xds-server-st*.sh scripts/xds-utils $(LOCAL_BINDIR)
133 | sed -e s,"webapp/dist","$(DESTDIR_WWW)",g \
134 | sed -e s,"\./bin","",g \
135 > $(DESTDIR)/config.json.in
139 @test -e $(LOCAL_BINDIR)/xds-server$(EXT) -a -d webapp/dist || { echo "Please execute first: make all\n"; exit 1; }
140 @test -e $(LOCAL_BINDIR)/xds-server-start.sh -a -d $(LOCAL_BINDIR)/xds-utils || { echo "Please execute first: make all\n"; exit 1; }
141 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
142 mkdir -p $(DESTDIR) \
143 && cp -a $(LOCAL_BINDIR)/* $(DESTDIR)
144 mkdir -p $(DESTDIR_WWW) \
145 && cp -a webapp/dist/* $(DESTDIR_WWW)
149 make -f $(ROOT_SRCDIR)/Makefile all install DESTDIR=$(PACKAGE_DIR)/xds-server
150 make -f $(ROOT_SRCDIR)/Makefile conffile DESTDIR=$(PACKAGE_DIR)/xds-server DESTDIR_WWW=www
151 cp -r $(ROOT_SRCDIR)/conf.d $(PACKAGE_DIR)/xds-server
152 rm -f $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE)
153 (cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
155 # On support Linux for now
158 @echo "# Build linux amd64..."
159 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile _package
160 make -f $(ROOT_SRCDIR)/Makefile clean
165 vendor: tools/glide glide.yaml
166 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
169 (cd vendor/github.com/iotbzh && \
170 rm -rf xds-common && ln -s ../../../../xds-common )
174 @test -f $(LOCAL_TOOLSDIR)/glide || { \
175 echo "Downloading glide"; \
176 mkdir -p $(LOCAL_TOOLSDIR); \
177 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
180 .PHONY: tools/syncthing
182 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
183 mkdir -p $(LOCAL_TOOLSDIR); \
184 DESTDIR=$(LOCAL_TOOLSDIR) \
185 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
186 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
187 ./scripts/xds-utils/get-syncthing.sh; }
190 tools/syncthing/copytobin:
191 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
192 @mkdir -p $(LOCAL_BINDIR)
193 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
197 @test "$(CHECKGOVER)" = "true" || { echo $(CHECKERRMSG); exit 1; }
202 @echo "Main supported rules:"
203 @echo " all (default)"
210 @echo "Influential make variables:"
211 @echo " V - Build verbosity {0,1,2}."
212 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."