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)
58 # Release or Debug mode
59 ifeq ($(filter 1,$(RELEASE) $(REL)),)
61 # disable compiler optimizations and inlining
63 BUILD_MODE="Debug mode"
65 # optimized code without debug info
68 BUILD_MODE="Release mode"
71 ifeq ($(SUB_VERSION), )
72 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION).zip
74 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip
78 all: tools/syncthing build
81 build: vendor xds webapp
83 xds: scripts tools/syncthing/copytobin
84 @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION), $(BUILD_MODE))";
85 @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)" .
88 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
91 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
94 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
96 run: build/xds tools/syncthing/copytobin
97 $(LOCAL_BINDIR)/xds-server$(EXT) --log info -c config.json.in
99 debug: build/xds tools/syncthing/copytobin
100 $(LOCAL_BINDIR)/xds-server$(EXT) --log debug -c config.json.in
104 rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
108 rm -rf $(LOCAL_BINDIR) $(ROOT_SRCDIR)/tools glide.lock vendor $(ROOT_SRCDIR)/webapp/dist $(ROOT_SRCDIR)/webapp/node_modules
110 webapp: webapp/install
111 mkdir -p $(ROOT_SRCDIR)/webapp/dist $(ROOT_SRCDIR)/webapp/dist/fonts
112 (cd $(ROOT_SRCDIR)/webapp && cp -a ./assets ./src/index.html ./node_modules/font-awesome/css/font-awesome.min.css ./dist/)
113 (cd $(ROOT_SRCDIR)/webapp && cp -a ./node_modules/font-awesome/fonts/* ./dist/fonts/)
116 (cd webapp && npm install)
120 @mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/xds-server-st*.sh scripts/xds-utils $(LOCAL_BINDIR)
125 | sed -e s,"webapp/dist","$(DESTDIR_WWW)",g \
126 | sed -e s,"\./bin","",g \
127 > $(DESTDIR)/config.json.in
131 @test -e $(LOCAL_BINDIR)/xds-server$(EXT) -a -d webapp/dist || { echo "Please execute first: make all\n"; exit 1; }
132 @test -e $(LOCAL_BINDIR)/xds-server-start.sh -a -d $(LOCAL_BINDIR)/xds-utils || { echo "Please execute first: make all\n"; exit 1; }
133 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
134 mkdir -p $(DESTDIR) \
135 && cp -a $(LOCAL_BINDIR)/* $(DESTDIR)
136 mkdir -p $(DESTDIR_WWW) \
137 && cp -a webapp/dist/* $(DESTDIR_WWW)
141 make -f $(ROOT_SRCDIR)/Makefile all install DESTDIR=$(PACKAGE_DIR)/xds-server
142 make -f $(ROOT_SRCDIR)/Makefile conffile DESTDIR=$(PACKAGE_DIR)/xds-server DESTDIR_WWW=www
143 cp -r $(ROOT_SRCDIR)/conf.d $(PACKAGE_DIR)/xds-server
144 rm -f $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE)
145 (cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
147 # On support Linux for now
150 @echo "# Build linux amd64..."
151 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile _package
152 make -f $(ROOT_SRCDIR)/Makefile clean
157 vendor: tools/glide glide.yaml
158 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
161 (cd vendor/github.com/iotbzh && \
162 rm -rf xds-common && ln -s ../../../../xds-common )
166 @test -f $(LOCAL_TOOLSDIR)/glide || { \
167 echo "Downloading glide"; \
168 mkdir -p $(LOCAL_TOOLSDIR); \
169 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
172 .PHONY: tools/syncthing
174 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
175 mkdir -p $(LOCAL_TOOLSDIR); \
176 DESTDIR=$(LOCAL_TOOLSDIR) \
177 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
178 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
179 ./scripts/xds-utils/get-syncthing.sh; }
182 tools/syncthing/copytobin:
183 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
184 @mkdir -p $(LOCAL_BINDIR)
185 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
189 @echo "Main supported rules:"
190 @echo " all (default)"
197 @echo "Influential make variables:"
198 @echo " V - Build verbosity {0,1,2}."
199 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."