OUTFILE = kernel
KOBJS = boot.o main.o cpu.o idt.o isrs.o ints.o vm86.o vm86asm.o

# default c compiler
ifndef CC
CC = gcc
endif

# default assembler
ifndef ASM
ASM = yasm
endif

#default linker
ifndef LD
LD = ld
endif

# default linker script
ifndef LDSCRIPT
LDSCRIPT = ldscript
endif

# default qemu command
ifndef QEMU
QEMU = qemu-system-i386
endif

# default qemu options
ifndef QEMUOPTIONS
QEMUOPTIONS = -debugcon stdio
endif

CFLAGS += -m32 -nostdinc -I. -fno-stack-protector -fno-pic -mno-sse
LDFLAGS += -melf_i386 -nostdlib -T$(LDSCRIPT)
ASMFLAGS += -f elf -w

ifdef DEBUG
CFLAGS += -ggdb
ASMFLAGS += -gstabs
endif

all: $(KOBJS)
	$(LD) $(LDFLAGS) $(KOBJS) -o $(OUTFILE)

%.o: %.asm
	$(ASM) $(ASMFLAGS) -o $@ $<

run: all
	$(QEMU) -kernel $(OUTFILE) $(QEMUOPTIONS)

clean:
	rm -rf $(KOBJS) $(OUTFILE)

.PHONY: clean run

