-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
89 lines (70 loc) · 1.75 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
88
89
SYSCALL = y
SRCS_ASM = \
start.S \
mem.S \
entry.S \
usys.S
SRCS_C = \
kernel.c \
uart.c \
printf.c \
page.c \
sched.c \
user.c \
trap.c \
plic.c \
timer.c \
lock.c \
syscall.c
ifeq (${SYSCALL}, y)
DEFS += -DCONFIG_SYSCALL
endif
DEFS +=
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS += -nostdlib -fno-builtin -g -Wall
CFLAGS += -march=rv32g -mabi=ilp32
LDFLAGS ?= -T os.ld
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none
GDB = gdb-multiarch
CC = ${CROSS_COMPILE}gcc
OBJCOPY = ${CROSS_COMPILE}objcopy
OBJDUMP = ${CROSS_COMPILE}objdump
MKDIR = mkdir -p
RM = rm -rf
OUTPUT_PATH = out
# SRCS_ASM & SRCS_C are defined in the Makefile of each project.
OBJS_ASM := $(addprefix ${OUTPUT_PATH}/, $(patsubst %.S, %.o, ${SRCS_ASM}))
OBJS_C := $(addprefix $(OUTPUT_PATH)/, $(patsubst %.c, %.o, ${SRCS_C}))
OBJS = ${OBJS_ASM} ${OBJS_C}
ELF = ${OUTPUT_PATH}/os.elf
BIN = ${OUTPUT_PATH}/os.bin
.DEFAULT_GOAL := all
all: ${OUTPUT_PATH} ${ELF}
${OUTPUT_PATH}:
@${MKDIR} $@
# start.o must be the first in dependency!
${ELF}: ${OBJS}
${CC} ${CFLAGS} ${LDFLAGS} -o ${ELF} $^
${OBJCOPY} -O binary ${ELF} ${BIN}
${OUTPUT_PATH}/%.o : %.c
${CC} ${DEFS} ${CFLAGS} -c -o $@ $<
${OUTPUT_PATH}/%.o : %.S
${CC} ${DEFS} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel ${ELF}
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel ${ELF} -s -S &
@${GDB} ${ELF} -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S ${ELF} | less
.PHONY : clean
clean:
@${RM} ${OUTPUT_PATH}