-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
45 lines (33 loc) · 1.12 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
ARCH ?= x86_64
TARGET ?= $(ARCH)-rcpu_os
KERNEL := build/kernel-$(ARCH).bin
ISO := build/rcpu_os-$(ARCH).iso
RUST_OS := target/$(TARGET)/release/librcpu_os.a
LINKER_SCRIPT := src/arch/$(ARCH)/linker.ld
MK_GRUB_CFG := src/arch/$(ARCH)/mkgrubcfg.sh
ASM_SRC_FILES := $(wildcard src/arch/$(ARCH)/*.asm)
ASM_OBJ_FILES := $(patsubst src/arch/$(ARCH)/%.asm, \
build/arch/$(ARCH)/%.o, $(ASM_SRC_FILES))
.PHONY: all clean run iso kernel
all: $(KERNEL)
clean:
rm -r build target
run: $(ISO)
qemu-system-x86_64 -cdrom $(ISO)
iso: $(ISO)
$(ISO): $(KERNEL) $(GRUB_CFG)
mkdir -p build/isofiles/boot/grub
cp modules/* build/isofiles/boot
cp $(KERNEL) build/isofiles/boot/kernel.bin
$(MK_GRUB_CFG) modules > build/isofiles/boot/grub/grub.cfg
grub-mkrescue -o $(ISO) build/isofiles
rm -r build/isofiles
$(KERNEL): kernel $(RUST_OS) $(ASM_OBJ_FILES) $(LINKER_SCRIPT)
ld -n -T $(LINKER_SCRIPT) -o $(KERNEL) \
$(ASM_OBJ_FILES) $(RUST_OS)
kernel:
RUST_TARGET_PATH=$(shell pwd) cargo build --release --target $(TARGET)
# compile assembly files
build/arch/$(ARCH)/%.o: src/arch/$(ARCH)/%.asm
mkdir -p $(shell dirname $@)
nasm -felf64 $< -o $@