-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
103 lines (76 loc) · 2.78 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
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
empty_disk := $(target_dir)/empty.img
swap_disk := $(target_dir)/swap.img
qemu_pts := $(shell [ -f .qemu_log ] && grep -Eo '/dev/pts/[0-9]+' .qemu_log)
link_script := kernel.lds
modules := lib init kern
targets := $(mos_elf)
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
endif
objects := $(addsuffix /*.o, $(modules)) $(addsuffix /*.x, $(user_modules))
modules += $(user_modules)
CFLAGS += -DLAB=$(shell echo $(lab) | cut -f1 -d_)
QEMU_FLAGS += -cpu 4Kc -m 64 -nographic -M malta \
$(shell [ -f '$(user_disk)' ] && echo '-drive id=ide0,file=$(user_disk),if=ide,format=raw') \
$(shell [ -f '$(empty_disk)' ] && echo '-drive id=ide1,file=$(empty_disk),if=ide,format=raw') \
$(shell [ -f '$(swap_disk)' ] && echo '-drive id=swap,file=$(swap_disk),if=ide,format=raw') \
-no-reboot
.PHONY: all test tools $(modules) clean run dbg_run dbg_pts dbg objdump fs-image clean-and-all connect
.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)
$(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) -N -T $(link_script) $(objects)
fs-image: $(target_dir) user
$(MAKE) --directory=fs image fs-files="$(addprefix ../, $(fs-files))"
fs: user
user: lib
clean:
for d in * 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 {} ';'
run:
$(QEMU) $(QEMU_FLAGS) -kernel $(mos_elf)
dbg_run:
$(QEMU) $(QEMU_FLAGS) -kernel $(mos_elf) -s -S
dbg:
export QEMU="$(QEMU)"
export QEMU_FLAGS="$(QEMU_FLAGS)"
export mos_elf="$(mos_elf)"
setsid ./tools/run_bg.sh $$$$ &
exec gdb-multiarch -q $(mos_elf) -ex "target remote localhost:1234"
dbg_pts: QEMU_FLAGS += -serial "pty"
dbg_pts: dbg
connect:
[ -f .qemu_log ] && screen -R mos $(qemu_pts)
objdump:
@find * \( -name '*.b' -o -path $(mos_elf) \) -exec sh -c \
'$(CROSS_COMPILE)objdump {} -aldS > {}.objdump && echo {}.objdump' ';'