os/Makefile

47 lines
1.2 KiB
Makefile
Raw Normal View History

2018-10-19 07:59:38 -05:00
C_SOURCES = $(wildcard kernel/*.c drivers/*.c libc/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h libc/*.h)
2018-10-28 13:28:45 -05:00
OBJ = ${C_SOURCES:.c=.o drivers/interrupt.o drivers/paging_helpers.o kernel/loader.o}
2018-10-19 07:59:38 -05:00
CC = /usr/local/bin/i386-elf-gcc
GDB = /usr/local/bin/i386-elf-gdb
CFLAGS = -g
# First rule is run by default
2018-10-28 13:28:45 -05:00
os-image.bin: kernel/kernel.bin
cat $^ > $@
2018-10-19 07:59:38 -05:00
# '--oformat binary' deletes all symbols as a collateral, so we don't need
# to 'strip' them manually on this case
2018-10-28 13:28:45 -05:00
kernel/kernel.bin: ${OBJ} link.ld
i386-elf-ld -T link.ld -o $@ $^
2018-10-19 07:59:38 -05:00
# Used for debugging purposes
2018-10-28 13:28:45 -05:00
kernel.elf: ${OBJ}
i386-elf-ld -T link.ld -o $@ $^
2018-10-19 07:59:38 -05:00
run: os-image.bin
2018-10-28 13:28:45 -05:00
qemu-system-i386 -kernel os-image.bin
2018-10-19 07:59:38 -05:00
# Open the connection to qemu and load our kernel-object file with symbols
debug: os-image.bin kernel.elf
2018-10-28 13:28:45 -05:00
qemu-system-i386 -s -kernel os-image.bin &
2018-10-19 07:59:38 -05:00
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
# Generic rules for wildcards
# To make an object, always compile from its .c
%.o: %.c ${HEADERS}
${CC} ${CFLAGS} -ffreestanding -c $< -o $@
%.o: %.asm
nasm $< -f elf -o $@
2018-10-28 13:28:45 -05:00
%.o: %.s
i386-elf-as $< -o $@
2018-10-19 07:59:38 -05:00
%.bin: %.asm
nasm $< -f bin -o $@
clean:
2018-10-20 11:32:14 -05:00
rm -rf *.bin *.dis *.o os-image.bin *.elf boot/boot.bin
2018-10-19 07:59:38 -05:00
rm -rf */*.o