-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·60 lines (47 loc) · 1.86 KB
/
Makefile
File metadata and controls
executable file
·60 lines (47 loc) · 1.86 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Makefile for building and running the Rust-based kernel and disk image
TARGET_NAME = x86_64-rustnix
TARGET = $(TARGET_NAME).json
KERNEL_DIR = kernel
FS_LOADER_DIR = fs-loader
KERNEL_BIN = $(KERNEL_DIR)/target/$(TARGET_NAME)/debug/bootimage-rustnix.bin
DISK_IMG = $(FS_LOADER_DIR)/disk.img
ASM_OUT_DIR = disk/bin
ASM_FILES = $(wildcard disk/src/*.S)
FEATURES ?= debug_log
.PHONY: all assemble kernel bootimage fs-loader run clean
all: run
assemble:
@mkdir -p $(ASM_OUT_DIR)
@echo "Assembling assembly files..."
@for file in $(ASM_FILES); do \
nasm $$file -o $(ASM_OUT_DIR)/$$(basename $$file .S).bin; \
echo -ne '\x7FBIN' | cat - $(ASM_OUT_DIR)/$$(basename $$file .S).bin > $(ASM_OUT_DIR)/$$(basename $$file .S).bin.tmp && mv $(ASM_OUT_DIR)/$$(basename $$file .S).bin.tmp $(ASM_OUT_DIR)/$$(basename $$file .S).bin; \
done
@echo "Assembly completed."
@echo "Compiling C files..."
@for file in $(wildcard disk/src/c/*.c); do \
tcc $$file -o $(ASM_OUT_DIR)/$$(basename $$file .c).o -nostdlib -static -nostdinc; \
echo "Compiled $$file to $(ASM_OUT_DIR)/$$(basename $$file .c).o"; \
done
@echo "C file compilation completed."
kernel: assemble
@echo "Building kernel..."
@cd $(KERNEL_DIR) && cargo build --target $(TARGET) --features $(FEATURES)
@echo "Kernel built successfully."
bootimage: kernel
@echo "Creating bootable image..."
@cd $(KERNEL_DIR) && cargo bootimage --target $(TARGET) --features $(FEATURES)
@echo "Bootable image created successfully."
fs-loader:
@echo "Loading files"
@cd $(FS_LOADER_DIR) && cargo run
@echo "Files loaded successfully."
qemu: bootimage fs-loader
@echo "Running QEMU..."
qemu-system-x86_64 -drive file=$(KERNEL_BIN),format=raw -drive file=$(DISK_IMG),format=raw -serial stdio
@echo "\nQEMU exited."
test: bootimage
@echo "Running tests..."
@cd $(KERNEL_DIR) && cargo test
@echo "Tests completed."
run: bootimage fs-loader qemu