-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
40 lines (30 loc) · 986 Bytes
/
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
kernel := build/kernel.bin
iso := build/os.iso
target ?= x86_64-unknown-linux-gnu
rust_os := target/$(target)/debug/librusty_xinu.a
linker_script := src/linker.ld
grub_cfg := src/grub.cfg
assembly_source_files := $(wildcard src/*.asm)
assembly_object_files := $(patsubst src/%.asm, \
build/%.o, $(assembly_source_files))
.PHONY: all clean run iso
all: $(kernel)
clean:
@rm -r build
run: $(iso)
@qemu-system -cdrom $(iso)
iso: $(iso)
$(iso): $(kernel) $(grub_cfg)
@mkdir -p build/iso/boot/grub
@cp $(kernel) build/iso/boot/kernel.bin
@cp $(grub_cfg) build/iso/boot/grub
@grub-mkrescue /usr/lib/grub/i386-pc -o $(iso) build/iso 2> /dev/null
@rm -r build/iso
$(kernel): cargo $(rust_os) $(assembly_object_files) $(linker_script)
@ld -n --gc-sections -T $(linker_script) -o $(kernel) $(assembly_object_files) $(rust_os)
cargo:
@cargo build --target=$(target) --verbose
# compile assembly files
build/%.o: src/%.asm
@mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@