-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
278 lines (231 loc) · 8.53 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
GO ?= go
DOMAIN=incus
POFILES=$(wildcard po/*.po)
MOFILES=$(patsubst %.po,%.mo,$(POFILES))
LINGUAS=$(basename $(POFILES))
POTFILE=po/$(DOMAIN).pot
VERSION=$(shell grep "var Version" shared/version/flex.go | cut -d'"' -f2)
ARCHIVE=incus-$(VERSION).tar
HASH := \#
TAG_SQLITE3=$(shell printf "$(HASH)include <cowsql.h>\nvoid main(){cowsql_node_id n = 1;}" | $(CC) ${CGO_CFLAGS} -o /dev/null -xc - >/dev/null 2>&1 && echo "libsqlite3")
GOPATH ?= $(shell $(GO) env GOPATH)
CGO_LDFLAGS_ALLOW ?= (-Wl,-wrap,pthread_create)|(-Wl,-z,now)
SPHINXENV=doc/.sphinx/venv/bin/activate
ifneq "$(wildcard vendor)" ""
RAFT_PATH=$(CURDIR)/vendor/raft
COWSQL_PATH=$(CURDIR)/vendor/cowsql
else
RAFT_PATH=$(GOPATH)/deps/raft
COWSQL_PATH=$(GOPATH)/deps/cowsql
endif
# raft
.PHONY: default
default: build
.PHONY: build
build:
ifeq "$(TAG_SQLITE3)" ""
@echo "Missing cowsql, run \"make deps\" to setup."
exit 1
endif
CC="$(CC)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" $(GO) install -v -tags "$(TAG_SQLITE3)" $(DEBUG) ./...
CGO_ENABLED=0 $(GO) install -v -tags netgo ./cmd/incus-migrate
CGO_ENABLED=0 $(GO) install -v -tags agent,netgo ./cmd/incus-agent
@echo "Incus built successfully"
.PHONY: client
client:
$(GO) install -v -tags "$(TAG_SQLITE3)" $(DEBUG) ./cmd/incus
@echo "Incus client built successfully"
.PHONY: incus-agent
incus-agent:
CGO_ENABLED=0 $(GO) install -v -tags agent,netgo ./cmd/incus-agent
@echo "Incus agent built successfully"
.PHONY: incus-migrate
incus-migrate:
CGO_ENABLED=0 $(GO) install -v -tags netgo ./cmd/incus-migrate
@echo "Incus migration tool built successfully"
.PHONY: incus-doc
incus-doc:
@$(GO) version > /dev/null 2>&1 || { echo "go is not installed for incus-doc installation."; exit 1; }
cd incusd/config/generate && CGO_ENABLED=0 $(GO) build -o $(GOPATH)/bin/incus-doc
@echo "Incus documentation generator built successfully"
.PHONY: deps
deps:
@if [ ! -e "$(RAFT_PATH)" ]; then \
git clone --depth=1 "https://github.com/canonical/raft" "$(RAFT_PATH)"; \
elif [ -e "$(RAFT_PATH)/.git" ]; then \
cd "$(RAFT_PATH)"; git pull; \
fi
cd "$(RAFT_PATH)" && \
autoreconf -i && \
./configure && \
make
# cowsql
@if [ ! -e "$(COWSQL_PATH)" ]; then \
git clone --depth=1 "https://github.com/cowsql/cowsql" "$(COWSQL_PATH)"; \
elif [ -e "$(COWSQL_PATH)/.git" ]; then \
cd "$(COWSQL_PATH)"; git pull; \
fi
cd "$(COWSQL_PATH)" && \
autoreconf -i && \
PKG_CONFIG_PATH="$(RAFT_PATH)" ./configure && \
make CFLAGS="-I$(RAFT_PATH)/include/" LDFLAGS="-L$(RAFT_PATH)/.libs/"
# environment
@echo ""
@echo "Please set the following in your environment (possibly ~/.bashrc)"
@echo "export CGO_CFLAGS=\"-I$(RAFT_PATH)/include/ -I$(COWSQL_PATH)/include/\""
@echo "export CGO_LDFLAGS=\"-L$(RAFT_PATH)/.libs -L$(COWSQL_PATH)/.libs/\""
@echo "export LD_LIBRARY_PATH=\"$(RAFT_PATH)/.libs/:$(COWSQL_PATH)/.libs/\""
@echo "export CGO_LDFLAGS_ALLOW=\"(-Wl,-wrap,pthread_create)|(-Wl,-z,now)\""
.PHONY: update
update:
ifneq "$(INCUS_OFFLINE)" ""
@echo "The update target cannot be run in offline mode."
exit 1
endif
$(GO) get -t -v -d -u ./...
$(GO) mod tidy
@echo "Dependencies updated"
.PHONY: update-protobuf
update-protobuf:
protoc --go_out=. ./incusd/migration/migrate.proto
.PHONY: update-schema
update-schema:
cd incusd/db/generate && $(GO) build -o $(GOPATH)/bin/incus-generate -tags "$(TAG_SQLITE3)" $(DEBUG) && cd -
$(GO) generate ./...
gofmt -s -w ./incusd/db/
goimports -w ./incusd/db/
@echo "Code generation completed"
.PHONY: update-api
update-api:
ifeq "$(INCUS_OFFLINE)" ""
(cd / ; $(GO) install -v -x github.com/go-swagger/go-swagger/cmd/swagger@latest)
endif
swagger generate spec -o doc/rest-api.yaml -w ./incusd -m
.PHONY: doc-setup
doc-setup:
@echo "Setting up documentation build environment"
python3 -m venv doc/.sphinx/venv
. $(SPHINXENV) ; pip install --upgrade -r doc/.sphinx/requirements.txt
rm -Rf doc/html
.PHONY: doc
doc: incus-doc doc-setup doc-incremental
.PHONY: doc-incremental
doc-incremental:
@echo "Build the documentation"
$(GOPATH)/bin/incus-doc ./incusd -y ./doc/config_options.yaml -t ./doc/config_options.txt
. $(SPHINXENV) ; sphinx-build -c doc/ -b dirhtml doc/ doc/html/ -w doc/.sphinx/warnings.txt
.PHONY: doc-serve
doc-serve:
cd doc/html; python3 -m http.server 8001
.PHONY: doc-spellcheck
doc-spellcheck: doc
. $(SPHINXENV) ; python3 -m pyspelling -c doc/.sphinx/.spellcheck.yaml
.PHONY: doc-linkcheck
doc-linkcheck: doc-setup
. $(SPHINXENV) ; sphinx-build -c doc/ -b linkcheck doc/ doc/html/
.PHONY: doc-lint
doc-lint:
doc/.sphinx/.markdownlint/doc-lint.sh
.PHONY: debug
debug:
ifeq "$(TAG_SQLITE3)" ""
@echo "Missing custom libsqlite3, run \"make deps\" to setup."
exit 1
endif
CC="$(CC)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" $(GO) install -v -tags "$(TAG_SQLITE3) logdebug" $(DEBUG) ./...
CGO_ENABLED=0 $(GO) install -v -tags "netgo,logdebug" ./cmd/incus-migrate
CGO_ENABLED=0 $(GO) install -v -tags "agent,netgo,logdebug" ./cmd/incus-agent
@echo "Incus built successfully"
.PHONY: nocache
nocache:
ifeq "$(TAG_SQLITE3)" ""
@echo "Missing custom libsqlite3, run \"make deps\" to setup."
exit 1
endif
CC="$(CC)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" $(GO) install -a -v -tags "$(TAG_SQLITE3)" $(DEBUG) ./...
CGO_ENABLED=0 $(GO) install -a -v -tags netgo ./cmd/incus-migrate
CGO_ENABLED=0 $(GO) install -a -v -tags agent,netgo ./cmd/incus-agent
@echo "Incus built successfully"
race:
ifeq "$(TAG_SQLITE3)" ""
@echo "Missing custom libsqlite3, run \"make deps\" to setup."
exit 1
endif
CC="$(CC)" CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" $(GO) install -race -v -tags "$(TAG_SQLITE3)" $(DEBUG) ./...
CGO_ENABLED=0 $(GO) install -v -tags netgo ./cmd/incus-migrate
CGO_ENABLED=0 $(GO) install -v -tags agent,netgo ./cmd/incus-agent
@echo "Incus built successfully"
.PHONY: check
check: default
ifeq "$(INCUS_OFFLINE)" ""
(cd / ; $(GO) install -v -x github.com/rogpeppe/godeps@latest)
(cd / ; $(GO) install -v -x github.com/tsenart/deadcode@latest)
(cd / ; $(GO) install -v -x golang.org/x/lint/golint@latest)
endif
CGO_LDFLAGS_ALLOW="$(CGO_LDFLAGS_ALLOW)" $(GO) test -v -tags "$(TAG_SQLITE3)" $(DEBUG) ./...
cd test && ./main.sh
.PHONY: dist
dist: doc
# Cleanup
rm -Rf $(ARCHIVE).gz
# Create build dir
$(eval TMP := $(shell mktemp -d))
git archive --prefix=incus-$(VERSION)/ HEAD | tar -x -C $(TMP)
git show-ref HEAD | cut -d' ' -f1 > $(TMP)/incus-$(VERSION)/.gitref
# Download dependencies
(cd $(TMP)/incus-$(VERSION) ; $(GO) mod vendor)
# Download the cowsql libraries
git clone --depth=1 https://github.com/cowsql/cowsql $(TMP)/incus-$(VERSION)/vendor/cowsql
(cd $(TMP)/incus-$(VERSION)/vendor/cowsql ; git show-ref HEAD | cut -d' ' -f1 > .gitref)
git clone --depth=1 https://github.com/canonical/raft $(TMP)/incus-$(VERSION)/vendor/raft
(cd $(TMP)/incus-$(VERSION)/vendor/raft ; git show-ref HEAD | cut -d' ' -f1 > .gitref)
# Copy doc output
cp -r doc/html $(TMP)/incus-$(VERSION)/doc/html/
# Assemble tarball
tar --exclude-vcs -C $(TMP) -zcf $(ARCHIVE).gz incus-$(VERSION)/
# Cleanup
rm -Rf $(TMP)
.PHONY: i18n
i18n: update-pot update-po
po/%.mo: po/%.po
msgfmt --statistics -o $@ $<
po/%.po: po/$(DOMAIN).pot
msgmerge -U po/$*.po po/$(DOMAIN).pot
.PHONY: update-po
update-po:
set -eu; \
for lang in $(LINGUAS); do\
msgmerge --backup=none -U $$lang.po po/$(DOMAIN).pot; \
done
.PHONY: update-pot
update-pot:
ifeq "$(INCUS_OFFLINE)" ""
(cd / ; $(GO) install -v -x github.com/snapcore/snapd/i18n/xgettext-go@2.57.1)
endif
xgettext-go -o po/$(DOMAIN).pot --add-comments-tag=TRANSLATORS: --sort-output --package-name=$(DOMAIN) --msgid-bugs-address=lxc-users@lists.linuxcontainers.org --keyword=i18n.G --keyword-plural=i18n.NG cmd/incus/*.go internal/cliconfig/*.go
.PHONY: build-mo
build-mo: $(MOFILES)
.PHONY: static-analysis
static-analysis:
ifeq ($(shell command -v golangci-lint 2> /dev/null),)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$($(GO) env GOPATH)/bin
endif
ifeq ($(shell command -v shellcheck 2> /dev/null),)
echo "Please install shellcheck"
exit 1
endif
ifneq "$(shell shellcheck --version | grep version: | cut -d ' ' -f2)" "0.8.0"
@echo "WARN: shellcheck version is not 0.8.0"
endif
ifeq ($(shell command -v flake8 2> /dev/null),)
echo "Please install flake8"
exit 1
endif
golangci-lint run --timeout 5m
flake8 test/deps/import-busybox
shellcheck --shell sh test/*.sh test/includes/*.sh test/suites/*.sh test/backends/*.sh test/lint/*.sh
shellcheck test/extras/*.sh
run-parts --exit-on-error --regex '.sh' test/lint
.PHONY: tags
tags: *.go incusd/*.go shared/*.go cmd/incus/*.go
find . -type f -name '*.go' | xargs gotags > tags