-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
151 lines (121 loc) · 3.34 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
SRC:= .
BUILD:= build
PREFIX:=riscv32-unknown-linux-gnu-
INCLUDE_PATH:= \
$(SRC)/kernel \
$(SRC)/cpu \
$(SRC)/bsp \
$(SRC)/kernel/Cfg
CC:=$(PREFIX)gcc
CCFLAGS:= \
-ffreestanding \
-nostdlib \
-nostdinc \
-fno-stack-protector \
-O0 -ggdb \
-march=rv32gc \
$(foreach it,$(INCLUDE_PATH),-I$(it))
LD:=$(PREFIX)ld
OBJDUMP:=$(PREFIX)objdump
NM:=$(PREFIX)nm
QEMU:=qemu-system-riscv32
QEMUFLAGS:= \
-bios none \
-smp 1 \
-m 512M \
-nographic \
-machine virt
SRFILES:= \
$(SRC)/bsp/boot.s \
$(SRC)/bsp/bsp_init.c \
$(SRC)/bsp/uart.c \
$(SRC)/bsp/string.c \
$(SRC)/bsp/riscv.c \
$(SRC)/bsp/trap.s \
$(SRC)/cpu/cpu_a.S \
$(SRC)/cpu/cpu_core.c \
$(SRC)/cpu/os_cpu_a.S \
$(SRC)/cpu/os_cpu_c.c \
$(SRC)/kernel/os_sem.c \
$(SRC)/kernel/os_mem.c \
$(SRC)/kernel/os_stat.c \
$(SRC)/kernel/os_cfg_app.c \
$(SRC)/kernel/os_msg.c \
$(SRC)/kernel/os_task.c \
$(SRC)/kernel/os_var.c \
$(SRC)/kernel/os_core.c \
$(SRC)/kernel/os_mutex.c \
$(SRC)/kernel/os_tick.c \
$(SRC)/kernel/os_dbg.c \
$(SRC)/kernel/os_prio.c \
$(SRC)/kernel/os_time.c \
$(SRC)/kernel/os_flag.c \
$(SRC)/kernel/os_q.c \
$(SRC)/kernel/os_tmr.c \
$(SRC)/kernel/Cfg/os_app_hooks.c\
$(SRC)/main.c
OBJECTS:= $(patsubst $(SRC)/bsp/%.s,$(BUILD)/bsp/%.o,$(SRFILES))
OBJECTS:= $(patsubst $(SRC)/bsp/%.c,$(BUILD)/bsp/%.o,$(OBJECTS))
OBJECTS:= $(patsubst $(SRC)/cpu/%.S,$(BUILD)/cpu/%.o,$(OBJECTS))
OBJECTS:= $(patsubst $(SRC)/cpu/%.c,$(BUILD)/cpu/%.o,$(OBJECTS))
OBJECTS:= $(patsubst $(SRC)/kernel/%.S,$(BUILD)/kernel/%.o,$(OBJECTS))
OBJECTS:= $(patsubst $(SRC)/kernel/%.c,$(BUILD)/kernel/%.o,$(OBJECTS))
OBJECTS:= $(patsubst $(SRC)/kernel/Cfg/%.S,$(BUILD)/kernel/Cfg/%.o,$(OBJECTS))
OBJECTS:= $(patsubst $(SRC)/kernel/Cfg/%.c,$(BUILD)/kernel/Cfg/%.o,$(OBJECTS))
OBJECTS:= $(patsubst $(SRC)/%.c,$(BUILD)/%.o,$(OBJECTS))
DEBUGFILES:=\
$(shell find $(SRC) -name "*.c")\
$(shell find $(SRC) -name "*.s")\
$(shell find $(SRC) -name "*.S")
compile:$(BUILD)/kernel.elf\
$(BUILD)/kernel.asm\
$(BUILD)/kernel.map
qemu:$(BUILD)/kernel.elf\
$(BUILD)/kernel.asm\
$(BUILD)/kernel.map
$(QEMU) $(QEMUFLAGS) -kernel $<
qemuDbg:$(BUILD)/kernel.elf\
$(BUILD)/kernel.asm\
$(BUILD)/kernel.map
$(QEMU) $(QEMUFLAGS) -kernel $< -s -S
$(BUILD)/kernel.asm:$(BUILD)/kernel.elf
@mkdir -p $(dir $@)
$(OBJDUMP) -d $< > $@
$(BUILD)/kernel.map:$(BUILD)/kernel.elf
@mkdir -p $(dir $@)
$(NM) $< |sort >$@
$(BUILD)/kernel.elf:$(SRC)/kernel.ld $(OBJECTS)
@mkdir -p $(dir $@)
$(LD) -T $< $(OBJECTS) -o $@
$(BUILD)/bsp/%.o:$(SRC)/bsp/%.c
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/bsp/%.o:$(SRC)/bsp/%.s
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/cpu/%.o:$(SRC)/cpu/%.c
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/cpu/%.o:$(SRC)/cpu/%.S
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/kernel/%.o:$(SRC)/kernel/%.c
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/kernel/%.o:$(SRC)/kernel/%.S
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/kernel/Cfg/%.o:$(SRC)/kernel/Cfg/%.c
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/kernel/Cfg/%.o:$(SRC)/kernel/Cfg/%.S
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
$(BUILD)/%.o:$(SRC)/%.c
@mkdir -p $(dir $@)
$(CC) $(CCFLAGS) -c $^ -o $@
clean:
rm -rf $(BUILD)
debug:
@echo $(CCFLAGS)
.PHONY:clean debug compile qemu qemuDbg