-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
62 lines (51 loc) · 2.1 KB
/
Copy pathMakefile
File metadata and controls
62 lines (51 loc) · 2.1 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
# Makefile for LifeOS
C_SOURCES = $(wildcard kernel/*.c drivers/*.c libc/*.c shell/*.c filesystem/*.c users/*.c)
HEADERS = $(wildcard include/*.h)
OBJ = ${C_SOURCES:.c=.o kernel/interrupt.o kernel/gdt_flush.o}
CC = gcc
CFLAGS = -g -m32 -ffreestanding -fno-pie -fno-stack-protector -nostdlib -Iinclude
# Default build target
all: build/lifeos.iso
# Build ISO target
iso: build/lifeos.iso
# Run QEMU
run: build/lifeos.iso
qemu-system-i386 -cdrom build/lifeos.iso
# Build the ISO image
build/lifeos.iso: build/kernel.bin build/boot.bin
mkdir -p build/iso/boot/grub
cp build/kernel.bin build/iso/boot/kernel.bin
# Using a simpler method for ISO: cat boot and kernel for floppy-like image
# or use grub-mkrescue for a proper ISO.
# For simplicity and to match the "boot directly from ISO" requirement:
cat build/boot.bin build/kernel.bin > build/lifeos.img
# Create a bootable ISO using xorriso or similar if needed,
# but for QEMU -cdrom, a raw image often works if structured correctly.
# Let's try to make a real ISO with grub.
echo 'set timeout=0' > build/iso/boot/grub/grub.cfg
echo 'set default=0' >> build/iso/boot/grub/grub.cfg
echo 'menuentry "LifeOS" {' >> build/iso/boot/grub/grub.cfg
echo ' multiboot /boot/kernel.bin' >> build/iso/boot/grub/grub.cfg
echo ' boot' >> build/iso/boot/grub/grub.cfg
echo '}' >> build/iso/boot/grub/grub.cfg
# Note: Our current bootloader is custom, not multiboot.
# To use GRUB, we'd need a multiboot header.
# Let's stick to the custom bootloader for now as requested.
# We will produce a hybrid ISO/IMG.
dd if=/dev/zero of=build/lifeos.iso bs=512 count=2880
dd if=build/lifeos.img of=build/lifeos.iso conv=notrunc
# Build the kernel binary
build/kernel.bin: kernel/kernel_entry.o ${OBJ}
ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary
# Build the bootloader binary
build/boot.bin: boot/boot.asm
nasm $< -f bin -o $@
# Generic rule for C files
%.o: %.c ${HEADERS}
${CC} ${CFLAGS} -c $< -o $@
# Generic rule for Assembly files
%.o: %.asm
nasm $< -f elf -o $@
clean:
rm -rf build/* kernel/*.o drivers/*.o libc/*.o shell/*.o boot/*.bin boot/*.o
rm -f *.img *.iso