generated from github/codespaces-blank
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
96 lines (70 loc) · 2.55 KB
/
Makefile
File metadata and controls
96 lines (70 loc) · 2.55 KB
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
include include.mk
lab ?= $(shell cat .mos-this-lab 2>/dev/null || echo 6)
target_dir := target
mos_elf := $(target_dir)/mos
user_disk := $(target_dir)/fs.img
link_script := kernel.lds
modules := lib init kern
targets := $(mos_elf)
syms_file := $(target_dir)/prog.syms
lab-ge = $(shell [ "$$(echo $(lab)_ | cut -f1 -d_)" -ge $(1) ] && echo true)
ifeq ($(call lab-ge,3),true)
user_modules += user/bare
endif
ifeq ($(call lab-ge,4),true)
user_modules += user
endif
ifeq ($(call lab-ge,5),true)
user_modules += fs
targets += fs-image
qemu_flags += -global virtio-mmio.force-legacy=false
qemu_flags += -drive file=${user_disk},if=none,format=raw,id=hd0
qemu_flags += -device virtio-blk-device,drive=hd0
endif
qemu_bin := qemu-system-riscv32
opensbi := sbi_bin/fw_dynamic.bin
qemu_flags += -machine virt -m 64M -nographic -bios $(opensbi)
CFLAGS += -DLAB=$(shell echo $(lab) | cut -f1 -d_)
objects := $(addsuffix /*.o, $(modules)) $(addsuffix /*.x, $(user_modules))
modules += $(user_modules)
.PHONY: all test tools $(modules) clean run dbg objdump fs-image clean-and-all
.ONESHELL:
clean-and-all: clean
$(MAKE) all
test: export test_dir = tests/lab$(lab)
test: clean-and-all
include mk/tests.mk mk/profiles.mk
export CC CFLAGS LD LDFLAGS lab
all: $(targets) objdump
nm target/mos > target/mos.map
$(target_dir):
mkdir -p $@
tools:
CC="$(HOST_CC)" CFLAGS="$(HOST_CFLAGS)" $(MAKE) --directory=$@
$(modules): tools
$(MAKE) --directory=$@
$(mos_elf): $(modules) $(target_dir)
$(LD) $(LDFLAGS) -o $(mos_elf) -T $(link_script) $(objects) $(LDLIBS)
fs-image: $(target_dir) user
$(MAKE) --directory=fs image fs-files="$(addprefix ../, $(fs-files))"
fs: user
user: lib
clean:
for d in $(modules) tools tools/readelf user/* tests/*; do
if [ -f $$d/Makefile ]; then
$(MAKE) --directory=$$d clean
fi
done
rm -rf *.o *~ $(target_dir) include/generated
find . -name '*.objdump' -exec rm {} ';'
dbg: qemu_flags += -no-reboot -s -S
dbg: objdump run
gdb:
$(CROSS_COMPILE)gdb --eval-command 'target remote :1234' $(mos_elf)
run:
$(qemu_bin) $(qemu_flags) -kernel $(mos_elf)
objdump:
@find * \( -name '*.b' -o -path $(mos_elf) \) -exec sh -c \
'$(CROSS_COMPILE)objdump {} -aldS > {}.objdump && echo {}.objdump' ';'
sbi:
$(MAKE) --directory=opensbi install CROSS_COMPILE=riscv64-unknown-elf- PLATFORM_RISCV_XLEN=32 PLATFORM=generic BUILD_INFO=y