forked from erulabs/criu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
382 lines (319 loc) · 9.31 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
__nmk_dir=$(CURDIR)/scripts/nmk/scripts/
export __nmk_dir
#
# No need to try to remake our Makefiles
Makefile: ;
Makefile.%: ;
scripts/%.mak: ;
$(__nmk_dir)%.mk: ;
#
# Import the build engine
include $(__nmk_dir)include.mk
include $(__nmk_dir)macro.mk
ifeq ($(origin HOSTCFLAGS), undefined)
HOSTCFLAGS := $(CFLAGS) $(USERCFLAGS)
endif
UNAME-M := $(shell uname -m)
#
# Supported Architectures
ifneq ($(filter-out x86 arm aarch64 ppc64 s390,$(ARCH)),)
$(error "The architecture $(ARCH) isn't supported")
endif
# The PowerPC 64 bits architecture could be big or little endian.
# They are handled in the same way.
ifeq ($(UNAME-M),ppc64)
error := $(error ppc64 big endian is not yet supported)
endif
#
# Architecture specific options.
ifeq ($(ARCH),arm)
ARMV := $(shell echo $(UNAME-M) | sed -nr 's/armv([[:digit:]]).*/\1/p; t; i7')
DEFINES := -DCONFIG_ARMV$(ARMV)
ifeq ($(ARMV),6)
USERCFLAGS += -march=armv6
endif
ifeq ($(ARMV),7)
USERCFLAGS += -march=armv7-a
endif
PROTOUFIX := y
endif
ifeq ($(ARCH),aarch64)
VDSO := y
DEFINES := -DCONFIG_AARCH64
endif
ifeq ($(ARCH),ppc64)
LDARCH := powerpc:common64
VDSO := y
DEFINES := -DCONFIG_PPC64 -D__SANE_USERSPACE_TYPES__
endif
ifeq ($(ARCH),x86)
LDARCH := i386:x86-64
VDSO := y
DEFINES := -DCONFIG_X86_64
endif
#
# CFLAGS_PIE:
#
# Ensure with -fno-optimize-sibling-calls that we don't create GOT
# (Global Offset Table) relocations with gcc compilers that don't have
# commit "S/390: Fix 64 bit sibcall".
ifeq ($(ARCH),s390)
ARCH := s390
SRCARCH := s390
VDSO := y
DEFINES := -DCONFIG_S390
CFLAGS_PIE := -fno-optimize-sibling-calls
endif
export CFLAGS_PIE
LDARCH ?= $(SRCARCH)
export LDARCH VDSO
export PROTOUFIX DEFINES
#
# Independent options for all tools.
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
WARNINGS := -Wall -Wformat-security
CFLAGS-GCOV := --coverage -fno-exceptions -fno-inline
export CFLAGS-GCOV
ifneq ($(GCOV),)
LDFLAGS += -lgcov
CFLAGS += $(CFLAGS-GCOV)
endif
ifeq ($(ASAN),1)
CFLAGS-ASAN := -fsanitize=address
export CFLAGS-ASAN
CFLAGS += $(CFLAGS-ASAN)
endif
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
ifeq ($(DEBUG),1)
DEFINES += -DCR_DEBUG
CFLAGS += -O0 -ggdb3
else
CFLAGS += -O2 -g
endif
ifeq ($(GMON),1)
CFLAGS += -pg
GMONLDOPT += -pg
export GMON GMONLDOPT
endif
CFLAGS += $(USERCFLAGS) $(WARNINGS) $(DEFINES) -iquote include/
HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
export CFLAGS USERCLFAGS HOSTCFLAGS
# Default target
all: criu lib
.PHONY: all
#
# Version headers.
include Makefile.versions
VERSION_HEADER := criu/include/version.h
GITID_FILE := .gitid
GITID := $(shell if [ -d ".git" ]; then git describe --always; fi)
# Git repository wasn't inited in CRIU folder
ifeq ($(GITID),)
GITID := 0
else
GITID_FILE_VALUE := $(shell if [ -f '$(GITID_FILE)' ]; then if [ `cat '$(GITID_FILE)'` = $(GITID) ]; then echo y; fi; fi)
ifneq ($(GITID_FILE_VALUE),y)
.PHONY: $(GITID_FILE)
endif
endif
$(GITID_FILE):
$(call msg-gen, $@)
$(Q) echo "$(GITID)" > $(GITID_FILE)
$(VERSION_HEADER): Makefile.versions $(GITID_FILE)
$(call msg-gen, $@)
$(Q) echo "/* Autogenerated, do not edit */" > $@
$(Q) echo "#ifndef __CR_VERSION_H__" >> $@
$(Q) echo "#define __CR_VERSION_H__" >> $@
$(Q) echo "#define CRIU_VERSION \"$(CRIU_VERSION)\"" >> $@
$(Q) echo "#define CRIU_VERSION_MAJOR " $(CRIU_VERSION_MAJOR) >> $@
$(Q) echo "#define CRIU_VERSION_MINOR " $(CRIU_VERSION_MINOR) >> $@
ifneq ($(CRIU_VERSION_SUBLEVEL),)
$(Q) echo "#define CRIU_VERSION_SUBLEVEL " $(CRIU_VERSION_SUBLEVEL) >> $@
endif
ifneq ($(CRIU_VERSION_EXTRA),)
$(Q) echo "#define CRIU_VERSION_EXTRA " $(CRIU_VERSION_EXTRA) >> $@
endif
$(Q) echo "#define CRIU_GITID \"$(GITID)\"" >> $@
$(Q) echo "#endif /* __CR_VERSION_H__ */" >> $@
criu-deps += $(VERSION_HEADER)
#
# Setup proper link for asm headers in common code.
include/common/asm: include/common/arch/$(ARCH)/asm
$(call msg-gen, $@)
$(Q) ln -s ./arch/$(ARCH)/asm $@
criu-deps += include/common/asm
#
# Configure variables.
export CONFIG_HEADER := include/common/config.h
ifeq ($(filter tags etags cscope clean mrproper,$(MAKECMDGOALS)),)
include Makefile.config
else
# To clean all files, enable make/build options here
export CONFIG_COMPAT := y
endif
#
# Protobuf images first, they are not depending
# on anything else.
$(eval $(call gen-built-in,images))
criu-deps += images/built-in.o
#
# Compel get used by CRIU, build it earlier
include Makefile.compel
#
# Next the socket CR library
#
SOCCR_A := soccr/libsoccr.a
soccr/Makefile: ;
soccr/%: $(CONFIG_HEADER) .FORCE
$(Q) $(MAKE) $(build)=soccr $@
soccr/built-in.o: $(CONFIG_HEADER) .FORCE
$(Q) $(MAKE) $(build)=soccr all
$(SOCCR_A): |soccr/built-in.o
criu-deps += $(SOCCR_A)
#
# CRIU building done in own directory
# with slightly different rules so we
# can't use nmk engine directly (we
# build syscalls library and such).
#
# But note that we're already included
# the nmk so we can reuse it there.
criu/Makefile: ;
criu/Makefile.packages: ;
criu/Makefile.crtools: ;
criu/%: $(criu-deps) .FORCE
$(Q) $(MAKE) $(build)=criu $@
criu: $(criu-deps)
$(Q) $(MAKE) $(build)=criu all
.PHONY: criu
#
# Libraries next once criu it ready
# (we might generate headers and such
# when building criu itself).
lib/Makefile: ;
lib/%: criu .FORCE
$(Q) $(MAKE) $(build)=lib $@
lib: criu
$(Q) $(MAKE) $(build)=lib all
.PHONY: lib
clean mrproper:
$(Q) $(MAKE) $(build)=images $@
$(Q) $(MAKE) $(build)=criu $@
$(Q) $(MAKE) $(build)=soccr $@
$(Q) $(MAKE) $(build)=lib $@
$(Q) $(MAKE) $(build)=compel $@
$(Q) $(MAKE) $(build)=compel/plugins $@
$(Q) $(MAKE) $(build)=lib $@
.PHONY: clean mrproper
clean-top:
$(Q) $(MAKE) -C Documentation clean
$(Q) $(MAKE) $(build)=test/compel clean
$(Q) $(RM) .gitid
.PHONY: clean-top
clean: clean-top
mrproper-top: clean-top
$(Q) $(RM) $(CONFIG_HEADER)
$(Q) $(RM) $(VERSION_HEADER)
$(Q) $(RM) $(COMPEL_VERSION_HEADER)
$(Q) $(RM) include/common/asm
$(Q) $(RM) compel/include/asm
$(Q) $(RM) cscope.*
$(Q) $(RM) tags TAGS
.PHONY: mrproper-top
mrproper: mrproper-top
#
# Non-CRIU stuff.
#
docs:
$(Q) $(MAKE) -s -C Documentation all
.PHONY: docs
zdtm: all
$(Q) MAKEFLAGS= $(MAKE) -C test/zdtm all
.PHONY: zdtm
test: zdtm
$(Q) MAKEFLAGS= $(MAKE) -C test
.PHONY: test
#
# Generating tar requires tag matched CRIU_VERSION.
# If not found then simply use GIT's describe with
# "v" prefix stripped.
head-name := $(shell git tag -l v$(CRIU_VERSION))
ifeq ($(head-name),)
head-name := $(shell git describe 2>/dev/null)
endif
# If no git tag could describe current commit,
# use pre-defined CRIU_VERSION with GITID (if any).
ifeq ($(head-name),)
ifneq ($(GITID),)
head-name := $(CRIU_VERSION)-$(GITID)
else
head-name := $(CRIU_VERSION)
endif
endif
tar-name := $(shell echo $(head-name) | sed -e 's/^v//g')
criu-$(tar-name).tar.bz2:
git archive --format tar --prefix 'criu-$(tar-name)/' $(head-name) | bzip2 > $@
dist tar: criu-$(tar-name).tar.bz2 ;
.PHONY: dist tar
TAGS_FILES_REGEXP := . -name '*.[hcS]' ! -path './.*' \( ! -path './test/*' -o -path './test/zdtm/lib/*' \)
tags:
$(call msg-gen, $@)
$(Q) $(RM) tags
$(Q) $(FIND) $(TAGS_FILES_REGEXP) -print | xargs $(CTAGS) -a
.PHONY: tags
etags:
$(call msg-gen, $@)
$(Q) $(RM) TAGS
$(Q) $(FIND) $(TAGS_FILES_REGEXP) -print | xargs $(ETAGS) -a
.PHONY: etags
cscope:
$(call msg-gen, $@)
$(Q) $(FIND) $(TAGS_FILES_REGEXP) ! -type l -print > cscope.files
$(Q) $(CSCOPE) -bkqu
.PHONY: cscope
gcov:
$(E) " GCOV"
$(Q) test -d gcov || mkdir gcov && \
geninfo --output-filename gcov/criu.info --no-recursion criu/ && \
cd gcov && \
genhtml --rc lcov_branch_coverage=1 --output-directory html criu.info
@echo "Code coverage report is in `pwd`/gcov/html/ directory."
.PHONY: gcov
docker-build:
$(MAKE) -C scripts/build/ x86_64
.PHONY: docker-build
phaul-test:
docker run --rm -it --privileged criu-x86_64 ./scripts/travis/phaul
.PHONY: phaul-test
docker-test:
docker run --rm -it --privileged criu-x86_64 ./test/zdtm.py run -a -x tcp6 -x tcpbuf6 -x static/rtc -x cgroup
.PHONY: docker-test
help:
@echo ' Targets:'
@echo ' all - Build all [*] targets'
@echo ' * criu - Build criu'
@echo ' zdtm - Build zdtm test-suite'
@echo ' docs - Build documentation'
@echo ' install - Install CRIU (see INSTALL.md)'
@echo ' uninstall - Uninstall CRIU'
@echo ' dist - Create a source tarball'
@echo ' clean - Clean most, but leave enough to navigate'
@echo ' mrproper - Delete all compiled/generated files'
@echo ' tags - Generate tags file (ctags)'
@echo ' etags - Generate TAGS file (etags)'
@echo ' cscope - Generate cscope database'
@echo ' test - Run zdtm test-suite'
@echo ' gcov - Make code coverage report'
.PHONY: help
lint:
flake8 --config=scripts/flake8.cfg test/zdtm.py
include Makefile.install
.DEFAULT_GOAL := all
# Disable implicit rules in _this_ Makefile.
.SUFFIXES:
#
# Optional local include.
-include Makefile.local