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