-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
129 lines (101 loc) · 3.56 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
CARGO?=cargo
BUILD_TYPE?=release
BUILD_REPO_TAG=16
DOCKER_IMAGE=adamschwalm/hypervisor-build:$(BUILD_REPO_TAG)
TEST_IMAGE_REPO=https://github.com/mythril-hypervisor/build
TEST_INITRAMFS_URL=$(TEST_IMAGE_REPO)/releases/download/$(BUILD_REPO_TAG)/test-initramfs.img
TEST_KERNEL_URL=$(TEST_IMAGE_REPO)/releases/download/$(BUILD_REPO_TAG)/test-bzImage
CARGO_BUILD_JOBS?=$(shell grep -c '^processor' /proc/cpuinfo)
KVM_GROUP_ID?=$(shell grep kvm /etc/group | cut -f 3 -d:)
mythril_binary = mythril/target/mythril_target/$(BUILD_TYPE)/mythril
mythril_src = $(shell find mythril* -type f -name '*.rs' -or -name '*.S' -or -name '*.ld' \
-name 'Cargo.toml')
seabios = seabios/out/bios.bin
seabios_blob = mythril/src/blob/bios.bin
guest_kernel = scripts/vmlinuz
guest_initramfs = scripts/initramfs
git_hooks_src = $(wildcard .mythril_githooks/*)
git_hooks = $(subst .mythril_githooks,.git/hooks,$(git_hooks_src))
GUEST_ASSETS=$(guest_kernel) $(guest_initramfs)
ifneq (,$(filter qemu%, $(firstword $(MAKECMDGOALS))))
QEMU_EXTRA := $(subst :,\:, $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
$(eval $(QEMU_EXTRA):;@:)
endif
CARGO_MANIFEST?=--manifest-path mythril/Cargo.toml
ifeq ($(BUILD_TYPE), release)
CARGO_BUILD_FLAGS := --release
endif
.PHONY: all
all: mythril $(seabios)
.PHONY: mythril
mythril: $(mythril_binary)
.PHONY: mythril-debug
mythril-debug: BUILD_TYPE=debug
mythril-debug: $(mythril_binary)
$(guest_kernel):
curl -L $(TEST_KERNEL_URL) -o $(guest_kernel)
$(guest_initramfs):
curl -L $(TEST_INITRAMFS_URL) -o $(guest_initramfs)
docker-%:
docker run --privileged -ti --rm -w $(CURDIR) -v $(CURDIR):$(CURDIR) \
-u $(shell id -u):$(shell id -g) \
--group-add=$(KVM_GROUP_ID) \
-e CARGO_HOME=$(CURDIR)/mythril/.cargo \
-e CARGO_BUILD_JOBS=$(CARGO_BUILD_JOBS) \
$(DOCKER_IMAGE) /bin/bash -c '$(MAKE) $*'
$(seabios):
cp scripts/seabios.config seabios/.config
make -j $(CARGO_BUILD_JOBS) -C seabios
$(seabios_blob): $(seabios)
cp $(seabios) $(seabios_blob)
.PHONY: qemu
qemu: mythril $(GUEST_ASSETS)
./scripts/mythril-run.sh $(mythril_binary) $(QEMU_EXTRA)
.PHONY: qemu-debug
qemu-debug: mythril-debug $(GUEST_ASSETS)
./scripts/mythril-run.sh $(mythril_binary) \
-gdb tcp::1234 -S $(QEMU_EXTRA)
$(mythril_binary): $(mythril_src) $(seabios_blob)
$(CARGO) build $(CARGO_BUILD_FLAGS) $(CARGO_MANIFEST) \
-Z build-std=core,alloc \
--target mythril/mythril_target.json \
.PHONY: check-fmt
check-fmt:
$(CARGO) fmt $(CARGO_MANIFEST) --all -- --check
.PHONY: fmt
fmt:
$(CARGO) fmt $(CARGO_MANIFEST) --all
.PHONY: test_core
test_common: $(seabios_blob)
$(CARGO) test $(CARGO_MANIFEST) --lib \
--features=test \
.PHONY: test
test: test_common
.PHONY: clean
clean:
$(CARGO) clean $(CARGO_MANIFEST)
rm $(seabios_blob)
make -C seabios clean
rm $(GUEST_ASSETS)
.PHONY: dev-init
dev-init: install-git-hooks
.PHONY: install-git-hooks
install-git-hooks: $(git_hooks)
$(git_hooks): $(git_hooks_src)
ln -s $(shell realpath --relative-to=.git/hooks $<) $@
.PHONY: help
help:
@echo " Make Targets:"
@echo " all build everything to run mythril, but do not start qemu"
@echo " check-fmt run cargo fmt --check"
@echo " fmt run cargo fmt"
@echo " qemu run mythril in a VM"
@echo " qemu-debug run mythril in a VM, but halt for a debugger connection"
@echo " test run the mythril tests"
@echo " clean clean the build state"
@echo " help this"
@echo ""
@echo " Examples:"
@echo ""
@echo " make qemu"
@echo " make qemu -- -serial pty -monitor stdio"