54 lines
1.4 KiB
Makefile
54 lines
1.4 KiB
Makefile
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
|
|
qemu-system-x86_64 -hdd bin/shade.iso
|
|
|
|
debug: clean bin/shade.iso bin/shade.bin
|
|
qemu-system-x86_64 -s -S -hdd bin/shade.iso &
|
|
${GDB} os-image.bin -ex "symbol-file bin/shade.bin" -ex "target remote localhost:1234"
|
|
|
|
|
|
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
|