1 ###########################################################################
2 # Copyright 2017-2018 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 # Syncthing version to install
24 SYNCTHING_VERSION = 0.14.38
25 SYNCTHING_INOTIFY_VERSION = 0.8.7
28 # Retrieve git tag/commit to set version & sub-version strings
29 GIT_DESC := $(shell git describe --always --tags)
30 VERSION := $(firstword $(subst -, ,$(GIT_DESC)))
31 ifeq (-,$(findstring -,$(GIT_DESC)))
32 SUB_VERSION := $(subst $(VERSION)-,,$(GIT_DESC))
35 VERSION := unknown-dev
37 ifeq ($(SUB_VERSION), )
38 SUB_VERSION := $(shell date +'%Y-%m-%d_%H%M%S')
41 # for backward compatibility
42 ifneq ($(origin INSTALL_DIR), undefined)
43 DESTDIR := $(INSTALL_DIR)
45 ifneq ($(origin INSTALL_WEBAPP_DIR), undefined)
46 DESTDIR_WWW := $(INSTALL_WEBAPP_DIR)
49 # Configurable variables for installation (default /opt/AGL/...)
50 ifeq ($(origin DESTDIR), undefined)
51 DESTDIR := /opt/AGL/xds/server
53 ifeq ($(origin DESTDIR_WWW), undefined)
54 DESTDIR_WWW := $(DESTDIR)/www
57 HOST_GOOS=$(shell go env GOOS)
58 HOST_GOARCH=$(shell go env GOARCH)
59 ARCH=$(HOST_GOOS)-$(HOST_GOARCH)
60 REPOPATH=gerrit.automotivelinux.org/gerrit/src/xds/$(TARGET)
63 ifeq ($(HOST_GOOS), windows)
67 mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
68 ROOT_SRCDIR := $(patsubst %/,%,$(dir $(mkfile_path)))
69 ROOT_GOPRJ := $(abspath $(ROOT_SRCDIR)/../../../../../..)
70 LOCAL_BINDIR := $(ROOT_SRCDIR)/bin
71 LOCAL_TOOLSDIR := $(ROOT_SRCDIR)/tools/${HOST_GOOS}
72 PACKAGE_DIR := $(ROOT_SRCDIR)/package
74 export GOPATH := $(shell go env GOPATH):$(ROOT_GOPRJ)
75 export PATH := $(PATH):$(LOCAL_TOOLSDIR)
78 GOVERSION := $(shell go version |grep -o '[0-9\.]*'|head -n 1)
79 GOVERMAJ := $(shell echo $(GOVERSION) |cut -f1 -d.)
80 GOVERMIN := $(shell echo $(GOVERSION) |cut -f2 -d.)
81 CHECKGOVER := $(shell [ $(GOVERMAJ) -gt 1 -o \( $(GOVERMAJ) -eq 1 -a $(GOVERMIN) -ge 8 \) ] && echo true)
82 CHECKERRMSG := "ERROR: Go version 1.8.1 or higher is requested (current detected version: $(GOVERSION))."
88 # Release or Debug mode
89 ifeq ($(filter 1,$(RELEASE) $(REL)),)
91 # disable compiler optimizations and inlining
93 BUILD_MODE="Debug mode"
94 WEBAPP_BUILD_RULE=build
96 # optimized code without debug info
99 BUILD_MODE="Release mode"
100 WEBAPP_BUILD_RULE=build:prod
103 ifeq ($(SUB_VERSION), )
104 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(VERSION).zip
106 # only use dot as separator to allow rpm packaging (see version .spec file)
107 PK_VER := $(subst _,.,$(subst -,,$(VERSION)))
108 PK_SBVER := $(subst _,.,$(subst -,,$(SUB_VERSION)))
109 PACKAGE_ZIPFILE := $(TARGET)_$(ARCH)-$(PK_VER).$(PK_SBVER).zip
113 all: tools/syncthing build
116 build: checkgover vendor xds webapp
118 xds: scripts tools/syncthing/copytobin
119 @echo "### Build XDS server (version $(VERSION), subversion $(SUB_VERSION)) - $(BUILD_MODE)";
120 @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)" .
125 GOCACHE=off go test --race ./test -v
127 GOCACHE=off go test --race ./test -v -run $(name)
131 go vet $(shell $(LOCAL_TOOLSDIR)/glide novendor)
134 go fmt $(shell $(LOCAL_TOOLSDIR)/glide novendor)
136 run: build/xds tools/syncthing/copytobin
137 $(LOCAL_BINDIR)/$(TARGET)$(EXT) --log info $(XDS_SERVER_RUN_ARGS)
139 debug: build/xds tools/syncthing/copytobin
140 $(LOCAL_BINDIR)/$(TARGET)$(EXT) --log debug $(XDS_SERVER_DEBUG_ARGS)
144 rm -rf $(LOCAL_BINDIR)/* $(ROOT_SRCDIR)/debug $(ROOT_GOPRJ)/pkg/*/$(REPOPATH) $(PACKAGE_DIR)
148 (cd $(ROOT_SRCDIR) && rm -rf $(LOCAL_BINDIR) ./tools ./glide.lock ./vendor ./*.zip ./webapp/dist ./webapp/node_modules ./scripts/sdks/agl/sdks_*.json)
150 webapp: webapp/install
151 mkdir -p $(ROOT_SRCDIR)/webapp/dist $(ROOT_SRCDIR)/webapp/dist/fonts
152 (cd $(ROOT_SRCDIR)/webapp && cp -a ./assets ./src/index.html ./node_modules/font-awesome/css/font-awesome.min.css ./dist/)
153 (cd $(ROOT_SRCDIR)/webapp && cp -a ./node_modules/font-awesome/fonts/* ./dist/fonts/)
156 (cd webapp && npm install)
157 @[ -d ${DESTDIR}/usr ] && { echo "Removing unwanted ${DESTDIR}/usr directory"; rm -rf ${DESTDIR}/usr; } || true
161 @mkdir -p $(LOCAL_BINDIR) && cp -rf scripts/xds-utils scripts/sdks $(LOCAL_BINDIR)
165 cat $(ROOT_SRCDIR)/conf.d/etc/xds/server/server-config.json \
166 | sed -e s,"www","$(DESTDIR_WWW)",g \
167 > $(DESTDIR)/server-config.json.in
171 @test -e $(LOCAL_BINDIR)/xds-server$(EXT) -a -d webapp/dist || { echo "Please execute first: make all"; exit 1; }
172 @test -d $(LOCAL_BINDIR)/xds-utils || { echo "Please execute first: make all"; exit 1; }
173 @test -e $(LOCAL_BINDIR)/syncthing$(EXT) -a -e $(LOCAL_BINDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make all"; exit 1; }
174 mkdir -p $(DESTDIR) \
175 && cp -a $(LOCAL_BINDIR)/* $(DESTDIR)
176 mkdir -p $(DESTDIR_WWW) \
177 && cp -a webapp/dist/* $(DESTDIR_WWW)
181 make -f $(ROOT_SRCDIR)/Makefile all install DESTDIR=$(PACKAGE_DIR)/xds-server
182 make -f $(ROOT_SRCDIR)/Makefile conffile DESTDIR=$(PACKAGE_DIR)/xds-server DESTDIR_WWW=www
183 cp -r $(ROOT_SRCDIR)/conf.d $(PACKAGE_DIR)/xds-server
184 rm -f $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE)
185 (cd $(PACKAGE_DIR) && zip -r $(ROOT_SRCDIR)/$(PACKAGE_ZIPFILE) ./xds-server)
187 # On support Linux for now
190 @echo "# Build linux amd64..."
191 GOOS=linux GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile _package
192 make -f $(ROOT_SRCDIR)/Makefile clean
197 vendor: tools/glide glide.yaml
198 $(LOCAL_TOOLSDIR)/glide install --strip-vendor
201 (cd vendor/gerrit.automotivelinux.org/gerrit/src/xds && \
202 rm -rf xds-common.git && ln -s ../../../../../../xds-common xds-common.git )
206 @test -f $(LOCAL_TOOLSDIR)/glide || { \
207 echo "Downloading glide"; \
208 mkdir -p $(LOCAL_TOOLSDIR); \
209 curl --silent --connect-timeout 60 --retry 3 -L https://glide.sh/get | GOBIN=$(LOCAL_TOOLSDIR) sh; \
212 .PHONY: tools/syncthing
214 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { \
215 mkdir -p $(LOCAL_TOOLSDIR); \
216 DESTDIR=$(LOCAL_TOOLSDIR) \
217 SYNCTHING_VERSION=$(SYNCTHING_VERSION) \
218 SYNCTHING_INOTIFY_VERSION=$(SYNCTHING_INOTIFY_VERSION) \
219 ./scripts/xds-utils/get-syncthing.sh; }
222 tools/syncthing/copytobin:
223 @test -e $(LOCAL_TOOLSDIR)/syncthing$(EXT) -a -e $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) || { echo "Please execute first: make tools/syncthing\n"; exit 1; }
224 @mkdir -p $(LOCAL_BINDIR)
225 @cp -f $(LOCAL_TOOLSDIR)/syncthing$(EXT) $(LOCAL_TOOLSDIR)/syncthing-inotify$(EXT) $(LOCAL_BINDIR)
229 @test "$(CHECKGOVER)" = "true" || { echo $(CHECKERRMSG); exit 1; }
234 @echo "Main supported rules:"
235 @echo " all (default)"
242 @echo "Influential make variables:"
243 @echo " V - Build verbosity {0,1,2}."
244 @echo " BUILD_ENV_FLAGS - Environment added to 'go build'."