Ignored Window Changed signal for now.
[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
26 EXT=
27 ifeq ($(HOST_GOOS), windows)
28         EXT=.exe
29 endif
30
31
32 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
33 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
34 BINDIR := $(ROOT_SRCDIR)/bin
35 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
36 PACKAGE_DIR := $(ROOT_SRCDIR)/package
37
38 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
39 export PATH := $(PATH):$(ROOT_SRCDIR)/tools
40
41 VERBOSE_1 := -v
42 VERBOSE_2 := -v -x
43
44 # Release or Debug mode
45 ifeq ($(filter 1,$(RELEASE) $(REL)),)
46         GORELEASE=
47         BUILD_MODE="Debug mode"
48 else
49         # optimized code without debug info
50         GORELEASE= -s -w
51         BUILD_MODE="Release mode"
52 endif
53
54 REPOPATH=github.com/iotbzh/xds-gdb
55 TARGET := xds-gdb
56
57 build: $(TARGET)
58
59 xds-gdb: vendor
60         @echo "### Build $@ (version $(VERSION), subversion $(SUB_VERSION)) - $(BUILD_MODE)";
61         @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)" .
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         make -f $(ROOT_SRCDIR)/Makefile clean
98
99 vendor: tools/glide glide.yaml
100         ./tools/glide install --strip-vendor
101
102 vendor/debug: vendor
103         (cd vendor/github.com/iotbzh && \
104                 rm -rf xds-common && ln -s ../../../../xds-common && \
105                 rm -rf xds-server && ln -s ../../../../xds-server )
106
107 tools/glide:
108         @echo "Downloading glide"
109         mkdir -p tools
110         curl --silent -L https://glide.sh/get | GOBIN=./tools  sh
111
112 help:
113         @echo "Main supported rules:"
114         @echo "  build               (default)"
115         @echo "  release"
116         @echo "  clean"
117         @echo "  package"
118         @echo "  distclean"
119         @echo ""
120         @echo "Influential make variables:"
121         @echo "  V                 - Build verbosity {0,1,2}."
122         @echo "  BUILD_ENV_FLAGS   - Environment added to 'go build'."