I'm now posting the second semi-complete part of my operating system makefile. The kernel itself is currently incomplete, so don't be surprised by the small size of the makefile. When the kernel expands, it will follow suit.
OFLAGS = -Ofast
DEBUGFLAGS = -g -g3 -ggdb3
TARGET = i686-elf
CC = gcc
INCDIR = -I kernel/include/
KERNEL = opal101
CFLAGS = -ffreestanding -Wall -Wextra -fno-exceptions -funsigned-char
LDFLAGS = -T linker.ld -Ofast -nostdlib -lgcc
AS = as
VPATH = kernel/arch/$(TARGET) $(shell find . -type d ! -name "arch"*)
include kernel/arch/$(TARGET)/Makefile
include kernel/drivers/vga/Makefile
include kernel/lib/Makefile
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
.PHONY: help all clean iso run debug
help:
@echo "make: Usage: make [target]";\
echo "Targets [run | iso | all | cleani | debug]"
debug: CFLAGS:= $(CFLAGS) $(DEBUGFLAGS)
debug: all
qemu-system-i386 --kernel $(KERNEL).bin -S -s& \
gdb-multiarch -s $(KERNEL).bin
run:iso
qemu-system-i386 -cdrom $(KERNEL).iso
iso: CFLAGS := $(CFLAGS) $(OFLAGS)
iso: all
mkdir -p $(KERNEL)/boot/grub;\
cp kernel/arch/i686-elf/stage2_eltorito $(KERNEL)/boot/grub;\
cp $(KERNEL).bin $(KERNEL)/boot;\
printf "default 0\n" >>menu.lst;\
printf "title %s\n" $(KERNEL) >>menu.lst;\
printf "kernel /boot/%s.bin" $(KERNEL) >>menu.lst;\
mv menu.lst $(KERNEL)/boot/grub;\
genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot \
-boot-load-size 4 -boot-info-table -o $(KERNEL).iso $(KERNEL)
all: $(KERNEL).bin
$(KERNEL).bin:$(OBJECTS)
$(TARGET)-$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $(KERNEL).bin
$(C_OBJECTS):%.o:%.c
$(TARGET)-$(CC) $(CFLAGS) -c $< -o $@ $(INCDIR)
$(ASM_OBJECTS): %.o:%.s
$(TARGET)-$(AS) $< -o $@
clean:
rm -rf *.o *.bin *.iso opal101/
I will show the kernel/lib/Makefile. All the rest are almost the same.
C_OBJECTS := $(C_OBJECTS) string.o
string.o:string.h
NOTE: I am not willing to use auto dependency generators because I found them very complex to learn and use, so please don't ask me to use them.