55 lines
1.3 KiB
Makefile
55 lines
1.3 KiB
Makefile
CC=i386-elf-gcc
|
|
LD=i386-elf-ld
|
|
CFLAGS=-ffreestanding -ggdb -m32 -std=gnu17 -O3 -Wall -Wextra -pedantic -lgcc -isystem ./libk/include
|
|
|
|
C_SOURCE=$(shell find kernel -type f -name "*.c")
|
|
C_OBJ=$(patsubst %.c,bin/%.o,$(C_SOURCE))
|
|
|
|
A_SOURCE=$(shell find kernel -type f -name "*.asm")
|
|
A_OBJ=$(patsubst %.asm,bin/%_asm.o,$(A_SOURCE))
|
|
|
|
LIBK_SOURCE=$(shell find libk -type f -name "*.c")
|
|
LIBK_OBJ=$(patsubst %.c,bin/%.o,$(LIBK_SOURCE))
|
|
|
|
.PHONY: test all run clean mkdiskimg
|
|
|
|
all: bin/os.iso
|
|
|
|
$(A_OBJ): bin/%_asm.o : %.asm
|
|
@mkdir -p $(@D)
|
|
nasm $< -f elf -o $@
|
|
|
|
$(C_OBJ): bin/%.o : %.c
|
|
@mkdir -p $(@D)
|
|
$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
$(LIBK_OBJ): bin/%.o : %.c
|
|
@mkdir -p $(@D)
|
|
$(CC) -c $(CFLAGS) -o $@ $<
|
|
|
|
bin/libk.a: $(LIBK_OBJ)
|
|
@mkdir -p $(@D)
|
|
$(AR) rcs bin/libk.a $(LIBK_OBJ)
|
|
|
|
bin/kernel.bin: bin/libk.a linker.ld $(A_OBJ) $(C_OBJ)
|
|
@mkdir -p $(@D)
|
|
$(LD) -nmagic -o bin/kernel.bin -T linker.ld $(A_OBJ) $(C_OBJ) bin/libk.a
|
|
|
|
bin/os.iso: bin/kernel.bin grub.cfg
|
|
@mkdir -p $(@D)
|
|
@mkdir -p bin/iso/boot/grub
|
|
cp grub.cfg bin/iso/boot/grub
|
|
cp bin/kernel.bin bin/iso/boot
|
|
grub-mkrescue -o bin/os.iso bin/iso
|
|
|
|
bin/disk.img:
|
|
@mkdir -p bin
|
|
cp disk.img bin/disk.img
|
|
|
|
run: bin/os.iso bin/disk.img
|
|
qemu-system-i386 -cdrom bin/os.iso \
|
|
-drive file=bin/disk.img,format=raw,if=ide \
|
|
-boot order=d
|
|
|
|
clean:
|
|
rm -rf bin
|