Auto start Syncthing and Syncthing-inotify.
[src/xds/xds-server.git] / Makefile
1 # Makefile used to build XDS daemon Web Server
2
3 # Application Version
4 VERSION := 0.0.1
5
6 # Syncthing version to install
7 SYNCTHING_VERSION = 0.14.27
8 # FIXME: use patched version while waiting integration of #165
9 #SYNCTHING_INOTIFY_VERSION = 0.8.5
10
11
12 # Retrieve git tag/commit to set sub-version string
13 ifeq ($(origin SUB_VERSION), undefined)
14         SUB_VERSION := $(shell git describe --tags --always | sed 's/^v//')
15         ifeq ($(SUB_VERSION), )
16                 SUB_VERSION=unknown-dev
17         endif
18 endif
19
20 # Configurable variables for installation (default /usr/local/...)
21 ifeq ($(origin INSTALL_DIR), undefined)
22         INSTALL_DIR := /usr/local/bin
23 endif
24 ifeq ($(origin INSTALL_WEBAPP_DIR), undefined)
25         INSTALL_WEBAPP_DIR := $(INSTALL_DIR)/xds-server-www
26 endif
27
28 HOST_GOOS=$(shell go env GOOS)
29 HOST_GOARCH=$(shell go env GOARCH)
30 REPOPATH=github.com/iotbzh/xds-server
31
32 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
33 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
34 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
35 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
36 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools
37
38
39 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
40 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
41
42 VERBOSE_1 := -v
43 VERBOSE_2 := -v -x
44
45
46 all: build webapp
47
48 .PHONY: build
49 build: xds
50
51 xds:vendor scripts
52         @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION))";
53         @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-server -ldflags "-X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" .
54
55 test: tools/glide
56         go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
57
58 vet: tools/glide
59         go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
60
61 fmt: tools/glide
62         go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
63
64 run: build/xds tools/syncthing
65         $(LOCAL_BINDIR)/xds-server --log info -c config.json.in
66
67 debug: build/xds webapp/debug tools/syncthing
68         $(LOCAL_BINDIR)/xds-server --log debug -c config.json.in
69
70 .PHONY: clean
71 clean:
72         rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH)
73
74 .PHONY: distclean
75 distclean: clean
76         rm -rf $(LOCAL_BINDIR) $(LOCAL_TOOLSDIR) glide.lock vendor webapp/node_modules webapp/dist
77
78 webapp: webapp/install
79         (cd webapp && gulp build)
80
81 webapp/debug:
82         (cd webapp && gulp watch &)
83
84 webapp/install:
85         (cd webapp && npm install)
86
87 .PHONY: scripts
88 scripts:
89         @mkdir -p $(LOCAL_BINDIR) && cp -f scripts/xds-start-server.sh $(LOCAL_BINDIR)
90
91 .PHONY: install
92 install: all scripts tools/syncthing
93         mkdir -p $(INSTALL_DIR) \
94                 && cp $(LOCAL_BINDIR)/* $(INSTALL_DIR) \
95                 && cp $(LOCAL_TOOLSDIR)/syncthing* $(INSTALL_DIR)
96         mkdir -p $(INSTALL_WEBAPP_DIR) \
97                 && cp -a webapp/dist/* $(INSTALL_WEBAPP_DIR)
98
99 vendor: tools/glide glide.yaml
100         $(LOCAL_TOOLSDIR)/glide install --strip-vendor
101
102 tools/glide:
103         @echo "Downloading glide"
104         mkdir -p $(LOCAL_TOOLSDIR)
105         curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR)  sh
106
107 .PHONY: tools/syncthing
108 tools/syncthing:
109         @(test -s $(LOCAL_TOOLSDIR)/syncthing || \
110         DESTDIR=$(LOCAL_TOOLSDIR) \
111         SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
112         SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
113         ./scripts/get-syncthing.sh)
114
115 .PHONY: help
116 help:
117         @echo "Main supported rules:"
118         @echo "  all                (default)"
119         @echo "  build"
120         @echo "  install"
121         @echo "  clean"
122         @echo "  distclean"
123         @echo ""
124         @echo "Influential make variables:"
125         @echo "  V                 - Build verbosity {0,1,2}."
126         @echo "  BUILD_ENV_FLAGS   - Environment added to 'go build'."