-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
executable file
·87 lines (71 loc) · 2.3 KB
/
Makefile
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
build_containing_dir := build
debug ?= 0
ifneq ($(debug), 1)
else ifndef log_level
log_level := debug
endif
ifndef log_level
log_level := ""
endif
ifeq ($(debug), 1)
nasm_flags := -f elf64 -F dwarf -g
build_type := debug
qemu_flags := -s -m 256M -d int -no-reboot -no-shutdown -monitor stdio -serial file:serial.log
cargo_flags := --features $(log_level)
else
nasm_flags := -f elf64
cargo_flags := --release --features $(log_level)
rustflags := "-C code-model=kernel"
build_type := release
qemu_flags := -m 256M -serial file:serial.log
endif
ifeq ($(wait_for_gdb), 1)
qemu_flags := -s -S
endif
linker_script := cfg/linker.ld
grub_cfg := cfg/grub.cfg
out_dir = $(build_containing_dir)/$(build_type)
asm_dir := kernel/src/asm
rust_crate_dir := kernel
rust_kernel := $(out_dir)/libflower_kernel.a
target := x86_64-unknown-flower-none
asm_source_files := $(wildcard $(asm_dir)/*.asm)
asm_obj_files = $(patsubst $(asm_dir)/%.asm, $(out_dir)/%.o, $(asm_source_files))
kernel = $(out_dir)/kernel.elf
grub_iso = $(out_dir)/flower.iso
default: build
.PHONY: clean run build $(rust_kernel) iso test
$(grub_iso): $(kernel) $(grub_cfg)
@cp $(grub_cfg) $(out_dir)/isofiles/boot/grub/
@cp $(kernel) $(out_dir)/isofiles/boot/
@grub-mkrescue -o $(out_dir)/flower.iso $(out_dir)/isofiles
test:
cd $(rust_crate_dir) && \
cargo test
build: $(kernel)
iso: $(grub_iso)
# Run with qemu
run: $(grub_iso)
@qemu-system-x86_64 -cdrom $(grub_iso) $(qemu_flags) -m 128M
# Clean build dir
clean:
@rm -rf build
@cd $(rust_crate_dir) && \
RUST_TARGET_PATH=$(shell pwd)/$(rust_crate_dir) cargo clean
# Make build directories
makedirs:
@mkdir -p $(out_dir)
@mkdir -p $(out_dir)/isofiles
@mkdir -p $(out_dir)/isofiles/boot/grub
# Compile rust
$(rust_kernel): $(rust_crate_dir)/**/*
@cd $(rust_crate_dir) && \
RUST_TARGET_PATH=$(shell pwd)/$(rust_crate_dir) RUSTFLAGS=$(rustflags) cargo xbuild --target $(target) $(cargo_flags)
@rm -f $(rust_kernel)
@mv $(rust_crate_dir)/target/$(target)/$(build_type)/libflower_kernel.a $(rust_kernel)
# Compile kernel.elf
$(kernel): $(asm_obj_files) $(linker_script) $(rust_kernel)
@ld -n -T $(linker_script) -o $(kernel) $(asm_obj_files) $(rust_kernel) --gc-sections
# Compile asm files
$(out_dir)/%.o: $(asm_dir)/%.asm makedirs
@nasm $(nasm_flags) $< -o $@