-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
58 lines (45 loc) · 1.4 KB
/
Copy pathMakefile
File metadata and controls
58 lines (45 loc) · 1.4 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
# Compilers and Assemblers
AS = nasm
CC = gcc
LD = ld
# Build Flags
ASFLAGS = -f elf64
CFLAGS = -ffreestanding -nostdlib -fno-pic -fno-pie -fno-stack-protector -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -mcmodel=kernel -m64 -O2
LDFLAGS = -n -T linker.ld
# Object files required for kernel
OBJS = boot.o kernel.o keyboard.o fs.o editor.o ata.o
# Binary and ISO output targets
BIN = iso/boot/xionos.bin
ISO = xionos.iso
INITRD = iso/boot/initrd.img
# Default rule: 'make' or 'make run' launches QEMU
all: run
# Create a persistent 10MB raw virtual hard disk (only created if disk.img doesn't exist)
disk.img:
qemu-img create -f raw disk.img 10M
# Run XionOS in QEMU with the virtual hard disk attached
run: $(ISO) disk.img
qemu-system-x86_64 -hda disk.img -cdrom $(ISO)
# Rule to create ISO image using GRUB
$(ISO): $(BIN) $(INITRD)
@mkdir -p iso/boot/grub
grub-mkrescue -o $(ISO) iso
# Rule to generate RAM disk image via Python script
$(INITRD): pack_fs.py
@mkdir -p iso/boot
python3 pack_fs.py
mv initrd.img $(INITRD)
# Rule to link kernel binary from object files
$(BIN): $(OBJS)
@mkdir -p iso/boot
$(LD) $(LDFLAGS) $(OBJS) -o $(BIN)
# Assembly compilation rule
boot.o: boot.asm
$(AS) $(ASFLAGS) boot.asm -o boot.o
# Generic C compilation rule
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Clean up ALL build artifacts (including fs.o and initrd)
clean:
rm -f *.o $(BIN) $(ISO) $(INITRD) disk.img
.PHONY: all run clean