tiny_os/Makefile

74 lines
1.9 KiB
Makefile
Raw Normal View History

2024-05-05 00:06:43 +08:00
ARCH ?= riscv64
MODE ?= debug
2024-05-05 00:06:43 +08:00
ifeq ($(ARCH), riscv64)
BUILD_TARGET := riscv64imac-unknown-none-elf
LINKER_LDS := kernel/src/arch/riscv/linker64.ld
else
$(error Invalid TARGET: $(ARCH))
endif
ifeq ($(MODE), release)
CARGO_BUILD_ARGS += --release
else ifneq ($(MODE), debug)
$(error Invalid MODE: $(MODE))
endif
2024-05-05 00:06:43 +08:00
RUSTFLAGS += -Crelocation-model=static
RUSTFLAGS += -Ccode-model=medium
2024-05-06 01:23:34 +08:00
#RUSTFLAGS += -Ctarget-feature=+relax
2024-05-05 00:06:43 +08:00
RUSTFLAGS += -Cforce-frame-pointers=yes
RUSTFLAGS += -Clink-arg=-T$(LINKER_LDS)
CARGO_TARGET_ARGS := --target=$(BUILD_TARGET)
CARGO_BUILD_ARGS += -Zbuild-std=core,compiler_builtins,alloc
CARGO_BUILD_ARGS += -Zbuild-std-features=compiler-builtins-mem
CARGO_BUILD_ARGS += $(CARGO_TARGET_ARGS)
QEMU = qemu-system-$(ARCH)
2024-07-08 20:12:47 +08:00
QEMU_ARGS = -nographic -serial mon:stdio -smp 4
QEMU_ARGS += -machine virt # TODO: override by $(BOARD)
QEMU_ARGS += -kernel target/$(BUILD_TARGET)/$(MODE)/kernel
2024-06-16 23:39:04 +08:00
QEMU_ARGS += -initrd root/init.cpio
ifeq ($(MODE), debug)
QEMU_ARGS += -append "loglevel=4"
endif
2024-05-05 00:06:43 +08:00
kernel:
env RUSTFLAGS="$(RUSTFLAGS)" cargo build --bin kernel $(CARGO_BUILD_ARGS)
clippy:
cargo clippy -p allocator
cargo clippy -p utils
cargo clippy --no-deps $(CARGO_TARGET_ARGS) --manifest-path=kernel/Cargo.toml
2024-06-14 15:31:39 +08:00
fmt:
cargo fmt --all
2024-05-05 00:06:43 +08:00
test:
cargo test -p allocator
cargo test -p utils
env RUSTFLAGS="$(RUSTFLAGS)" cargo test $(CARGO_TARGET_ARGS) --bin=kernel
2024-05-06 15:53:48 +08:00
kernel-test-dump:
@env RUSTFLAGS="$(RUSTFLAGS)" cargo test $(CARGO_TARGET_ARGS) --bin=kernel --no-run --message-format=json
2024-05-07 20:39:52 +08:00
kernel-asm: kernel
riscv64-elf-objdump -d target/$(BUILD_TARGET)/$(MODE)/kernel | c++filt -t > kernel.asm
2024-05-07 20:39:52 +08:00
2024-05-06 15:53:48 +08:00
build-target:
@echo $(BUILD_TARGET)
2024-05-05 00:06:43 +08:00
clean:
cargo clean
qemu: kernel
$(QEMU) $(QEMU_ARGS) | tools/parse_backtrace.sh target/$(BUILD_TARGET)/$(MODE)/kernel
2024-05-05 00:06:43 +08:00
qemu-gdb: kernel
$(QEMU) $(QEMU_ARGS) -s -S
2024-06-14 15:31:39 +08:00
.PHONY: kernel clippy fmt test kernel-test-dump kernel-asm build-target clean qemu qemu-gdb