Rework Version and Sub-version setup.
[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 SYNCTHING_INOTIFY_VERSION = 0.8.5
9
10
11 # Retrieve git tag/commit to set sub-version string
12 ifeq ($(origin SUB_VERSION), undefined)
13         SUB_VERSION := $(shell git describe --tags --always | sed 's/^v//')
14         ifeq ($(SUB_VERSION), )
15                 SUB_VERSION=unknown-dev
16         endif
17 endif
18
19 # Configurable variables for installation (default /usr/local/...)
20 ifeq ($(origin INSTALL_DIR), undefined)
21         INSTALL_DIR := /usr/local/bin
22 endif
23 ifeq ($(origin INSTALL_WEBAPP_DIR), undefined)
24         INSTALL_WEBAPP_DIR := $(INSTALL_DIR)/xds-server-www
25 endif
26
27 HOST_GOOS=$(shell go env GOOS)
28 HOST_GOARCH=$(shell go env GOARCH)
29 REPOPATH=github.com/iotbzh/xds-server
30
31 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
32 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
33 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
34 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
35
36 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
37 export PATH := $(PATH):$(ROOT_SRCDIR)/tools
38
39 VERBOSE_1 := -v
40 VERBOSE_2 := -v -x
41
42
43 all: build webapp
44
45 .PHONY: build
46 build: xds
47
48 xds:vendor scripts
49         @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION))";
50         @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)" .
51
52 test: tools/glide
53         go test --race $(shell ./tools/glide novendor)
54
55 vet: tools/glide
56         go vet $(shell ./tools/glide novendor)
57
58 fmt: tools/glide
59         go fmt $(shell ./tools/glide novendor)
60
61 run: build/xds tools/syncthing
62         $(LOCAL_BINDIR)/xds-server --log info -c config.json.in
63
64 debug: build/xds webapp/debug tools/syncthing
65         $(LOCAL_BINDIR)/xds-server --log debug -c config.json.in
66
67 .PHONY: clean
68 clean:
69         rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH)
70
71 .PHONY: distclean
72 distclean: clean
73         rm -rf $(LOCAL_BINDIR) tools glide.lock vendor webapp/node_modules webapp/dist
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 "  all                (default)"
113         @echo "  build"
114         @echo "  install"
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'."