Cleanup
[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 .PHONY: build
42 build: xds
43
44 xds:vendor scripts
45         @echo "### Build XDS server (version $(VERSION))";
46         @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-server -ldflags "-X main.AppVersionGitTag=$(VERSION)" .
47
48 test: tools/glide
49         go test --race $(shell ./tools/glide novendor)
50
51 vet: tools/glide
52         go vet $(shell ./tools/glide novendor)
53
54 fmt: tools/glide
55         go fmt $(shell ./tools/glide novendor)
56
57 run: build/xds tools/syncthing
58         $(LOCAL_BINDIR)/xds-server --log info -c config.json.in
59
60 debug: build/xds webapp/debug tools/syncthing
61         $(LOCAL_BINDIR)/xds-server --log debug -c config.json.in
62
63 .PHONY: clean
64 clean:
65         rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH)
66
67 .PHONY: distclean
68 distclean: clean
69         rm -rf $(LOCAL_BINDIR) tools glide.lock vendor webapp/node_modules webapp/dist
70
71 webapp: webapp/install
72         (cd webapp && gulp build)
73
74 webapp/debug:
75         (cd webapp && gulp watch &)
76
77 webapp/install:
78         (cd webapp && npm install)
79
80 .PHONY: scripts
81 scripts:
82         @mkdir -p $(LOCAL_BINDIR) && cp -f scripts/xds-start-server.sh $(LOCAL_BINDIR)
83
84 .PHONY: install
85 install: all scripts tools/syncthing
86         mkdir -p $(INSTALL_DIR) && cp $(LOCAL_BINDIR)/* $(INSTALL_DIR)
87         mkdir -p $(INSTALL_WEBAPP_DIR) && cp -a webapp/dist/* $(INSTALL_WEBAPP_DIR)
88
89 vendor: tools/glide glide.yaml
90         ./tools/glide install --strip-vendor
91
92 tools/glide:
93         @echo "Downloading glide"
94         mkdir -p tools
95         curl --silent -L https://glide.sh/get | GOBIN=./tools  sh
96
97 .PHONY: tools/syncthing
98 tools/syncthing:
99         @(test -s $(LOCAL_BINDIR)/syncthing || \
100         DESTDIR=$(LOCAL_BINDIR) \
101         SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
102         SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
103         ./scripts/get-syncthing.sh)
104
105 .PHONY: help
106 help:
107         @echo "Main supported rules:"
108         @echo "  build               (default)"
109         @echo "  build/xds"
110         @echo "  clean"
111         @echo "  distclean"
112         @echo ""
113         @echo "Influential make variables:"
114         @echo "  V                 - Build verbosity {0,1,2}."
115         @echo "  BUILD_ENV_FLAGS   - Environment added to 'go build'."