forked from arceos-org/arceos
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
117 lines (91 loc) · 2.32 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
# Arguments
ARCH ?= riscv64
MODE ?= release
LOG ?= warn
APP ?= helloworld
FS ?= off
NET ?= off
# Platform
ifeq ($(ARCH), riscv64)
PLATFORM ?= qemu-virt-riscv
target := riscv64gc-unknown-none-elf
else ifeq ($(ARCH), aarch64)
PLATFORM ?= qemu-virt-aarch64
target := aarch64-unknown-none-softfloat
else
$(error "ARCH" must be "riscv64" or "aarch64")
endif
export ARCH
export PLATFORM
export MODE
export LOG
# Paths
kernel_package := arceos-$(APP)
kernel_elf := target/$(target)/$(MODE)/$(kernel_package)
kernel_bin := $(kernel_elf).bin
# Cargo features and build args
features := axruntime/platform-$(PLATFORM)
ifneq ($(filter $(LOG),off error warn info debug trace),)
features += axruntime/log-level-$(LOG)
else
$(error "LOG" must be one of "off", "error", "warn", "info", "debug", "trace")
endif
ifeq ($(FS), on)
features += axruntime/fs
endif
ifeq ($(NET), on)
features += axruntime/net
endif
build_args := --no-default-features --features "$(features)" --target $(target) -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem
ifeq ($(MODE), release)
build_args += --release
endif
build_args += -p $(kernel_package)
# Binutils
OBJDUMP := rust-objdump -d --print-imm-hex --x86-asm-syntax=intel
OBJCOPY := rust-objcopy --binary-architecture=$(ARCH)
GDB := gdb-multiarch
# QEMU
qemu := qemu-system-$(ARCH)
qemu_args := -nographic -m 128M
ifeq ($(ARCH), riscv64)
qemu_args += \
-machine virt \
-bios default \
-kernel $(kernel_bin)
else ifeq ($(ARCH), aarch64)
qemu_args += \
-cpu cortex-a72 \
-machine virt \
-kernel $(kernel_bin)
endif
ifeq ($(FS), on)
qemu_args += \
-device virtio-blk-device,drive=disk0 \
-drive id=disk0,if=none,format=raw,file=disk.img
endif
ifeq ($(NET), on)
qemu_args += \
-device virtio-net-device,netdev=net0 \
-netdev user,id=net0,hostfwd=tcp::5555-:5555
endif
build: $(kernel_bin)
kernel_elf:
@echo Arch: $(ARCH), Platform: $(PLATFORM)
cargo build $(build_args)
$(kernel_bin): kernel_elf
@$(OBJCOPY) $(kernel_elf) --strip-all -O binary $@
disasm:
$(OBJDUMP) $(kernel_elf) | less
run: build justrun
justrun:
$(qemu) $(qemu_args)
clean:
cargo clean
clippy:
cargo clippy --target $(target)
fmt:
cargo fmt --all
test:
cargo test --workspace --exclude "arceos-*" -- --nocapture
.PHONY: build kernel_elf disasm run justrun clean clippy fmt test