-
Notifications
You must be signed in to change notification settings - Fork 16
/
Makefile
150 lines (113 loc) · 4.9 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
arch ?= x86_64
target ?= $(arch)-sos-kernel-gnu
boot_target := x86_32-sos-bootstrap-gnu
boot_outdir := boot/target/$(boot_target)
iso := target/$(target)/debug/sos-$(arch).iso
kernel := target/$(target)/debug/sos_kernel
isofiles := target/$(target)/debug/isofiles
boot := $(boot_outdir)/debug/libboot.a
release_iso := target/$(target)/release/sos-$(arch).iso
release_kernel := target/$(target)/release/sos_kernel
release_isofiles := target/$(target)/release/isofiles
release_boot := $(boot_outdir)/release/libboot.a
grub_cfg := src/arch/$(arch)/grub.cfg
TIMESTAMP := $(shell /bin/date "+%Y-%m-%d-%H:%M:%S")
# wildcard paths
wild_iso := target/$(target)/%/sos-$(arch).iso
wild_kernel := target/$(target)/%/sos_kernel
wild_isofiles := target/$(target)/%/isofiles
#COLORS
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
# A category can be added with @category
HELP_FUN = \
%help; \
while(<>) { push @{$$help{$$2 // 'options'}}, [$$1, $$3] if /^([a-zA-Z\-]+)\s*:.*\#\#(?:@([a-zA-Z\-]+))?\s(.*)$$/ }; \
print "usage: make [target]\n\n"; \
for (sort keys %help) { \
print "${WHITE}$$_:${RESET}\n"; \
for (@{$$help{$$_}}) { \
$$sep = " " x (20 - length $$_->[0]); \
print " ${YELLOW}$$_->[0]${RESET}$$sep${GREEN}$$_->[1]${RESET}\n"; \
}; \
print "\n"; }
.PHONY: all clean kernel run iso cargo help gdb test doc release-iso release-run release-kernel
exception: $(iso) ##@build Run the kernel, dumping the state from QEMU if an exception occurs
@qemu-system-x86_64 -s -hda $(iso) -d int -no-reboot -serial file:$(CURDIR)/target/$(target)/serial-$(TIMESTAMP).log
cargo:
doc: ##@utilities Make RustDoc documentation
@xargo doc
help: ##@miscellaneous Show this help.
@perl -e '$(HELP_FUN)' $(MAKEFILE_LIST)
all: help
env: ##@utilities Install dev environment dependencies
./scripts/install-env.sh
clean: ##@utilities Delete all build artefacts.
@xargo clean
@cd boot && xargo clean
kernel: $(kernel).bin ##@build Compile the debug kernel binary
iso: $(iso) ##@build Compile the kernel binary and make an ISO image
run: run-debug ##@build Make the kernel ISO image and boot QEMU from it.
release-kernel: $(release_kernel).bin ##@release Compile the release kernel binary
release-iso: $(release_iso) ##@release Compile the release kernel binary and make an ISO image
release-run: run-release ##@release Make the release kernel ISO image and boot QEMU from it.
debug: $(iso) ##@build Run the kernel, redirecting serial output to a logfile.
@qemu-system-x86_64 -s -S -hda $(iso) -serial file:$(CURDIR)/target/$(target)/serial-$(TIMESTAMP).log
test: ##@build Test crate dependencies
@cargo test -p sos_intrusive
# @xargo test -p alloc
@cd alloc && cargo test
run-%: $(wild_iso)
@qemu-system-x86_64 -s -hda $<
$(wild_iso): $(wild_kernel).bin $(wild_isofiles) $(grub_cfg)
@cp $< $(word 2,$^)/boot/
@cp $(grub_cfg) $(word 2,$^)/boot/grub
grub-mkrescue -o $@ $(word 2,$^)/
@rm -r $(word 2,$^)
$(wild_isofiles):
@mkdir -p $@/boot/grub
$(boot):
@cd boot && RUST_TARGET_PATH="$(PWD)/targets" xargo rustc \
--target $(boot_target) \
-- --crate-type=staticlib
# Place 32-bit bootstrap code into a 64-bit ELF
@x86_64-pc-elf-objcopy -O elf64-x86-64 \
$(boot_outdir)/debug/libboot32.a \
$(boot_outdir)/debug/libboot.a
@x86_64-pc-elf-objcopy --strip-debug -G _start \
$(boot_outdir)/debug/libboot.a
# @cd $(boot_outdir)/debug && ar -crus libboot.a boot.o
$(release_boot):
@cd boot && RUST_TARGET_PATH="$(PWD)/targets" xargo rustc \
--target $(boot_target) \
-- --release \
--crate-type=staticlib
# Place 32-bit bootstrap code into a 64-bit ELF
@x86_64-pc-elf-objcopy -O elf64-x86-64 \
$(boot_outdir)/release/libboot32.a \
$(boot_outdir)/release/libboot.a
@x86_64-pc-elf-objcopy --strip-debug -G _start \
$(boot_outdir)/release/libboot.a
$(release_kernel): $(release_boot)
@RUST_TARGET_PATH="$(PWD)/targets" xargo build --target $(target) --release
$(release_kernel).bin: $(release_kernel)
@cp $(release_kernel) $(release_kernel).bin
$(release_iso): $(release_kernel).bin $(grub_cfg)
@mkdir -p $(release_isofiles)/boot/grub
@cp $(release_kernel).bin $(release_isofiles)/boot/
@cp $(grub_cfg) $(release_isofiles)/boot/grub
@grub-mkrescue -o $(release_iso) $(release_isofiles)/
@rm -r $(release_isofiles)
$(kernel): $(boot)
@RUST_TARGET_PATH="$(PWD)/targets" xargo build --target $(target)
$(kernel).debug: $(kernel)
@x86_64-elf-objcopy --only-keep-debug $(kernel) $(kernel).debug
$(kernel).bin: $(kernel) $(kernel).debug
@x86_64-elf-strip -g -o $(kernel).bin $(kernel)
@x86_64-elf-objcopy --add-gnu-debuglink=$(kernel).debug $(kernel)
gdb: $(kernel).bin $(kernel).debug ##@utilities Connect to a running QEMU instance with gdb.
@rust-os-gdb -ex "target remote tcp:127.0.0.1:1234" $(kernel)