-
Notifications
You must be signed in to change notification settings - Fork 2
/
GNUmakefile
114 lines (97 loc) · 3.15 KB
/
GNUmakefile
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
# Nuke built-in rules and variables.
MAKEFLAGS += -rR
.SUFFIXES:
# Default user QEMU flags. These are appended to the QEMU command calls.
QEMUFLAGS := -m 2G
override IMAGE_NAME := template
# Toolchain for building the 'limine' executable for the host.
HOST_CC := cc
HOST_CFLAGS := -g -O2 -pipe
HOST_CPPFLAGS :=
HOST_LDFLAGS :=
HOST_LIBS :=
.PHONY: all
all: $(IMAGE_NAME).iso
.PHONY: all-hdd
all-hdd: $(IMAGE_NAME).hdd
.PHONY: run
run: $(IMAGE_NAME).iso
qemu-system-x86_64 \
-M q35 \
-cdrom $(IMAGE_NAME).iso \
-boot d \
$(QEMUFLAGS)
.PHONY: run-uefi
run-uefi: ovmf/ovmf-code-x86_64.fd $(IMAGE_NAME).iso
qemu-system-x86_64 \
-M q35 \
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-x86_64.fd,readonly=on \
-cdrom $(IMAGE_NAME).iso \
-boot d \
$(QEMUFLAGS)
.PHONY: run-hdd
run-hdd: $(IMAGE_NAME).hdd
qemu-system-x86_64 \
-M q35 \
-hda $(IMAGE_NAME).hdd \
$(QEMUFLAGS)
.PHONY: run-hdd-uefi
run-hdd-uefi: ovmf/ovmf-code-x86_64.fd $(IMAGE_NAME).hdd
qemu-system-x86_64 \
-M q35 \
-drive if=pflash,unit=0,format=raw,file=ovmf/ovmf-code-x86_64.fd,readonly=on \
-hda $(IMAGE_NAME).hdd \
$(QEMUFLAGS)
ovmf/ovmf-code-x86_64.fd:
mkdir -p ovmf
curl -Lo $@ https://github.com/osdev0/edk2-ovmf-nightly/releases/latest/download/ovmf-code-x86_64.fd
limine/limine:
rm -rf limine
git clone https://github.com/limine-bootloader/limine.git --branch=v8.x-binary --depth=1
$(MAKE) -C limine \
CC="$(HOST_CC)" \
CFLAGS="$(HOST_CFLAGS)" \
CPPFLAGS="$(HOST_CPPFLAGS)" \
LDFLAGS="$(HOST_LDFLAGS)" \
LIBS="$(HOST_LIBS)"
kernel-deps:
./kernel/get-deps
touch kernel-deps
.PHONY: kernel
kernel: kernel-deps
$(MAKE) -C kernel
$(IMAGE_NAME).iso: limine/limine kernel
rm -rf iso_root
mkdir -p iso_root/boot
cp -v kernel/bin/kernel iso_root/boot/
mkdir -p iso_root/boot/limine
cp -v limine.conf limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/boot/limine/
mkdir -p iso_root/EFI/BOOT
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT/
xorriso -as mkisofs -R -r -J -b boot/limine/limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
-apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
iso_root -o $(IMAGE_NAME).iso
./limine/limine bios-install $(IMAGE_NAME).iso
rm -rf iso_root
$(IMAGE_NAME).hdd: limine/limine kernel
rm -f $(IMAGE_NAME).hdd
dd if=/dev/zero bs=1M count=0 seek=64 of=$(IMAGE_NAME).hdd
PATH=$$PATH:/usr/sbin:/sbin sgdisk $(IMAGE_NAME).hdd -n 1:2048 -t 1:ef00
./limine/limine bios-install $(IMAGE_NAME).hdd
mformat -i $(IMAGE_NAME).hdd@@1M
mmd -i $(IMAGE_NAME).hdd@@1M ::/EFI ::/EFI/BOOT ::/boot ::/boot/limine
mcopy -i $(IMAGE_NAME).hdd@@1M kernel/bin/kernel ::/boot
mcopy -i $(IMAGE_NAME).hdd@@1M limine.conf limine/limine-bios.sys ::/boot/limine
mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTX64.EFI ::/EFI/BOOT
mcopy -i $(IMAGE_NAME).hdd@@1M limine/BOOTIA32.EFI ::/EFI/BOOT
.PHONY: clean
clean:
$(MAKE) -C kernel clean
rm -rf iso_root $(IMAGE_NAME).iso $(IMAGE_NAME).hdd
.PHONY: distclean
distclean: clean
$(MAKE) -C kernel distclean
rm -rf kernel-deps limine ovmf