Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
- HEADERS = $(wildcard kernel/*.h drivers/*.h)
- # Nice syntax for file extension replacement
- OBJ = ${C_SOURCES:.c=.o}
- # Change this if your cross-compiler is somewhere else
- CC = gcc
- GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
- # -g: Use debugging symbols in gcc
- CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -std=gnu99
- # First rule is run by default
- os-image.bin: boot/boot.bin kernel.bin
- cat $^ > os-image.bin
- # '--oformat binary' deletes all symbols as a collateral, so we don't need
- # to 'strip' them manually on this case
- kernel.bin: kernel/kernel.o ${OBJ}
- ld -melf_i386 -o $@ -T link.ld $^ --oformat binary
- # Used for debugging purposes
- kernel.elf: kernel/kernel.o ${OBJ}
- ld -o $@ -Ttext 0x1000 $^
- run: os-image.bin
- qemu-system-i386 -fda os-image.bin
- # Open the connection to qemu and load our kernel-object file with symbols
- 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"
- # 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 $@
- %.bin: %.asm
- nasm $< -f bin -o $@
- clean:
- rm -rf *.bin *.dis os-image.bin *.elf
- rm -rf boot/*.bin drivers/*.o boot/*.o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement