CC := x86_64-elf-gcc
CC_FLAGS := -ffreestanding -nostdlib -fno-pic -mno-red-zone -Ilibc
DOOM_CC_FLAGS := $(CC_FLAGS) -std=gnu11

LD := x86_64-elf-ld

BUILDDIR := ../build
LIBDIR := libc

all: pedicel apex doom

.PHONY: pedicel
pedicel:
	nasm -f bin pedicel.S -o $(BUILDDIR)/pedicel.raw

.PHONY: apex
apex:
	$(CC) $(CC_FLAGS) -c apex.c -o $(BUILDDIR)/apex.o
	nasm -f elf64 $(LIBDIR)/crt0.S -o $(BUILDDIR)/crt0.o
	$(LD) -T $(LIBDIR)/linker.ld $(BUILDDIR)/crt0.o $(BUILDDIR)/apex.o -o $(BUILDDIR)/apex.elf
	objcopy -O binary $(BUILDDIR)/apex.elf $(BUILDDIR)/apex.raw

.PHONY: doom
doom:
	$(CC) $(DOOM_CC_FLAGS) -c doom.c -o $(BUILDDIR)/doom.o
	nasm -f elf64 $(LIBDIR)/crt0.S -o $(BUILDDIR)/crt0.o
	$(LD) -T $(LIBDIR)/linker.ld $(BUILDDIR)/crt0.o $(BUILDDIR)/doom.o -o $(BUILDDIR)/doom.elf
	objcopy -O binary $(BUILDDIR)/doom.elf $(BUILDDIR)/doom.raw