Set "exec" command from client side.
[src/xds/xds-gdb.git] / Makefile
1 # Makefile used to build xds-gdb commands
2
3 # Application Version
4 VERSION := 0.0.1
5
6
7 # Retrieve git tag/commit to set sub-version string
8 ifeq ($(origin SUB_VERSION), undefined)
9         SUB_VERSION := $(shell git describe --exact-match --tags 2>/dev/null | sed 's/^v//')
10         ifneq ($(SUB_VERSION), )
11                 VERSION := $(firstword $(subst -, ,$(SUB_VERSION)))
12                 SUB_VERSION := $(word 2,$(subst -, ,$(SUB_VERSION)))
13         else
14                 SUB_VERSION := $(shell git rev-parse --short HEAD)
15                 ifeq ($(SUB_VERSION), )
16                         SUB_VERSION := unknown-dev
17                 endif
18         endif
19 endif
20
21 HOST_GOOS=$(shell go env GOOS)
22 HOST_GOARCH=$(shell go env GOARCH)
23 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
24
25 EXT=
26 ifeq ($(HOST_GOOS), windows)
27         EXT=.exe
28 endif
29
30
31 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
32 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
33 BINDIR := $(ROOT_SRCDIR)/bin
34 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
35 PACKAGE_DIR := $(ROOT_SRCDIR)/package
36
37 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
38 export PATH := $(PATH):$(ROOT_SRCDIR)/tools
39
40 VERBOSE_1 := -v
41 VERBOSE_2 := -v -x
42
43 # Release or Debug mode
44 ifeq ($(filter 1,$(RELEASE) $(REL)),)
45         GORELEASE=
46         BUILD_MODE="Debug mode"
47 else
48         # optimized code without debug info
49         GORELEASE= -s -w
50         BUILD_MODE="Release mode"
51 endif
52
53 REPOPATH=github.com/iotbzh/xds-gdb
54 TARGET := xds-gdb
55
56 build: $(TARGET)
57
58 xds-gdb: vendor
59         @echo "### Build $@ (version $(VERSION), subversion $(SUB_VERSION)) - $(BUILD_MODE)";
60         @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(BINDIR)/$@$(EXT) -ldflags "$(GORELEASE) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" .
61         @([ "$(HOST_GOOS)" = "linux" ] && { cd $(BINDIR) && ln -sf $@ $(subst xds-,,$@); } || { true; } )
62
63 test: tools/glide
64         go test --race $(shell ./tools/glide novendor)
65
66 vet: tools/glide
67         go vet $(shell ./tools/glide novendor)
68
69 fmt: tools/glide
70         go fmt $(shell ./tools/glide novendor)
71
72 .PHONY: clean
73 clean:
74         rm -rf $(BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
75
76 distclean: clean
77         rm -rf $(BINDIR) tools glide.lock vendor $(ROOT_SRCDIR)/*.zip
78
79 .PHONY: release
80 release:
81         RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile clean build
82
83 package: clean build
84         @mkdir -p $(PACKAGE_DIR)/xds-gdb
85         @cp -a $(BINDIR)/*gdb$(EXT) $(PACKAGE_DIR)/xds-gdb
86         @cd $(PACKAGE_DIR) && zip  --symlinks -r $(ROOT_SRCDIR)/xds-gdb_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip ./xds-gdb
87
88 .PHONY: package-all
89 package-all:
90         @echo "# Build linux amd64..."
91         GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
92         @echo "# Build windows amd64..."
93 #       GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
94         @echo " WARNING: build on Windows not supported for now."
95         @echo "# Build darwin amd64..."
96         GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
97
98 vendor: tools/glide glide.yaml
99         ./tools/glide install --strip-vendor
100
101 vendor/debug: vendor
102         (cd vendor/github.com/iotbzh && \
103                 rm -rf xds-common && ln -s ../../../../xds-common && \
104                 rm -rf xds-server && ln -s ../../../../xds-server )
105
106 tools/glide:
107         @echo "Downloading glide"
108         mkdir -p tools
109         curl --silent -L https://glide.sh/get | GOBIN=./tools  sh
110
111 help:
112         @echo "Main supported rules:"
113         @echo "  build               (default)"
114         @echo "  release"
115         @echo "  clean"
116         @echo "  package"
117         @echo "  distclean"
118         @echo ""
119         @echo "Influential make variables:"
120         @echo "  V                 - Build verbosity {0,1,2}."
121         @echo "  BUILD_ENV_FLAGS   - Environment added to 'go build'."