# https://www.gnu.org/software/make/manual/html_node/Setting.html
# := expanded variable, right-hand side can contain variables
# ?= only set if it doesn't have a value
# != execute a shell script on the right-hand side and assign its result to the left-hand side
TARGET := i686-elf
NASM := nasm
CXX := clang++
CXXFLAGS := -std=c++20 -ffreestanding -nostdinc -fno-exceptions -fno-rtti -Wall -Wextra -O2
INCLUDE := stdlib
OBJ := kernel.o vga.o stdlib/string.o stdlib/stdlib/console.o
# $@ is target
# $< is first dependency
# $^ is all dependencies
default: boot.o $(OBJ)
ld.lld -T linker.ld -o myos.bin boot.o $(OBJ)
boot.o: boot.asm
$(NASM) -felf32 -o $@ $^
$(OBJ): %.o : %.cc
$(CXX) -target $(TARGET) $(CXXFLAGS) -I$(INCLUDE) -c $^ -o $@
iso:
mkdir -p isodir/boot/grub
cp myos.bin isodir/boot/myos.bin
cp grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o myos.iso isodir
run:
qemu-system-i386 -kernel myos.bin
clean:
rm boot.o $(OBJ) myos.bin
clean-iso:
rm -rf isodir