trios/Makefile

56 lines
1.3 KiB
Makefile
Raw Normal View History

2023-04-19 03:44:10 +00:00
CC=i386-elf-gcc
LD=i386-elf-ld
2023-04-21 13:39:35 +00:00
CFLAGS=-ffreestanding -ggdb -m32 -std=gnu17 -O3 -Wall -Wextra -pedantic -lgcc -isystem ./libk/include
2023-04-19 03:44:10 +00:00
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))
2023-04-28 23:17:17 +00:00
.PHONY: test all run clean mkdiskimg
2023-04-19 03:44:10 +00:00
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)
2023-04-21 13:39:35 +00:00
bin/kernel.bin: bin/libk.a linker.ld $(A_OBJ) $(C_OBJ)
2023-04-19 03:44:10 +00:00
@mkdir -p $(@D)
$(LD) -nmagic -o bin/kernel.bin -T linker.ld $(A_OBJ) $(C_OBJ) bin/libk.a
2023-04-21 13:39:35 +00:00
bin/os.iso: bin/kernel.bin grub.cfg
2023-04-19 03:44:10 +00:00
@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
2023-04-28 23:17:17 +00:00
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
2023-04-19 03:44:10 +00:00
clean:
rm -rf bin