-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
196 lines (148 loc) · 5.93 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
############ OPTIONS
include config.mk
############ GENERICS
RKERNEL_SRC = kernel/Cargo* \
kernel/rust-toolchain \
kernel/src/* \
kernel/src/memman/* \
kernel/src/arch/* \
kernel/.cargo/* \
# https://stackoverflow.com/questions/2483182/recursive-wildcards-in-gnu-make
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
# 1 = limine configure features
define compile_limine_base
cd limine && ./bootstrap
cd limine && make distclean || true
cd limine && ./configure $(1)
make -C limine
endef
# 1 = triple/target
# 2 = linked dependencies
# 3 = output filename
# 4 = linker
define compile_kernel
cd kernel/ && $(CARGO) build --target triple/$(1).json --lib $(if $(KERNEL_BUILD_RELEASE), --release, )
$(4) -T kernel/link/$(1).ld -o $(3) $(2) $(if $(KERNEL_BUILD_RELEASE), kernel/target/$(1)/release/libkernel.a, kernel/target/$(1)/debug/libkernel.a)
endef
# 1 = triple/target
define document_kernel
cd kernel/ && $(CARGO) doc --document-private-items --target triple/$(1).json
endef
# 1 = destination
# 2 = source
define link
$(1): $(2)
ln -f $(2) $(1)
endef
# 1 = destination
# 2 = source
define symlink
$(1): $(2)
rm -f $(1)
ln -sf $(2) $(1)
endef
############ x86_64 RECIEPES
RKERNEL_SRC_x86_64 = $(RKERNEL_SRC) kernel/src/arch/amd64/* kernel/triple/x86_64.json kernel/link/x86_64.ld
RKERNEL_DOC_x86_64 = kernel/target/x86_64/doc/kernel/
LIMINE_ARTIFACTS_x86_64 = $(PATH_LIMINE_BIN)/limine-deploy \
$(PATH_LIMINE_BIN)/limine.sys \
$(PATH_LIMINE_BIN)/limine-cd-efi.bin \
$(PATH_LIMINE_BIN)/limine-cd.bin
# these dependencies get copied on the boot partition
ISODEPS_x86_64 = build/isoroot_x86_64/kernel.bin \
build/isoroot_x86_64/limine-cd.bin \
build/isoroot_x86_64/limine-cd-efi.bin \
build/isoroot_x86_64/limine.sys \
build/isoroot_x86_64/limine.cfg
# main
build/RezOS-x86_64.iso: $(ISODEPS_x86_64) build/limine-deploy
xorriso -as mkisofs -b limine-cd.bin \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table --efi-boot limine-cd-efi.bin -efi-boot-part \
--efi-boot-image \
build/isoroot_x86_64/ -o $@
build/limine-deploy $@
@echo "Done!"
$(eval $(call link, build/isoroot_x86_64/kernel.bin, build/kernel.x86_64.bin ))
$(eval $(call link, build/isoroot_x86_64/limine.cfg, kernel/limine.cfg ))
$(eval $(call link, build/isoroot_x86_64/limine-cd.bin, $(PATH_LIMINE_BIN)/limine-cd.bin ))
$(eval $(call link, build/isoroot_x86_64/limine-cd-efi.bin, $(PATH_LIMINE_BIN)/limine-cd-efi.bin ))
$(eval $(call link, build/isoroot_x86_64/limine.sys, $(PATH_LIMINE_BIN)/limine.sys ))
$(eval $(call link, build/limine-deploy, $(PATH_LIMINE_BIN)/limine-deploy ))
$(LIMINE_ARTIFACTS_x86_64): $(call rwildcard limine/*)
$(call compile_limine_base, --enable-uefi-cd --enable-bios-cd)
make -C limine limine-deploy
# the kernel itself compiles to a static library that gets linked to kentry.asm which holds the entry point and some additional structures and functions (such as limine requests)
build/kernel.x86_64.bin: build/kentry.x86_64.o $(RKERNEL_SRC_x86_64)
mkdir -p build/isoroot_x86_64/
$(call compile_kernel,x86_64, $<, $@, ld)
build/kentry.x86_64.o: kernel/kentry/x86_64/*
mkdir -p build/
nasm -f elf64 kernel/kentry/x86_64/kentry.asm -o $@
isodeps_x86_64: $(ISODEPS_x86_64)
echo "Built all required dependencies!"
# docs
$(RKERNEL_DOC_x86_64): $(RKERNEL_SRC_x86_64)
$(call document_kernel,x86_64)
############ aarch64 RECIEPES
RKERNEL_SRC_aarch64 = $(RKERNEL_SRC) kernel/src/arch/arm64/* kernel/triple/aarch64.json kernel/link/aarch64.ld
RKERNEL_DOC_aarch64 = kernel/target/aarch64/doc/kernel/
ISODEPS_aarch64 = build/isoroot_aarch64/kernel.bin \
build/isoroot_aarch64/limine.cfg \
build/isoroot_aarch64/BOOTAA64.EFI
build/RezOS-aarch64.iso: $(ISODEPS_aarch64)
xorriso -as mkisofs \
-no-emul-boot \
-boot-info-table \
--efi-boot BOOTAA64.EFI -efi-boot-part \
--efi-boot-image \
build/isoroot_aarch64/ -o $@
@echo "Done!"
$(eval $(call link, build/isoroot_aarch64/kernel.bin, build/kernel.aarch64.bin ))
$(eval $(call link, build/isoroot_aarch64/limine.cfg, kernel/limine.cfg ))
$(eval $(call link, build/isoroot_aarch64/BOOTAA64.EFI, $(PATH_LIMINE_BIN)/BOOTAA64.EFI ))
$(PATH_LIMINE_BIN)/BOOTAA64.EFI: $(call rwildcard limine/*)
$(call compile_limine_base, --enable-uefi-aarch64)
build/kernel.aarch64.bin: build/kentry.aarch64.o $(RKERNEL_SRC_aarch64)
mkdir -p build/isoroot_aarch64/
$(call compile_kernel,aarch64, $<, $@, aarch64-linux-gnu-ld)
build/kentry.aarch64.o: kernel/kentry/aarch64/*
mkdir -p build/
aarch64-linux-gnu-as kernel/kentry/aarch64/kentry.S -o $@
# docs
$(RKERNEL_DOC_aarch64): $(RKERNEL_SRC_aarch64)
$(call document_kernel,aarch64)
############ COMMON RECIEPES
# visual representation of the build process
doc/buildflow.png: $(PATH_MAKEFILE2GRAPH) Makefile
make all -Bnd | $(PATH_MAKEFILE2GRAPH) -r | dot -Tpng -o $@
$(PATH_MAKEFILE2GRAPH):
cd makefile2graph && make
############ PHONY (commands, non file targets)
.PHONY: run clean deep-clean all doc
RUN_ARGS = -D log/qemu.log -cdrom
all: build/RezOS-x86_64.iso build/RezOS-aarch64.iso doc
@echo "Done all jobs!"
doc: doc/buildflow.png $(RKERNEL_DOC_aarch64) $(RKERNEL_DOC_x86_64)
@echo "Documentation generated!"
run-x86_64: build/RezOS-x86_64.iso
qemu-system-x86_64 $(RUN_ARGS) $^ $(QEMU_ARGS)
clean:
find build/ -type f -delete
rm -f log/*
rm -f doc/buildflow.png
deep-clean: clean clean-limine
rm -rf kernel/target/
rm -f $(PATH_MAKEFILE2GRAPH)
clean-limine:
cd limine
rm -f limine/bin/*
rm -f limine/cross-files/config.log
rm -f limine/cross-files/config.status
rm -f limine/cross-files/i686-toolchain.mk
distclean-limine:
cd limine && make distclean