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
16 # for backward compatibility
17 ifneq ($(origin INSTALL_DIR), undefined)
18 DESTDIR := $(INSTALL_DIR)
20 ifneq ($(origin INSTALL_WEBAPP_DIR), undefined)
21 DESTDIR_WWW := $(INSTALL_WEBAPP_DIR)
24 # Configurable variables for installation (default /opt/AGL/...)
25 ifeq ($(origin DESTDIR), undefined)
26 DESTDIR := /opt/AGL/xds/server
28 ifeq ($(origin DESTDIR_WWW), undefined)
29 DESTDIR_WWW := $(DESTDIR)/www
32 HOST_GOOS=$(shell go env GOOS)
33 HOST_GOARCH=$(shell go env GOARCH)
34 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
35 REPOPATH=github.com/iotbzh/xds-server
38 ifeq ($(HOST_GOOS), windows)
42 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
43 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
44 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
45 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
46 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
47 PACKAGE_DIR := $(ROOT_SRCDIR)/package
49 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
50 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
55 # Release or Debug mode
56 ifeq ($(filter 1,$(RELEASE) $(REL)),)
58 # disable compiler optimizations and inlining
60 BUILD_MODE="Debug mode"
62 # optimized code without debug info
65 BUILD_MODE="Release mode"
68 ifeq ($(SUB_VERSION), )
69 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION).zip
71 PACKAGE_ZIPFILE := xds-server_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip
75 all: tools/syncthing build
78 build: vendor xds webapp
80 xds: scripts tools/syncthing/copytobin
81 @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION), $(BUILD_MODE))";
82 @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)" .
85 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
88 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
91 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
93 run: build/xds tools/syncthing/copytobin
94 $(LOCAL_BINDIR)/xds-server$(EXT) --log info -c config.json.in
96 debug: build/xds tools/syncthing/copytobin
97 $(LOCAL_BINDIR)/xds-server$(EXT) --log debug -c config.json.in
101 rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
105 rm -rf $(LOCAL_BINDIR) $(ROOT_SRCDIR)/tools glide.lock vendor $(ROOT_SRCDIR)/webapp/dist $(ROOT_SRCDIR)/webapp/node_modules
107 webapp: webapp/install
108 mkdir -p $(ROOT_SRCDIR)/webapp/dist $(ROOT_SRCDIR)/webapp/dist/fonts
109 (cd $(ROOT_SRCDIR)/webapp && cp -a ./assets ./src/index.html ./node_modules/font-awesome/css/font-awesome.min.css ./dist/)
110 (cd $(ROOT_SRCDIR)/webapp && cp -a ./node_modules/font-awesome/fonts/* ./dist/fonts/)
113 (cd webapp && npm install)
117 @mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/xds-server-st*.sh scripts/xds-utils $(LOCAL_BINDIR)
122 | sed -e s,"webapp/dist","$(DESTDIR_WWW)",g \
123 | sed -e s,"\./bin","",g \
124 > $(DESTDIR)/config.json.in
128 @test -e $(LOCAL_BINDIR)/xds-server$(EXT) -a -d webapp/dist || { echo "Please execute first: make all\n"; exit 1; }
129 @test -e $(LOCAL_BINDIR)/xds-server-start.sh -a -d $(LOCAL_BINDIR)/xds-utils || { echo "Please execute first: make all\n"; exit 1; }
130 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
131 mkdir -p $(DESTDIR) \
132 && cp -a $(LOCAL_BINDIR)/* $(DESTDIR)
133 mkdir -p $(DESTDIR_WWW) \
134 && cp -a webapp/dist/* $(DESTDIR_WWW)
138 make -f $(ROOT_SRCDIR)/Makefile all install DESTDIR=$(PACKAGE_DIR)/xds-server
139 make -f $(ROOT_SRCDIR)/Makefile conffile DESTDIR=$(PACKAGE_DIR)/xds-server DESTDIR_WWW=www
140 cp -r $(ROOT_SRCDIR)/conf.d $(PACKAGE_DIR)/xds-server
141 rm -f $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE)
142 (cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
144 # On support Linux for now
147 @echo "# Build linux amd64..."
148 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile _package
149 make -f $(ROOT_SRCDIR)/Makefile clean
154 vendor: tools/glide glide.yaml
155 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
158 (cd vendor/github.com/iotbzh && \
159 rm -rf xds-common && ln -s ../../../../xds-common )
163 @test -f $(LOCAL_TOOLSDIR)/glide || { \
164 echo "Downloading glide"; \
165 mkdir -p $(LOCAL_TOOLSDIR); \
166 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
169 .PHONY: tools/syncthing
171 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
172 mkdir -p $(LOCAL_TOOLSDIR); \
173 DESTDIR=$(LOCAL_TOOLSDIR) \
174 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
175 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
176 ./scripts/xds-utils/get-syncthing.sh; }
179 tools/syncthing/copytobin:
180 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
181 @mkdir -p $(LOCAL_BINDIR)
182 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
186 @echo "Main supported rules:"
187 @echo " all (default)"
194 @echo "Influential make variables:"
195 @echo " V - Build verbosity {0,1,2}."
196 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."