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