-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
105 lines (86 loc) · 2.7 KB
/
Copy pathMakefile
File metadata and controls
105 lines (86 loc) · 2.7 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
97
98
99
100
101
102
103
104
105
ASM_SOURCES = $(shell find kernel/src/ -type f -name '*.asm')
C_SOURCES = $(shell find kernel/src/ -type f -name '*.c')
C_SOURCES += $(shell find kernel/acpi/ -type f -name '*.c')
LD_SCRIPT = link.ld
ASM_OBJS = $(ASM_SOURCES:.asm=.o)
C_OBJS = $(C_SOURCES:.c=.o)
TARGET = kernel.elf
ISO = BrickOS.iso
CC = clang
LLD = ld.lld
AS = nasm
HOST_CC := $(CC)
HOST_CFLAGS := -g -O2 -pipe
HOST_CPPFLAGS :=
HOST_LDFLAGS :=
HOST_LIBS :=
CFLAGS = -target x86_64-elf -ffreestanding -m64 -nostdlib \
-fno-builtin -fno-stack-protector -fno-exceptions -g \
-Wno-pointer-sign -fno-pic -fno-pie -mcmodel=kernel -O1
# idgaf about casting const char* to char*
CFLAGS += -Ikernel/acpi/uacpi/include -DUACPI_ARCH_X86_64
LDFLAGS = \
-nostdlib \
-static \
-z max-page-size=0x1000 \
--gc-sections \
-T $(LD_SCRIPT)
all: $(ISO)
.PHONY: always_run
always_run:
make -C iso/modules
bash limine_conf_gen.sh
%.o: %.asm
$(AS) -g -f elf64 $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(TARGET): limine/limine $(ASM_OBJS) $(C_OBJS)
$(LLD) $(LDFLAGS) $(ASM_OBJS) $(C_OBJS) -o $(TARGET)
limine/limine:
rm -rf limine
git clone https://codeberg.org/Limine/Limine.git limine --branch=v10.x-binary --depth=1
$(MAKE) -C limine \
CC="$(HOST_CC)" \
CFLAGS="$(HOST_CFLAGS)" \
CPPFLAGS="$(HOST_CPPFLAGS)" \
LDFLAGS="$(HOST_LDFLAGS)" \
LIBS="$(HOST_LIBS)"
kernel/.deps-obtained:
bash kernel/get-deps.sh
$(ISO): always_run kernel/.deps-obtained $(TARGET)
rm -rf iso_root
mkdir -p iso_root/boot
cp -v $(TARGET) iso_root/boot/
mkdir -p iso_root/modules
mkdir -p iso_root/modules/images
cp -v iso/modules/*.elf iso_root/modules
cp -v iso/modules/images/*.qoi iso_root/modules/images
mkdir -p iso_root/boot/limine
cp -v limine.conf iso_root/boot/limine
mkdir -p iso_root/EFI/BOOT
cp -v limine/limine-bios.sys limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/boot/limine/
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 $(ISO)
./limine/limine bios-install $(ISO)
rm -rf iso_root
run: $(ISO)
qemu-img create -f raw hdd.img 256M
qemu-system-x86_64 -s \
-drive file=hdd.img,format=raw,if=ide \
-serial file:serial.log \
-boot d \
-cdrom $(ISO) \
-m 512M \
-vga qxl \
-netdev tap,id=net0,ifname=tap0,script=no,downscript=no \
-device e1000,netdev=net0
clean:
rm -f $(ASM_OBJS) $(C_OBJS) $(TARGET) $(ISO)
rm -rf limine
make -C iso/modules clean
rm hdd.img