-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (54 loc) · 1.78 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
exe := "" #"$(shell cat /proc/version | grep -q microsoft && echo ".exe")"
disk_size := 1g
target := target/x86_64-unknown-lucy/debug
rom := $(target)/lucy.iso
initrd := $(target)/lucy.initrd
kernel := $(target)/lucy
lib_boot := $(target)/libboot.a
user_target := target/x86_64-unknown-none/release
user_program := $(user_target)/program
libc := $(target)
.PHONY: all
all: $(rom) $(target)/_disk_image
$(kernel): $(shell find kernel) $(lib_boot) boot/linker.ld
cargo -Z unstable-options -C kernel build
$(user_program): $(shell find user)
cargo -Z unstable-options -C user/program build --release
$(target)/boot.o: boot/boot.asm | $(target)
nasm -felf64 $^ -o $@
$(target)/syscall.o: $(shell find kernel/src -name 'syscall.asm') | $(target)
nasm -felf64 $< -o $@
$(target)/base: $(shell find base) $(target)
cp -r $< $@
mkdir -p $@/usr/bin
cargo -Z unstable-options -C user/hello-world build --release
cp $(user_target)/hello-world $@/usr/bin
$(lib_boot): $(target)/boot.o $(target)/syscall.o
ar rvs $@ $^
$(initrd): $(user_program)
cp $< $@
$(rom): $(kernel) $(initrd)
mkdir -p $(target)/rom/boot/grub
cp boot/grub.cfg $(target)/rom/boot/grub/grub.cfg
cp $(kernel) $(target)/rom/boot/lucy
cp $(initrd) $(target)/rom/boot/lucy.initrd
gunzip -c /usr/share/kbd/consolefonts/sun12x22.psfu.gz > $(target)/rom/boot/font.psfu
grub-mkrescue -o $@ $(target)/rom
$(target)/_disk_image: $(target)/base
qemu-img$(exe) create -f raw $@ $(disk_size)
mkfs.ext2 -d $< $@
$(target):
mkdir -p $@
.PHONY: run
run: $(rom) $(target)/_disk_image
qemu-system-x86_64$(exe) -cdrom $(rom) \
-cpu Broadwell \
-drive file=$(target)/_disk_image,format=raw,if=ide \
-m 2g \
-no-reboot \
-no-shutdown \
-serial stdio
.PHONY: clean
clean:
$(RM) -r $(rom) $(target)/boot.o $(target)/syscall.o $(target)/rom
cargo clean