-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
48 lines (36 loc) · 1.42 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
SRCS := $(shell find kernel/ -name "*.c" -o -name "*.s")
OBJS := $(patsubst %.c, %.o, $(patsubst %.s, %.o, $(SRCS)))
$(shell mkdir -p $(dir $(OBJS)))
CFLAGS = -m64 -Wall -Werror -std=gnu2x -Ikernel/include -ffreestanding -O0 -fno-stack-protector
ASFLAGS = -64
.PHONY: all run test clean format
all: cis-os.iso
cis-os.iso: kernel/kernel.elf boot/grub.cfg
mkdir -p isodir/boot/grub
cp kernel/kernel.elf isodir/boot/kernel.elf
cp boot/grub.cfg isodir/boot/grub/grub.cfg
cd initrd && find . -print | cpio -o -H newc > ../initrd.cpio && cd ..
cp initrd.cpio isodir/initrd.cpio
grub-mkrescue -o cis-os.iso isodir
kernel/kernel.elf: $(OBJS)
ld -z noexecstack -nostdlib -o $@ -T scripts/linker.ld $(OBJS)
%.o: %.c
gcc $(CFLAGS) -c -o $@ $<
%.o: %.s
as $(ASFLAGS) -o $@ $<
serial.log: cis-os.iso
timeout 10s qemu-system-x86_64 -vga vmware -display none -m 256 -cdrom $< -d guest_errors -serial file:$@ --no-reboot -no-shutdown || true
test: serial.log
cat $<
ls
grep -q '\[OK\]' $< && echo "Test passed." || (echo "Test failed." && exit 1)
run: cis-os.iso
qemu-system-x86_64 -vga vmware -m 256 -cdrom $< -d guest_errors -serial file:serial.log --no-reboot -no-shutdown
clean:
rm -rf isodir
rm -rf initrd.cpio
rm -rf kernel/kernel.elf cis-os.iso
find kernel/ -name "*.o" -delete
rm -f serial.log
format:
find . -type d -name "3rd" -prune -o -type f \( -name "*.c" -o -name "*.h" \) -print0 | xargs -0 clang-format -i -style=file