]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - Makefile
Refactor Makefile, linker script, properly set up stack
[nameless-os.git] / Makefile
index 738fb0c89192daa87e3ca2a3c2e65e1b6a43fcd7..8ffcdf86123bb9b1acee0fe0ab3746d4d339cfbb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,24 +7,24 @@ GIT_REV = $(shell git rev-parse --short HEAD)
 CFLAGS = -std=gnu89 -g -Iinclude/arch/x86 -ffreestanding -DGIT_COMMIT=\"$(GIT_REV)\"
 
 KERNEL_OBJ = kernel/entry.o kernel/arch/x86/tty/tty.o kernel/drivers/irq/i8259a.o kernel/arch/x86/irq/idt.o kernel/arch/x86/irq/sample_handler.o kernel/kernel.o
+BOOTLOADER_OBJ = boot/x86/mbr boot/x86/vbr-fat32 boot/x86/stage3/LOADER.BIN
 
 default: kernel/kernel.elf bootloader
 
 all: default boot/x86/disk.img
 
-bootloader: boot/x86/mbr boot/x86/vbr-fat32 boot/x86/stage3/LOADER.BIN
+bootloader: $(BOOTLOADER_OBJ)
 
 run: all
        $(QEMU) boot/x86/disk.img
 
 boot/x86/mbr: boot/x86/mbr.s
-       $(MAKE) -C boot/x86
 boot/x86/vbr-fat32: boot/x86/vbr-fat32.s boot/x86/fat32/*.s 
-       $(MAKE) -C boot/x86
 boot/x86/stage3/LOADER.BIN: boot/x86/stage3/*.s boot/x86/fat32/*.s
+$(BOOTLOADER_OBJ):
        $(MAKE) -C boot/x86
 
-boot/x86/disk.img: boot/x86/mbr boot/x86/vbr-fat32 boot/x86/stage3/LOADER.BIN boot/x86/disk.dump 
+boot/x86/disk.img: boot/x86/mbr boot/x86/vbr-fat32 boot/x86/stage3/LOADER.BIN boot/x86/disk.dump kernel/kernel.bin
        truncate -s1G boot/x86/disk.img
        sfdisk boot/x86/disk.img < boot/x86/disk.dump
        mkfs.fat -F 32 --offset 2048 boot/x86/disk.img
@@ -33,20 +33,23 @@ boot/x86/disk.img: boot/x86/mbr boot/x86/vbr-fat32 boot/x86/stage3/LOADER.BIN bo
        mcopy -i boot/x86/disk.img@@1M boot/x86/stage3/LOADER.BIN ::.
        mcopy -i boot/x86/disk.img@@1M kernel/kernel.bin ::./KERNEL.BIN
 
-kernel/kernel.bin: ${KERNEL_OBJ}
+kernel/kernel.bin: ${KERNEL_OBJ} kernel/linker.ld
        $(CC) -ffreestanding -nostdlib -o $@ -T kernel/linker.ld ${KERNEL_OBJ}
 
 kernel/entry.o: kernel/entry.s
-       $(AS) -f elf kernel/entry.s -o $@
+       $(AS) -f elf $< -o $@
 
 kernel/arch/x86/irq/sample_handler.o: kernel/arch/x86/irq/sample_handler.c
-       $(CC) $(CFLAGS) -mgeneral-regs-only -c kernel/arch/x86/irq/sample_handler.c -o $@
+       $(CC) $(CFLAGS) -mgeneral-regs-only -c $< -o $@
 
 kernel/kernel.elf: kernel/kernel.bin
        $(CC) -ffreestanding -nostdlib -o $@ -T kernel/linker.ld ${KERNEL_OBJ} -Wl,--oformat=elf32-i386
+       i686-elf-objcopy --only-keep-debug kernel/kernel.elf kernel/kernel.dbg
+       i686-elf-objcopy --add-gnu-debuglink=kernel/kernel.dbg kernel/kernel.elf
+       i686-elf-strip --strip-unneeded kernel/kernel.elf
 
 clean:
-       -rm kernel/kernel.bin kernel/kernel.elf ${KERNEL_OBJ}
+       -rm kernel/kernel.{bin,dbg,elf} ${KERNEL_OBJ}
        cd boot/x86 && $(MAKE) clean
 
 .PHONY: default all clean run bootloader