mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Right now, it does not matter whether we boot from a drive or a cdrom. Therefore we use the shorter `-cdrom`.
58 lines
1.7 KiB
Makefile
58 lines
1.7 KiB
Makefile
# Copyright 2015 Philipp Oppermann. See the README.md
|
|
# file at the top-level directory of this distribution.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
# option. This file may not be copied, modified, or distributed
|
|
# except according to those terms.
|
|
|
|
arch ?= x86_64
|
|
target ?= $(arch)-unknown-linux-gnu
|
|
kernel := build/kernel-$(arch).bin
|
|
iso := build/os-$(arch).iso
|
|
|
|
rust_os := target/$(target)/debug/libblog_os.a
|
|
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))
|
|
|
|
.PHONY: all clean run debug iso cargo gdb
|
|
|
|
all: $(kernel)
|
|
|
|
clean:
|
|
@cargo clean
|
|
@rm -rf build
|
|
|
|
run: $(iso)
|
|
@qemu-system-x86_64 -cdrom $(iso) -s
|
|
|
|
debug: $(iso)
|
|
@qemu-system-x86_64 -cdrom $(iso) -s -S
|
|
|
|
gdb:
|
|
@rust-os-gdb/bin/rust-gdb "build/kernel-x86_64.bin" -ex "target remote :1234"
|
|
|
|
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
|
|
|
|
$(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 rustc --target $(target) -- -Z no-landing-pads
|
|
|
|
# compile assembly files
|
|
build/arch/$(arch)/%.o: src/arch/$(arch)/%.asm
|
|
@mkdir -p $(shell dirname $@)
|
|
@nasm -felf64 $< -o $@
|