fix image link
[src/xds/xds-gdb.git] / Makefile
1 # Makefile used to build xds-gdb commands
2
3 # Application Version
4 VERSION := 0.1.0
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
62 test: tools/glide
63         go test --race $(shell ./tools/glide novendor)
64
65 vet: tools/glide
66         go vet $(shell ./tools/glide novendor)
67
68 fmt: tools/glide
69         go fmt $(shell ./tools/glide novendor)
70
71 .PHONY: clean
72 clean:
73         rm -rf $(BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
74
75 distclean: clean
76         rm -rf $(BINDIR) tools glide.lock vendor $(ROOT_SRCDIR)/*.zip
77
78 .PHONY: release
79 release:
80         RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile clean build
81
82 package: clean build
83         @mkdir -p $(PACKAGE_DIR)/xds-gdb
84         @cp -a $(BINDIR)/*gdb$(EXT) $(PACKAGE_DIR)/xds-gdb
85         @cd $(PACKAGE_DIR) && zip  --symlinks -r $(ROOT_SRCDIR)/xds-gdb_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip ./xds-gdb
86
87 .PHONY: package-all
88 package-all:
89         @echo "# Build linux amd64..."
90         GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
91         @echo "# Build windows amd64..."
92 #       GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
93         @echo " WARNING: build on Windows not supported for now."
94         @echo "# Build darwin amd64..."
95         GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
96
97 vendor: tools/glide glide.yaml
98         ./tools/glide install --strip-vendor
99
100 vendor/debug: vendor
101         (cd vendor/github.com/iotbzh && \
102                 rm -rf xds-common && ln -s ../../../../xds-common && \
103                 rm -rf xds-server && ln -s ../../../../xds-server )
104
105 tools/glide:
106         @echo "Downloading glide"
107         mkdir -p tools
108         curl --silent -L https://glide.sh/get | GOBIN=./tools  sh
109
110 help:
111         @echo "Main supported rules:"
112         @echo "  build               (default)"
113         @echo "  release"
114         @echo "  clean"
115         @echo "  package"
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'."