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