shadeos/Makefile

54 lines
1.5 KiB
Makefile
Raw Normal View History

2022-05-13 03:08:46 +00:00
ASM ?= nasm
CC := i686-elf-gcc
GDB := i686-elf-gdb
LD := i686-elf-ld
C_FILES = $(shell find src/ -type f -name '*.c')
CO_FILES = $(patsubst src/%.c, obj/%.o, $(C_FILES))
ASM_FILES = $(shell find src/kernel/ -type f -name '*.asm')
AO_FILES = $(patsubst src/kernel/%.asm, obj/kernel/%.o, $(ASM_FILES))
KERNEL_O_FILES = ${CO_FILES} ${AO_FILES}
iso: bin/shade.iso
obj/boot.o: src/boot.asm
$(ASM) -felf32 $^ -o $@
bin/shade.bin: obj/boot.o ${KERNEL_O_FILES}
mkdir -p bin
$(CC) -T src/linker.ld -ffreestanding -O2 -nostdlib $^ -o $@ -lgcc
grub-file --is-x86-multiboot bin/shade.bin
bin/shade.iso: bin/shade.bin
mkdir -p isodir/boot/grub
cp bin/shade.bin isodir/boot/shade.bin
cp src/iso/grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o bin/shade.iso isodir
rm -rf isodir
obj/%.o: src/%.c
mkdir -p "$(@D)"
$(CC) -ffreestanding -O2 -Wall -Wextra -c $< -o $@
obj/%.o: src/%.asm
mkdir -p "$(@D)"
$(ASM) -f elf $< -o $@
run: clean bin/shade.iso
2022-05-13 21:00:50 +00:00
qemu-system-x86_64 -hdd bin/shade.iso -d int -no-reboot
2022-05-13 03:08:46 +00:00
debug: clean bin/shade.iso bin/shade.bin
2022-05-13 21:00:50 +00:00
qemu-system-x86_64 -s -S -hdd bin/shade.iso -d int -no-reboot &
${GDB} os-image.bin -ex "set arch i386:x86-64" -ex "symbol-file bin/shade.bin" -ex "target remote localhost:1234"
2022-05-13 03:08:46 +00:00
clean:
find obj -type f -name '*.o' -exec rm {} +
find obj -type f -name '*.bin' -exec rm {} +
find bin -type f -name '*.o' -exec rm {} +
find bin -type f -name '*.bin' -exec rm {} +
find . -type f -name '*.dis' -exec rm {} +
rm -f kernel.elf
rm -rf isodir