2017-04-11 11:02:09 +04:00
|
|
|
arch ?= x86_64
|
|
|
|
kernel := build/kernel-$(arch).bin
|
|
|
|
iso := build/os-$(arch).iso
|
2017-04-11 20:23:27 +04:00
|
|
|
target ?= $(arch)-blog_os
|
|
|
|
rust_os := target/$(target)/debug/libblog_os.a
|
2017-04-11 11:02:09 +04:00
|
|
|
|
|
|
|
linker_script := src/arch/$(arch)/linker.ld
|
|
|
|
grub_cfg := src/arch/$(arch)/grub.cfg
|
|
|
|
assembly_source_files := $(wildcard src/arch/$(arch)/*.asm)
|
|
|
|
assembly_object_files := $(patsubst src/arch/$(arch)/%.asm, \
|
|
|
|
build/arch/$(arch)/%.o, $(assembly_source_files))
|
|
|
|
|
2017-04-11 20:23:27 +04:00
|
|
|
.PHONY: all clean run iso kernel
|
2017-04-11 11:02:09 +04:00
|
|
|
|
|
|
|
all: $(kernel)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
@rm -r build
|
|
|
|
|
|
|
|
run: $(iso)
|
|
|
|
@qemu-system-x86_64 -cdrom $(iso)
|
|
|
|
|
|
|
|
iso: $(iso)
|
|
|
|
|
|
|
|
$(iso): $(kernel) $(grub_cfg)
|
|
|
|
@mkdir -p build/isofiles/boot/grub
|
|
|
|
@cp $(kernel) build/isofiles/boot/kernel.bin
|
|
|
|
@cp $(grub_cfg) build/isofiles/boot/grub
|
|
|
|
@grub-mkrescue -o $(iso) build/isofiles 2> /dev/null
|
|
|
|
@rm -r build/isofiles
|
|
|
|
|
2017-04-11 20:23:27 +04:00
|
|
|
$(kernel): kernel $(rust_os) $(assembly_object_files) $(linker_script)
|
2017-04-11 20:52:31 +04:00
|
|
|
@ld -n --gc-sections -T $(linker_script) -o $(kernel) \
|
2017-04-11 20:23:27 +04:00
|
|
|
$(assembly_object_files) $(rust_os)
|
|
|
|
|
|
|
|
kernel:
|
|
|
|
@xargo build --target $(target)
|
2017-04-11 11:02:09 +04:00
|
|
|
|
|
|
|
# compile assembly files
|
|
|
|
build/arch/$(arch)/%.o: src/arch/$(arch)/%.asm
|
|
|
|
@mkdir -p $(shell dirname $@)
|
|
|
|
@nasm -felf64 $< -o $@
|