1 # Makefile used to build xds-cli commands
7 # Retrieve git tag/commit to set version & sub-version strings
8 GIT_DESC := $(shell git describe --always --tags)
9 VERSION := $(firstword $(subst -, ,$(GIT_DESC)))
10 ifeq (-,$(findstring -,$(GIT_DESC)))
11 SUB_VERSION := $(subst $(VERSION)-,,$(GIT_DESC))
14 VERSION := unknown-dev
16 ifeq ($(SUB_VERSION), )
17 SUB_VERSION := $(shell date +'%Y-%m-%d_%H%M%S')
20 # Configurable variables for installation (default /opt/AGL/...)
21 ifeq ($(origin DESTDIR), undefined)
22 DESTDIR := /opt/AGL/xds/cli
25 HOST_GOOS=$(shell go env GOOS)
26 HOST_GOARCH=$(shell go env GOARCH)
27 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
28 REPOPATH=github.com/iotbzh/$(TARGET)
31 ifeq ($(HOST_GOOS), windows)
35 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
36 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
37 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
38 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
39 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
40 PACKAGE_DIR := $(ROOT_SRCDIR)/package
42 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
43 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
46 GOVERSION := $(shell go version |grep -o '[0-9\.]*'|head -n 1)
47 GOVERMAJ := $(shell echo $(GOVERSION) |cut -f1 -d.)
48 GOVERMIN := $(shell echo $(GOVERSION) |cut -f2 -d.)
49 CHECKGOVER := $(shell [ $(GOVERMAJ) -gt 1 -o \( $(GOVERMAJ) -eq 1 -a $(GOVERMIN) -ge 8 \) ] && echo true)
50 CHECKERRMSG := "ERROR: Go version 1.8.1 or higher is requested (current detected version: $(GOVERSION))."
56 # Release or Debug mode
57 ifeq ($(filter 1,$(RELEASE) $(REL)),)
59 # disable compiler optimizations and inlining
61 BUILD_MODE="Debug mode"
63 # optimized code without debug info
66 BUILD_MODE="Release mode"
70 ifeq ($(SUB_VERSION), )
71 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(VERSION).zip
73 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(VERSION)_$(SUB_VERSION).zip
81 @echo "### Build $(TARGET) (version $(VERSION), subversion $(SUB_VERSION) - $(BUILD_MODE))";
82 @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/$(TARGET)$(EXT) -ldflags "$(GO_LDFLAGS) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" -gcflags "$(GO_GCFLAGS)" .
85 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
88 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
91 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
95 rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
99 rm -rf $(LOCAL_BINDIR) $(ROOT_SRCDIR)/tools glide.lock vendor
104 @mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/*.sh scripts/xds-utils $(LOCAL_BINDIR)
108 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile clean build
110 package: clean vendor build
111 @mkdir -p $(PACKAGE_DIR)/$(TARGET)
112 @cp -a $(LOCAL_BINDIR)/*cli$(EXT) $(PACKAGE_DIR)/$(TARGET)
113 @cp -r $(ROOT_SRCDIR)/conf.d $(ROOT_SRCDIR)/scripts $(PACKAGE_DIR)/$(TARGET)
114 cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./$(TARGET)
118 @echo "# Build linux amd64..."
119 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
120 @echo "# Build windows amd64..."
121 GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
122 @echo "# Build darwin amd64..."
123 GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
124 make -f $(ROOT_SRCDIR)/Makefile clean
128 @test -e $(LOCAL_BINDIR)/$(TARGET)$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
129 export DESTDIR=$(DESTDIR) && $(ROOT_SRCDIR)/scripts/install.sh
133 export DESTDIR=$(DESTDIR) && $(ROOT_SRCDIR)/scripts/install.sh uninstall
135 vendor: tools/glide glide.yaml
136 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
139 (cd vendor/github.com/iotbzh && \
140 rm -rf xds-common && ln -s ../../../../xds-common && \
141 rm -rf xds-agent && ln -s ../../../../xds-agent )
145 @test -f $(LOCAL_TOOLSDIR)/glide || { \
146 echo "Downloading glide"; \
147 mkdir -p $(LOCAL_TOOLSDIR); \
148 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
153 @test "$(CHECKGOVER)" = "true" || { echo $(CHECKERRMSG); exit 1; }
158 @echo "Main supported rules:"
159 @echo " all (default)"
164 @echo " install / uninstall"
167 @echo "Influential make variables:"
168 @echo " V - Build verbosity {0,1,2}."
169 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."