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