-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
108 lines (90 loc) · 3.11 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
include common.mk
.DEFAULT_GOAL := all
objdir := obj
depdir := $(objdir)/.deps
$(depdir):
@mkdir -p $@
depflags = -MMD -MP -MF $(depdir)/$*.d
OS := $(objdir)/os.elf
UCFLAGS = -Iinclude/ -g -O0 -T user/user.ld
UCFLAGS += $(CFLAGS)
# linuxheaders = /usr/src/linux-headers-$(shell uname -r)/include/
CFLAGS += -Iinclude/ -Ithirdparty/tinystl/include -Ithirdparty/eastl-port/include -Ithirdparty/eastl-port/test/packages/EABase/include/Common -Ithirdparty/linux -g
KCFLAGS = $(CFLAGS) -O0 -Werror=return-type
compile = $(CC) $(depflags) $(KCFLAGS)
# SBI: sbi/sbi.elf;
OS: $(OS);
all: OS #SBI
cp $(OS) kernel-qemu
ksrcs = $(shell find kernel/ -name "*.S") \
$(shell find kernel/ -name "*.cc")
utilsrcs = $(shell find utils/ -name "*.cc")
utilobjs = $(patsubst %.cc,$(objdir)/%.o,$(utilsrcs))
src3party = $(shell find thirdparty/ -name "*.cc")
eastl-srcs = $(wildcard thirdparty/eastl-port/source/*.cpp)
ksrcs += $(utilsrcs) $(src3party) $(eastl-srcs)
kobjs = $(addprefix $(objdir)/,$(addsuffix .o,$(basename $(ksrcs))))
depfiles := $(patsubst $(objdir)/%.o,$(depdir)/%.d,$(kobjs))
$(depfiles):
include $(wildcard $(depfiles))
$(info ksrcs=$(ksrcs), kobjs=$(kobjs), depfils=$(depfiles))
$(objdir)/%.o : %.cpp
@echo + CC $<
@mkdir -p $(dir $(depdir)/$*.d)
@mkdir -p $(dir $@)
$(compile) -c -o $@ $<
$(objdir)/%.o : %.cc
@echo + CC $<
@mkdir -p $(dir $(depdir)/$*.d)
@mkdir -p $(dir $@)
$(compile) -c -o $@ $<
$(objdir)/%.o : %.S
@echo + CC $<
@mkdir -p $(dir $(depdir)/$*.d)
@mkdir -p $(dir $@)
$(compile) -c -o $@ $<
uimg = $(objdir)/user/uimg.o
$(OS): $(kobjs) $(uimg)
$(info ksrcs=$(ksrcs), kobjs=$(kobjs))
@echo + CC $<
$(CC) $(KCFLAGS) -T kernel/os.ld -o $(OS) $^
usersrcs = $(shell find user/ -name "*.cc")
# userprogs := $(patsubst %.cc,$(objdir)/%.elf,$(usersrcs))
# userprogs := obj/riscv64/yield
userprogs := obj/user/init.elf
# userprogs := user/testsuits/clone
$(info utilobjs=$(utilobjs))
$(objdir)/user/%.elf : user/%.cc
@echo +CC $^
@mkdir -p $(dir $@)
$(CC) $(UCFLAGS) -o $@ $^
uprogs: $(userprogs)
$(uimg): $(userprogs)
$(OBJCOPY) -I binary -O elf64-littleriscv --binary-architecture riscv --prefix-sections=uimg $< $@
TEXTMODE=-nographic > obj/output
run: all
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel $(OS) -s ${TEXTMODE} 2> obj/log
testrun: all
rm -rf obj/*
rm -rf *.o *.bin *.elf
qemu-system-riscv64 -machine virt -kernel kernel-qemu -m 128M -nographic -smp 2 -bios default -drive file=tests/fat.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel $(OS) -s -S ${TEXTMODE} 2> obj/log &
@${GDB} $(OS) -q -x gdbinit && killall ${QEMU}
.PHONY : code
code: all
@${READELF} -a $(OS) > os-elf.txt
@${OBJDUMP} -S -D $(OS) >> os-elf.txt
@less os-elf.txt
.PHONY : clean
clean:
rm -rf obj/*
rm -rf *.o *.bin *.elf
.PHONY : stats
stats:
@echo $(shell find -regex ".*\.[h|c|S]+" | grep -v thirdparty |xargs cat | wc -l) lines