# 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
export TARGET := i686-elf
export AR := llvm-ar
export NASM := nasm
export LD := ld.lld
export CXX := clang++
export CXX_FLAGS := -std=c++20 -ffreestanding \
-nostdlib -nostdinc -nostdinc++ \
-fno-exceptions -fno-rtti -Wall -Wextra -O2
CXX_INCLUDE := $(CURDIR)/libk
CXX_OBJ := kernel.o vga.o
# $@ is target
# $< is first dependency
# $^ is all dependencies
default: glitch.elf
check-grub: glitch.elf
grub-file --is-x86-multiboot2 glitch.elf
glitch.elf: boot.o $(CXX_OBJ) libk/libk.a
$(LD) -T linker.ld -o glitch.elf boot.o $(CXX_OBJ) -Llibk -lk
boot.o: boot.asm
$(NASM) -felf32 -o $@ $^
$(CXX_OBJ): %.o : %.cc
$(CXX) -target $(TARGET) $(CXX_FLAGS) -I$(CXX_INCLUDE) -c $^ -o $@
libk/libk.a:
$(MAKE) -C libk libk.a
iso: glitch.elf
mkdir -p isodir/boot/grub
cp glitch.elf isodir/boot/glitch.elf
cp grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o myos.iso isodir
run: glitch.elf
qemu-system-i386 -kernel glitch.elf
run-iso: iso
qemu-system-i386 -cdrom myos.iso
clean:
rm boot.o $(CXX_OBJ) glitch.elf
$(MAKE) -C libk clean
clean-iso:
rm -rf isodir