1 # Makefile used to build XDS Agent
3 # Syncthing version to install
4 SYNCTHING_VERSION = 0.14.38
5 SYNCTHING_INOTIFY_VERSION = 0.8.7
8 # Retrieve git tag/commit to set version & sub-version strings
9 GIT_DESC := $(shell git describe --always --tags)
10 VERSION := $(firstword $(subst -, ,$(GIT_DESC)))
11 SUB_VERSION := $(subst $(VERSION)-,,$(GIT_DESC))
13 VERSION := unknown-dev
15 ifeq ($(SUB_VERSION), )
16 SUB_VERSION := $(shell date +'%Y-%m-%d_%H%M%S')
19 # Configurable variables for installation (default /opt/AGL/...)
20 ifeq ($(origin DESTDIR), undefined)
21 DESTDIR := /opt/AGL/xds/agent
23 ifeq ($(origin DESTDIR_WWW), undefined)
24 DESTDIR_WWW := $(DESTDIR)/www
27 HOST_GOOS=$(shell go env GOOS)
28 HOST_GOARCH=$(shell go env GOARCH)
29 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
30 REPOPATH=github.com/iotbzh/xds-agent
33 ifeq ($(HOST_GOOS), windows)
37 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
38 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
39 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../..)
40 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
41 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
42 PACKAGE_DIR := $(ROOT_SRCDIR)/package
44 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
45 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
50 # Release or Debug mode
51 ifeq ($(filter 1,$(RELEASE) $(REL)),)
53 # disable compiler optimizations and inlining
55 BUILD_MODE="Debug mode"
57 # optimized code without debug info
60 BUILD_MODE="Release mode"
63 ifeq ($(SUB_VERSION), )
64 PACKAGE_ZIPFILE := xds-agent_$(ARCH)-v$(VERSION).zip
66 PACKAGE_ZIPFILE := xds-agent_$(ARCH)-v$(VERSION)_$(SUB_VERSION).zip
70 all: tools/syncthing build
73 build: vendor xds webapp
75 xds: scripts tools/syncthing/copytobin
76 @echo "### Build XDS agent (version $(VERSION), subversion $(SUB_VERSION)) - $(BUILD_MODE)";
77 @cd $(ROOT_SRCDIR); $(BUILD_ENV_FLAGS) go build $(VERBOSE_$(V)) -i -o $(LOCAL_BINDIR)/xds-agent$(EXT) -ldflags "$(GO_LDFLAGS) -X main.AppVersion=$(VERSION) -X main.AppSubVersion=$(SUB_VERSION)" -gcflags "$(GO_GCFLAGS)" .
80 go test --race $(shell $(LOCAL_TOOLSDIR)/glide novendor)
83 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
86 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
88 run: build/xds tools/syncthing/copytobin
89 $(LOCAL_BINDIR)/xds-agent$(EXT) --log info -c agent-config.json.in
91 debug: build/xds tools/syncthing/copytobin
92 $(LOCAL_BINDIR)/xds-agent$(EXT) --log debug -c agent-config.json.in
96 rm -rf $(LOCAL_BINDIR)/* $(ROOT_SRCDIR)/debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
100 cd $(ROOT_SRCDIR) && rm -rf $(LOCAL_BINDIR) ./tools ./glide.lock ./vendor ./*.zip ./webapp/node_modules ./webapp/dist
102 webapp: webapp/install
103 (cd webapp && npm run build)
106 (cd webapp && npm run watch)
109 (cd webapp && npm install)
110 @if [ -d ${DESTDIR}/usr/local/etc ]; then rm -rf ${DESTDIR}/usr; fi
114 @test -e $(LOCAL_BINDIR)/xds-agent$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
115 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all\n"; exit 1; }
116 export DESTDIR=$(DESTDIR) && export DESTDIR_WWW=$(DESTDIR_WWW) && $(ROOT_SRCDIR)/scripts/install.sh
120 export DESTDIR=$(DESTDIR) && export DESTDIR_WWW=$(DESTDIR_WWW) && $(ROOT_SRCDIR)/scripts/install.sh uninstall
122 package: clean tools/syncthing vendor build
123 @mkdir -p $(PACKAGE_DIR)/xds-agent $(PACKAGE_DIR)/scripts
124 @cp -a $(LOCAL_BINDIR)/* $(PACKAGE_DIR)/xds-agent
125 @cp -r $(ROOT_SRCDIR)/conf.d $(ROOT_SRCDIR)/scripts $(PACKAGE_DIR)/xds-agent
126 cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-agent
130 @echo "# Build linux amd64..."
131 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
132 @echo "# Build windows amd64..."
133 GOOS=windows GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
134 @echo "# Build darwin amd64..."
135 GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package
136 make -f $(ROOT_SRCDIR)/Makefile clean
138 vendor: tools/glide glide.yaml
139 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
142 (cd vendor/github.com/iotbzh && \
143 rm -rf xds-common && ln -s ../../../../xds-common )
147 @test -f $(LOCAL_TOOLSDIR)/glide || { \
148 echo "Downloading glide"; \
149 mkdir -p $(LOCAL_TOOLSDIR); \
150 curl --silent -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
153 .PHONY: tools/syncthing
155 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
156 mkdir -p $(LOCAL_TOOLSDIR); \
157 DESTDIR=$(LOCAL_TOOLSDIR) \
158 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
159 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
160 ./scripts/get-syncthing.sh; }
162 .PHONY: tools/syncthing/copytobin
163 tools/syncthing/copytobin:
164 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
165 @mkdir -p $(LOCAL_BINDIR)
166 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
170 @echo "Main supported rules:"
171 @echo " all (default)"
179 @echo "Influential make variables:"
180 @echo " V - Build verbosity {0,1,2}."
181 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."