1 # Makefile used to build XDS Agent
7 # Syncthing version to install
8 SYNCTHING_VERSION = 0.14.38
9 SYNCTHING_INOTIFY_VERSION = 0.8.7
12 # Retrieve git tag/commit to set version & sub-version strings
13 GIT_DESC := $(shell git describe --always --tags)
14 VERSION := $(firstword $(subst -, ,$(GIT_DESC)))
15 ifeq (-,$(findstring -,$(GIT_DESC)))
16 SUB_VERSION := $(subst $(VERSION)-,,$(GIT_DESC))
19 VERSION := unknown-dev
21 ifeq ($(SUB_VERSION), )
22 SUB_VERSION := $(shell date +'%Y-%m-%d_%H%M%S')
25 # Configurable variables for installation (default /opt/AGL/...)
26 ifeq ($(origin DESTDIR), undefined)
27 DESTDIR := /opt/AGL/xds/agent
29 ifeq ($(origin DESTDIR_WWW), undefined)
30 DESTDIR_WWW := $(DESTDIR)/www
33 HOST_GOOS=$(shell go env GOOS)
34 HOST_GOARCH=$(shell go env GOARCH)
35 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
36 REPOPATH=github.com/iotbzh/$(TARGET)
39 ifeq ($(HOST_GOOS), windows)
43 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
44 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
45 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
46 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
47 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
48 PACKAGE_DIR := $(ROOT_SRCDIR)/package
50 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
51 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
54 GOVERSION := $(shell go version |grep -o '[0-9\.]*'|head -n 1)
55 GOVERMAJ := $(shell echo $(GOVERSION) |cut -f1 -d.)
56 GOVERMIN := $(shell echo $(GOVERSION) |cut -f2 -d.)
57 CHECKGOVER := $(shell [ $(GOVERMAJ) -gt 1 -o \( $(GOVERMAJ) -eq 1 -a $(GOVERMIN) -ge 8 \) ] && echo true)
58 CHECKERRMSG := "ERROR: Go version 1.8.1 or higher is requested (current detected version: $(GOVERSION))."
64 # Release or Debug mode
65 ifeq ($(filter 1,$(RELEASE) $(REL)),)
67 # disable compiler optimizations and inlining
69 BUILD_MODE="Debug mode"
70 WEBAPP_BUILD_RULE=build
72 # optimized code without debug info
75 BUILD_MODE="Release mode"
76 WEBAPP_BUILD_RULE=build:prod
79 ifeq ($(SUB_VERSION), )
80 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(VERSION).zip
82 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(VERSION)_$(SUB_VERSION).zip
86 all: tools/syncthing build
89 build: checkgover vendor xds webapp
91 xds: scripts tools/syncthing/copytobin
92 @echo "### Build XDS agent (version $(VERSION), subversion $(SUB_VERSION)) - $(BUILD_MODE)";
93 @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)" .
96 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
99 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
102 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
104 run: build/xds tools/syncthing/copytobin
105 $(LOCAL_BINDIR)/$(TARGET)$(EXT) --log info -c agent-config.json.in
107 debug: build/xds tools/syncthing/copytobin
108 $(LOCAL_BINDIR)/$(TARGET)$(EXT) --log debug -c agent-config.json.in
112 rm -rf $(LOCAL_BINDIR)/* $(ROOT_SRCDIR)/debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
116 cd $(ROOT_SRCDIR) && rm -rf $(LOCAL_BINDIR) ./tools ./glide.lock ./vendor ./*.zip ./webapp/node_modules ./webapp/dist
118 webapp: webapp/install
119 cd webapp && npm run $(WEBAPP_BUILD_RULE)
122 cd webapp && npm run watch
125 (cd webapp && npm install)
126 @if [ -d ${DESTDIR}/usr/local/etc ]; then rm -rf ${DESTDIR}/usr; fi
130 @test -e $(LOCAL_BINDIR)/$(TARGET)$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
131 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
132 export DESTDIR=$(DESTDIR) && export DESTDIR_WWW=$(DESTDIR_WWW) && $(ROOT_SRCDIR)/scripts/install.sh
136 export DESTDIR=$(DESTDIR) && export DESTDIR_WWW=$(DESTDIR_WWW) && $(ROOT_SRCDIR)/scripts/install.sh uninstall
138 package: clean tools/syncthing vendor build
139 @mkdir -p $(PACKAGE_DIR)/$(TARGET)/www $(PACKAGE_DIR)/scripts
140 @cp -a $(LOCAL_BINDIR)/* $(PACKAGE_DIR)/$(TARGET)/
141 @cp -a webapp/dist/* $(PACKAGE_DIR)/$(TARGET)/www/
142 @cp -r $(ROOT_SRCDIR)/conf.d $(ROOT_SRCDIR)/scripts $(PACKAGE_DIR)/$(TARGET)/
143 @cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./$(TARGET)
144 @echo "### Package $(PACKAGE_ZIPFILE) has been successfuly built - $(BUILD_MODE)"
148 @echo "# Build linux amd64..."
149 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
150 @echo "# Build windows amd64..."
151 GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
152 @echo "# Build darwin amd64..."
153 GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
154 make -f $(ROOT_SRCDIR)/Makefile clean
156 vendor: tools/glide glide.yaml
157 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
160 (cd vendor/github.com/iotbzh && \
161 rm -rf xds-common && ln -s ../../../../xds-common \
162 rm -rf xds-server && ln -s ../../../../xds-server )
166 @test -f $(LOCAL_TOOLSDIR)/glide || { \
167 echo "Downloading glide"; \
168 mkdir -p $(LOCAL_TOOLSDIR); \
169 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
172 .PHONY: tools/syncthing
174 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
175 mkdir -p $(LOCAL_TOOLSDIR); \
176 DESTDIR=$(LOCAL_TOOLSDIR) \
177 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
178 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
179 ./scripts/get-syncthing.sh; }
181 .PHONY: tools/syncthing/copytobin
182 tools/syncthing/copytobin:
183 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
184 @mkdir -p $(LOCAL_BINDIR)
185 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
189 @test "$(CHECKGOVER)" = "true" || { echo $(CHECKERRMSG); exit 1; }
194 @echo "Main supported rules:"
195 @echo " all (default)"
203 @echo "Influential make variables:"
204 @echo " V - Build verbosity {0,1,2}."
205 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."