X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=Makefile;h=ca04632b009a091738c5b2e54ea35b1b419e48c0;hb=840bfc5fd01bf036344bd687d2e40e0fc19f39e4;hp=7ba91638ed0e78976550411924740c419c6f5beb;hpb=c9bfbf5461e3ecbdd2aff84095cba695bdfe0e26;p=src%2Fxds%2Fxds-agent.git diff --git a/Makefile b/Makefile index 7ba9163..ca04632 100644 --- a/Makefile +++ b/Makefile @@ -13,12 +13,19 @@ SYNCTHING_INOTIFY_VERSION = master # Retrieve git tag/commit to set sub-version string ifeq ($(origin SUB_VERSION), undefined) - SUB_VERSION := $(shell git describe --tags --always | sed 's/^v//') - ifeq ($(SUB_VERSION), ) - SUB_VERSION=unknown-dev + SUB_VERSION := $(shell git describe --tags 2>/dev/null | sed 's/^v//') + ifneq ($(SUB_VERSION), ) + VERSION := $(firstword $(subst -, ,$(SUB_VERSION))) + SUB_VERSION := $(word 2,$(subst -, ,$(SUB_VERSION))) + else + SUB_VERSION := $(shell git describe --tags --always | sed 's/^v//') + ifeq ($(SUB_VERSION), ) + SUB_VERSION := unknown-dev + endif endif endif + # Configurable variables for installation (default /usr/local/...) ifeq ($(origin INSTALL_DIR), undefined) INSTALL_DIR := /usr/local/bin @@ -29,11 +36,16 @@ HOST_GOARCH=$(shell go env GOARCH) ARCH=$(HOST_GOOS)-$(HOST_GOARCH) REPOPATH=github.com/iotbzh/xds-agent +EXT= +ifeq ($(HOST_GOOS), windows) + EXT=.exe +endif + mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path))) ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..) LOCAL_BINDIR := $(ROOT_SRCDIR)/bin -LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools +LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS} PACKAGE_DIR := $(ROOT_SRCDIR)/package export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ) @@ -42,17 +54,43 @@ export PATH := $(PATH):$(LOCAL_TOOLSDIR) VERBOSE_1 := -v VERBOSE_2 := -v -x +# Release or Debug mode +ifeq ($(filter 1,$(RELEASE) $(REL)),) + GORELEASE= + BUILD_MODE="Debug mode" +else + # optimized code without debug info + GORELEASE= -s -w + BUILD_MODE="Release mode" +endif + +ifeq ($(SUB_VERSION), ) + PACKAGE_ZIPFILE := xds-agent_$(ARCH)-v$(VERSION).zip +else + PACKAGE_ZIPFILE := xds-agent_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip +endif + + all: tools/syncthing build build: vendor tools/syncthing/copytobin - @echo "### Build XDS agent (version $(VERSION), subversion $(SUB_VERSION))"; - @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-agent -ldflags "-X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" . + @echo "### Build XDS agent (version $(VERSION), subversion $(SUB_VERSION)) - $(BUILD_MODE)"; + @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-agent$(EXT) -ldflags "$(GORELEASE) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" . -package: clean build +package: clean tools/syncthing build @mkdir -p $(PACKAGE_DIR)/xds-agent @cp agent-config.json.in $(PACKAGE_DIR)/xds-agent/agent-config.json @cp -a $(LOCAL_BINDIR)/* $(PACKAGE_DIR)/xds-agent - cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/xds-agent_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip ./xds-agent + cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-agent + +.PHONY: package-all +package-all: + @echo "# Build linux amd64..." + GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package + @echo "# Build windows amd64..." + GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package + @echo "# Build darwin amd64..." + GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package test: tools/glide go test --race $(shell ./tools/glide novendor) @@ -64,10 +102,10 @@ fmt: tools/glide go fmt $(shell ./tools/glide novendor) run: build/xds tools/syncthing/copytobin - $(LOCAL_BINDIR)/xds-agent --log info -c agent-config.json.in + $(LOCAL_BINDIR)/xds-agent$(EXT) --log info -c agent-config.json.in debug: build/xds tools/syncthing/copytobin - $(LOCAL_BINDIR)/xds-agent --log debug -c agent-config.json.in + $(LOCAL_BINDIR)/xds-agent$(EXT) --log debug -c agent-config.json.in .PHONY: clean clean: @@ -75,7 +113,7 @@ clean: .PHONY: distclean distclean: clean - rm -rf $(LOCAL_BINDIR) tools glide.lock vendor + rm -rf $(LOCAL_BINDIR) tools glide.lock vendor $(ROOT_SRCDIR)/*.zip .PHONY: install install: all @@ -91,7 +129,8 @@ tools/glide: .PHONY: tools/syncthing tools/syncthing: - @test -e $(LOCAL_TOOLSDIR)/syncthing -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify || { \ + @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \ + mkdir -p $(LOCAL_TOOLSDIR); \ DESTDIR=$(LOCAL_TOOLSDIR) \ SYNCTHING_VERSION=$(SYNCTHING_VERSION) \ SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \ @@ -99,8 +138,9 @@ tools/syncthing: .PHONY: tools/syncthing/copytobin: - @test -e $(LOCAL_TOOLSDIR)/syncthing -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify || { echo "Please execute first: make tools/syncthing\n"; exit 1; } - @cp -f $(LOCAL_TOOLSDIR)/syncthing* $(LOCAL_BINDIR) + @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; } + @mkdir -p $(LOCAL_BINDIR) + @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR) .PHONY: help help: