Fix distclean
[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
12 HOST_GOOS=$(shell go env GOOS)
13 HOST_GOARCH=$(shell go env GOARCH)
14 REPOPATH=github.com/iotbzh/xds-server
15
16 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
17 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
18 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
19
20 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
21 export PATH := $(PATH):$(ROOT_SRCDIR)/tools
22
23 VERBOSE_1 := -v
24 VERBOSE_2 := -v -x
25
26 #WHAT := xds-make
27
28 all: build webapp
29
30 #build: build/xds build/cmds
31 build: build/xds
32
33 xds: build/xds
34
35 build/xds: vendor
36         @echo "### Build XDS server (version $(VERSION))";
37         @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o bin/xds-server -ldflags "-X main.AppVersionGitTag=$(VERSION)" .
38
39 #build/cmds: vendor
40 #       @for target in $(WHAT); do \
41 #               echo "### Build $$target"; \
42 #               $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o bin/$$target -ldflags "-X main.AppVersionGitTag=$(VERSION)" ./cmd/$$target; \
43 #       done
44
45 test: tools/glide
46         go test --race $(shell ./tools/glide novendor)
47
48 vet: tools/glide
49         go vet $(shell ./tools/glide novendor)
50
51 fmt: tools/glide
52         go fmt $(shell ./tools/glide novendor)
53
54 run: build/xds
55         ./bin/xds-server --log info -c config.json.in
56
57 debug: build/xds webapp/debug
58         ./bin/xds-server --log debug -c config.json.in
59
60 clean:
61         rm -rf ./bin/* debug cmd/*/debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH)
62
63 distclean: clean
64         rm -rf bin tools glide.lock vendor cmd/*/vendor webapp/node_modules webapp/dist
65
66 run3:
67         goreman start
68
69 webapp: webapp/install
70         (cd webapp && gulp build)
71
72 webapp/debug:
73         (cd webapp && gulp watch &)
74
75 webapp/install:
76         (cd webapp && npm install)
77
78
79 # FIXME - package webapp
80 release: releasetar
81         goxc -d ./release -tasks-=go-vet,go-test -os="linux darwin" -pv=$(VERSION)  -arch="386 amd64 arm arm64" -build-ldflags="-X main.AppVersionGitTag=$(VERSION)" -resources-include="README.md,Documentation,LICENSE,contrib" -main-dirs-exclude="vendor"
82
83 releasetar:
84         mkdir -p release/$(VERSION)
85         glide install --strip-vcs --strip-vendor --update-vendored --delete
86         glide-vc --only-code --no-tests --keep="**/*.json.in"
87         git ls-files > /tmp/xds-server-build
88         find vendor >> /tmp/xds-server-build
89         find webapp/ -path webapp/node_modules -prune -o -print >> /tmp/xds-server-build
90         tar -cvf release/$(VERSION)/xds-server_$(VERSION)_src.tar -T /tmp/xds-server-build --transform 's,^,xds-server_$(VERSION)/,'
91         rm /tmp/xds-server-build
92         gzip release/$(VERSION)/xds-server_$(VERSION)_src.tar
93
94
95 vendor: tools/glide glide.yaml
96         ./tools/glide install --strip-vendor
97
98 tools/glide:
99         @echo "Downloading glide"
100         mkdir -p tools
101         curl --silent -L https://glide.sh/get | GOBIN=./tools  sh
102
103 goenv:
104         @go env
105
106 help:
107         @echo "Main supported rules:"
108         @echo "  build               (default)"
109         @echo "  build/xds"
110         @echo "  build/cmds"
111         @echo "  release"
112         @echo "  clean"
113         @echo "  distclean"
114         @echo ""
115         @echo "Influential make variables:"
116         @echo "  V                 - Build verbosity {0,1,2}."
117         @echo "  BUILD_ENV_FLAGS   - Environment added to 'go build'."
118 #       @echo "  WHAT              - Command to build. (e.g. WHAT=xds-make)"