1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-23 08:26:17 +04:00
rCore/Makefile

113 lines
2.7 KiB
Makefile
Raw Normal View History

2017-04-11 11:02:09 +04:00
arch ?= x86_64
kernel := build/kernel-$(arch).bin
iso := build/os-$(arch).iso
target ?= $(arch)-blog_os
rust_os := target/$(target)/debug/libblog_os.a
2017-04-11 11:02:09 +04:00
boot_src := src/arch/$(arch)/boot
linker_script := $(boot_src)/linker.ld
grub_cfg := $(boot_src)/grub.cfg
assembly_source_files := $(wildcard $(boot_src)/*.asm)
assembly_object_files := $(patsubst $(boot_src)/%.asm, \
build/arch/$(arch)/boot/%.o, $(assembly_source_files))
qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio
2018-04-14 21:01:44 +04:00
features := use_apic
2018-04-09 17:20:47 +04:00
ifdef travis
test := 1
features := $(features) qemu_auto_exit
2018-04-09 17:20:47 +04:00
endif
ifdef test
features := $(features) test
# enable shutdown inside the qemu
qemu_opts := $(qemu_opts) -device isa-debug-exit
2018-04-09 17:20:47 +04:00
endif
2017-04-11 11:02:09 +04:00
2018-04-19 11:57:34 +04:00
ifeq ($(OS),Windows_NT)
uname := Win32
else
uname := $(shell uname)
endif
ifeq ($(uname), Linux)
prefix :=
2018-04-02 13:48:07 +04:00
else
prefix := x86_64-elf-
2018-04-02 13:48:07 +04:00
endif
ld := $(prefix)ld
2018-04-12 19:44:25 +04:00
objdump := $(prefix)objdump
2018-04-12 20:54:13 +04:00
cc := $(prefix)gcc
2018-04-02 13:48:07 +04:00
2018-04-12 19:44:25 +04:00
.PHONY: all clean run iso kernel build debug_asm
2017-04-11 11:02:09 +04:00
all: $(kernel)
clean:
2018-04-12 19:44:25 +04:00
@rm -r build target
2017-04-11 11:02:09 +04:00
run: $(iso)
@qemu-system-$(arch) $(qemu_opts) || [ $$? -eq 11 ] # run qemu and assert it exit 11
2017-04-11 11:02:09 +04:00
iso: $(iso)
2018-04-09 17:20:47 +04:00
build: iso
2018-04-12 19:44:25 +04:00
debug_asm:
@$(objdump) -dS $(kernel) | less
2017-04-11 11:02:09 +04:00
$(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): kernel $(rust_os) $(assembly_object_files) $(linker_script)
2018-04-02 13:48:07 +04:00
@$(ld) -n --gc-sections -T $(linker_script) -o $(kernel) \
$(assembly_object_files) $(rust_os)
kernel:
2018-04-12 20:54:13 +04:00
@RUST_TARGET_PATH=$(shell pwd) CC=$(cc) xargo build --target $(target) --features "$(features)"
2017-04-11 11:02:09 +04:00
# compile assembly files
build/arch/$(arch)/boot/%.o: $(boot_src)/%.asm
2017-04-11 11:02:09 +04:00
@mkdir -p $(shell dirname $@)
@nasm -felf64 $< -o $@
2018-04-02 11:28:32 +04:00
# used by docker_* targets
docker_image ?= blog_os
tag ?= 0.1
2018-04-19 11:57:34 +04:00
pwd ?= $(realpath ./)
ifeq ($(OS),Windows_NT)
uid ?= 0
gid ?= 0
innerpwd ?= /root/blog_os
else
uid ?= $(shell id -u)
gid ?= $(shell id -g)
innerpwd ?= pwd
endif
docker_cargo_volume ?= blogos-$(uid)-$(gid)-cargo
docker_rustup_volume ?= blogos-$(uid)-$(gid)-rustup
docker_args ?= -e LOCAL_UID=$(uid) -e LOCAL_GID=$(gid) -v $(docker_cargo_volume):/usr/local/cargo -v $(docker_rustup_volume):/usr/local/rustup -v $(pwd):$(innerpwd) -w $(innerpwd)
2018-04-02 11:28:32 +04:00
docker_clean_args ?= $(docker_cargo_volume) $(docker_rustup_volume)
2018-04-19 11:57:34 +04:00
# docker_* targets
2018-04-02 11:28:32 +04:00
docker_build:
@docker build docker/ -t $(docker_image):$(tag)
2018-04-19 11:57:34 +04:00
docker_iso:
docker run --rm $(docker_args) $(docker_image):$(tag) make iso
2018-04-02 11:28:32 +04:00
docker_run: docker_iso
@qemu-system-$(arch) -cdrom $(iso) -s
2018-04-02 11:28:32 +04:00
docker_interactive:
2018-04-19 11:57:34 +04:00
@docker run -it --rm $(docker_args) $(docker_image):$(tag)
2018-04-02 11:28:32 +04:00
docker_clean:
@docker volume rm $(docker_clean_args)