-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
37 lines (29 loc) · 962 Bytes
/
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
RISCVGUN ?= riscv64-unknown-elf
CFLAGS = -I include -ffreestanding -mcmodel=medany -Wall -g
QEMUFLAGS = -M virt -smp 1 -m 4G -display none -serial stdio \
-kernel build/kernel.img \
-initrd res/initramfs.cpio
LD_SCRIPT = src/kernel.ld
SRC_FILES = $(shell find src -name "*.S") \
$(shell find src -name "*.c")
OBJ_FILES = $(addprefix build/, $(addsuffix .o, \
$(basename $(notdir $(SRC_FILES)))))
all: clean kernel
clean:
rm -rf build *.fit *.o
build:
$(RISCVGUN)-gcc $(CFLAGS) -c $(SRC_FILES)
@mkdir -p build
@mv *.o build
kernel: build
$(RISCVGUN)-ld -T $(LD_SCRIPT) -o build/kernel.elf $(OBJ_FILES)
$(RISCVGUN)-objcopy -O binary build/kernel.elf build/kernel.img
mkimage -f src/kernel.its kernel.fit > /dev/null
qemu: CFLAGS += -D __QEMU__
qemu: LD_SCRIPT = src/qemu.ld
qemu: all
clear & qemu-system-riscv64 $(QEMUFLAGS)
debug: CFLAGS += -D __QEMU__
debug: LD_SCRIPT = src/qemu.ld
debug: all
qemu-system-riscv64 $(QEMUFLAGS) -S -s