This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (66 loc) · 2.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
.DELETE_ON_ERROR:
.PHONY: all bootloader kernel mkinitrd initrd userspace bootloader-clean kernel-clean \
mkinitrd-clean initrd-clean userspace-clean clean run
BOOT_BUILDDIR := boot/build
BUILD_TYPE ?= debug
ifeq ($(BUILD_TYPE),debug)
CARGO_PROFILE_FLAG :=
TARGET_SUBDIR := debug
else ifeq ($(BUILD_TYPE),release)
CARGO_PROFILE_FLAG := --release
TARGET_SUBDIR := release
else ifeq ($(BUILD_TYPE),test)
CARGO_PROFILE_FLAG := --profile doors-test
TARGET_SUBDIR := doors-test
else
$(error BUILD_TYPE should be either debug, release, or test, found $(BUILD_TYPE))
endif
KERNEL_BIN := kernel/target/x86_64-unknown-none/$(TARGET_SUBDIR)/doors
all: boot.img
bootloader:
$(MAKE) -C boot
kernel:
cd kernel && cargo fmt && cargo build $(CARGO_PROFILE_FLAG) && cargo clippy && cargo doc
mkinitrd:
cd mkinitrd && cargo build --release
initrd: mkinitrd userspace
mkinitrd/target/release/mkinitrd initrd initrd.bin
userspace:
$(MAKE) -C userspace
bootpart.img: bootloader kernel initrd
cp $(KERNEL_BIN) kernel.bin
$(BOOT_BUILDDIR)/genfat $@ kernel.bin initrd.bin
boot.img: bootpart.img
cp $(BOOT_BUILDDIR)/loader.bin $@
truncate -s 128M $@
dd if=bootpart.img of=$@ seek=2048 conv=notrunc
bootloader-clean:
$(MAKE) -C boot clean
kernel-clean:
cd kernel && cargo clean
mkinitrd-clean:
cd mkinitrd && cargo clean
initrd-clean:
rm -f initrd.bin
userspace-clean:
$(MAKE) -C userspace clean
clean: bootloader-clean kernel-clean mkinitrd-clean initrd-clean userspace-clean
rm -f boot.img bootpart.img kernel.bin
QEMU_FIXED_FLAGS := -drive file=boot.img,format=raw,index=0,media=disk
ifeq ($(BUILD_TYPE),test)
run: boot.img
qemu-system-x86_64 $(QEMU_FIXED_FLAGS) -device isa-debug-exit,iobase=0xf4,iosize=0x04 -debugcon stdio -display none; \
STATUS=$$?; \
if [ $$STATUS -eq 5 ]; then \
echo "Test success"; \
elif [ $$STATUS -eq 7 ]; then \
echo "Test failure"; \
exit 1; \
else \
echo "Unrecognized QEMU exit status; QEMU error?"; \
exit 1; \
fi
else
run: boot.img
qemu-system-x86_64 $(QEMU_FIXED_FLAGS) -monitor stdio -debugcon vc
endif