1 ###########################################################################
2 # Copyright 2017 IoT.bzh
4 # author: Sebastien Douheret <sebastien@iot.bzh>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 ###########################################################################
23 # Retrieve git tag/commit to set version & sub-version strings
24 GIT_DESC := $(shell git describe --always --tags)
25 VERSION := $(firstword $(subst -, ,$(GIT_DESC)))
26 SUB_VERSION := $(subst $(VERSION)-,,$(GIT_DESC))
28 VERSION := unknown-dev
30 ifeq ($(SUB_VERSION), )
31 SUB_VERSION := $(shell date +'%Y-%m-%d_%H%M%S')
34 # Configurable variables for installation (default /opt/AGL/...)
35 ifeq ($(origin DESTDIR), undefined)
36 DESTDIR := /opt/AGL/xds/gdb
39 HOST_GOOS=$(shell go env GOOS)
40 HOST_GOARCH=$(shell go env GOARCH)
41 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
42 REPOPATH=github.com/iotbzh/$(TARGET)
45 ifeq ($(HOST_GOOS), windows)
49 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
50 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
51 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
52 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
53 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
54 PACKAGE_DIR := $(ROOT_SRCDIR)/package
56 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
57 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
62 # Release or Debug mode
63 ifeq ($(filter 1,$(RELEASE) $(REL)),)
65 # disable compiler optimizations and inlining
67 BUILD_MODE="Debug mode"
69 # optimized code without debug info
72 BUILD_MODE="Release mode"
76 ifeq ($(SUB_VERSION), )
77 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(VERSION).zip
79 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(VERSION)_$(SUB_VERSION).zip
87 @echo "### Build $(TARGET) (version $(VERSION), subversion $(SUB_VERSION) - $(BUILD_MODE))";
88 @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)" .
91 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
94 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
97 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
101 rm -rf $(LOCAL_BINDIR)/* debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
105 rm -rf $(LOCAL_BINDIR) $(ROOT_SRCDIR)/tools glide.lock vendor $(ROOT_SRCDIR)/*.zip
109 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile clean build
111 package: clean vendor build
112 @mkdir -p $(PACKAGE_DIR)/$(TARGET)
113 @cp -a $(LOCAL_BINDIR)/*gdb$(EXT) $(PACKAGE_DIR)/$(TARGET)
114 @cp -r $(ROOT_SRCDIR)/conf.d $(ROOT_SRCDIR)/scripts $(PACKAGE_DIR)/$(TARGET)
115 cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./$(TARGET)
119 @echo "# Build linux amd64..."
120 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
121 @echo "# Build windows amd64..."
122 GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
123 @echo "# Build darwin amd64..."
124 GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
125 make -f $(ROOT_SRCDIR)/Makefile clean
129 @test -e $(LOCAL_BINDIR)/$(TARGET)$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
130 export DESTDIR=$(DESTDIR) && $(ROOT_SRCDIR)/scripts/install.sh
134 export DESTDIR=$(DESTDIR) && $(ROOT_SRCDIR)/scripts/install.sh uninstall
136 vendor: tools/glide glide.yaml
137 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
140 (cd vendor/github.com/iotbzh && \
141 rm -rf xds-common && ln -s ../../../../xds-common && \
142 rm -rf xds-agent && ln -s ../../../../xds-agent )
146 @test -f $(LOCAL_TOOLSDIR)/glide || { \
147 echo "Downloading glide"; \
148 mkdir -p $(LOCAL_TOOLSDIR); \
149 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
153 @echo "Main supported rules:"
154 @echo " all (default)"
159 @echo " install / uninstall"
162 @echo "Influential make variables:"
163 @echo " V - Build verbosity {0,1,2}."
164 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."