-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
52 lines (39 loc) · 1.55 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
arch ?= x86_64
kernel := target/kernel-$(arch).bin
iso := target/diy-os-$(arch).iso
linker_script := boot/$(arch)/linker.ld
ld_mapfile := target/linker.map
grub_cfg := boot/$(arch)/grub.cfg
assembly_source_files := $(wildcard boot/$(arch)/*.asm)
assembly_object_files := $(patsubst boot/$(arch)/%.asm, target/arch/$(arch)/%.o, $(assembly_source_files))
rust_os := target/x86_64-rust_os/release/librust_os.a
.PHONY: all clean run debug iso
all: $(kernel)
clean:
@rm -rf target
test:
@sed -Ei 's/^(crate-type = ).*/\1["lib"]/g' kernel/Cargo.toml
@#cargo xtest -p diy-os-runner --bin diy-os-runner
@sed -Ei 's/^(crate-type = ).*/\1["staticlib"]/g' kernel/Cargo.toml
run: $(iso)
@qemu-system-x86_64 -m size=8000 -serial stdio --no-reboot -cdrom $(iso)
debug: $(iso)
@qemu-system-x86_64 -m size=8000 -monitor stdio -d int --no-reboot -s -S -cdrom $(iso)
iso: $(iso)
$(iso): $(kernel) $(grub_cfg)
@mkdir -p target/isofiles/boot/grub
@cp $(kernel) target/isofiles/boot/kernel.bin
@cp $(grub_cfg) target/isofiles/boot/grub
@grub-mkrescue -o $(iso) target/isofiles 2> /dev/null
@rm -r target/isofiles
$(kernel): $(rust_os) $(assembly_object_files) $(linker_script)
@mkdir -p target
@ld -z noreloc-overflow -n -T $(linker_script) -o $(kernel) -Map=$(ld_mapfile) $(assembly_object_files) $(rust_os)
# compile assembly files
target/arch/$(arch)/%.o: boot/$(arch)/%.asm
@mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@
# compile rust OS
$(rust_os): FORCE
@cargo build -Z build-std=core,alloc -Z build-std-features=compiler-builtins-mem -p diy-os --release
FORCE: ;