cfenollosa_os-tutorial/14-checkpoint/Makefile

44 lines
1.1 KiB
Makefile
Raw Normal View History

2014-10-20 21:13:57 +00:00
C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
HEADERS = $(wildcard kernel/*.h drivers/*.h)
OBJ = ${C_SOURCES:.c=.o}
# Change this if your cross-compiler is somewhere else
CC = /usr/local/i386elfgcc/bin/i386-elf-gcc
GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
# -g: Use debugging symbols
CFLAGS = -g
# First rule is run by default
os-image.bin: boot/bootsect.bin kernel.bin
cat $^ > os-image.bin
2014-10-20 21:21:20 +00:00
kernel.bin: boot/kernel_entry.o ${OBJ}
2014-10-20 21:13:57 +00:00
i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary
2014-10-20 21:21:20 +00:00
# Used for debugging purposes
kernel.elf: boot/kernel_entry.o ${OBJ}
i386-elf-ld -o $@ -Ttext 0x1000 $^
2014-10-20 21:13:57 +00:00
run: os-image.bin
qemu-system-i386 -fda os-image.bin
debug: os-image.bin kernel.elf
qemu-system-i386 -s -fda os-image.bin &
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
# To make an object, always compile from its .c
%.o: %.c ${HEADERS}
${CC} ${CFLAGS} -ffreestanding -c $< -o $@
# Object files from asm files
%.o: %.asm
nasm $< -f elf -o $@
%.bin: %.asm
nasm $< -f bin -o $@
clean:
rm -rf *.bin *.dis *.o os-image.bin *.elf
rm -rf kernel/*.o boot/*.bin drivers/*.o