# Makefile for poet OS

AS = as
AFLAGS = -traditional

AR = ar

CC = gcc
CFLAGS = 

DC = gdc
DFLAGS = -nostdlib -fno-builtin -frelease -Wall -O3 -inline -I$(BUILD_ROOT)

MAKE = /bin/make
OBJCOPY = objcopy

CAT = cat

INCLUDES = 
ARCH = i386
POET = poet

LD = ld
LDFLAGS =

OBJS = os/i386/ipl.o\
	os/i386/setup.o\
	os/i386/interrupt.o\
	os/i386/ihandler.o\
	os/i386/io.o\
	os/i386/memorymap.o\
	os/i386/sync.o\
	os/i386/bitmap.o\
	os/i386/page.o\
	os/i386/pic8259a.o\
	os/i386/cache.o\
	os/i386/segment.o\
	os/i386/serial.o\
	os/i386/startup.o\
	os/i386/process.o\
	os/i386/switchto.o\
	os/i386/tss.o\
	os/i386/systemcall.o\
	drt/algorithm.o\
	drt/format.o\
	drt/list.o\
	drt/stream.o\
	object.o\
	std/array.o\
	std/c/stdarg.o\
	std/c/string.o\
	std/gc.o\
	std/llmath.o\
	std/math.o\
	std/metastrings.o\
	std/moduleinit.o\
	std/stdarg.o\
	std/stdint.o\
	std/string.o\
	std/typeinfo/ti_Aa.o\
	std/typeinfo/ti_AC.o\
	std/typeinfo/ti_Acdouble.o\
	std/typeinfo/ti_Acfloat.o\
	std/typeinfo/ti_Acreal.o\
	std/typeinfo/ti_Adchar.o\
	std/typeinfo/ti_Adouble.o\
	std/typeinfo/ti_Afloat.o\
	std/typeinfo/ti_Ag.o\
	std/typeinfo/ti_Aint.o\
	std/typeinfo/ti_Along.o\
	std/typeinfo/ti_Areal.o\
	std/typeinfo/ti_Ashort.o\
	std/typeinfo/ti_Aubyte.o\
	std/typeinfo/ti_Auint.o\
	std/typeinfo/ti_Aulong.o\
	std/typeinfo/ti_Aushort.o\
	std/typeinfo/ti_Awchar.o\
	std/typeinfo/ti_byte.o\
	std/typeinfo/ti_C.o\
	std/typeinfo/ti_cdouble.o\
	std/typeinfo/ti_cfloat.o\
	std/typeinfo/ti_char.o\
	std/typeinfo/ti_creal.o\
	std/typeinfo/ti_dchar.o\
	std/typeinfo/ti_delegate.o\
	std/typeinfo/ti_double.o\
	std/typeinfo/ti_float.o\
	std/typeinfo/ti_idouble.o\
	std/typeinfo/ti_ifloat.o\
	std/typeinfo/ti_int.o\
	std/typeinfo/ti_ireal.o\
	std/typeinfo/ti_long.o\
	std/typeinfo/ti_ptr.o\
	std/typeinfo/ti_real.o\
	std/typeinfo/ti_short.o\
	std/typeinfo/ti_ubyte.o\
	std/typeinfo/ti_uint.o\
	std/typeinfo/ti_ulong.o\
	std/typeinfo/ti_ushort.o\
	std/typeinfo/ti_void.o\
	std/typeinfo/ti_wchar.o\
	std/unwind.o\

KERNEL_EXE = kernel.exe
IPL_BIN = ipl.bin
KERNEL_BIN = kernel.bin
LINKER_SCRIPT = i386.ls

# rule

%.o: %.d
	$(DC) $(DFLAGS) $(INCLUDES) -o $@ -c $<

%.o: %.c
	$(CC) $(CFLAGS) $(INCLUDES) -o $@  -c $<

%.o: %.s
	$(AS) $(ASFLAGS) $(INCLUDES) -o $@ $<

%.bin: %.o
	$(LD) $(LDFLAGS) -o $@ $<
	$(OBJCOPY) -O binary $@ $@

TARGET = $(POET)
BUILD_ROOT = $(CURDIR)

QEMU_DIR=../qemu
QEMU=qemu.exe
QEMU_RAM=128

export BUILD_ROOT

DD = dd
FD_IMAGE = floppy.img
FD_BLOCKS = 2880

# target

.PHONY: all run clean kernel drt

all: $(FD_IMAGE)

run:
	$(QEMU_DIR)/$(QEMU) -L $(QEMU_DIR) -m $(QEMU_RAM) -fda $(FD_IMAGE)

clean:
	-rm -f $(TARGET) $(FD_IMAGE) $(OBJS)

# dependencies

$(FD_IMAGE): $(POET)
	$(DD) if=/dev/zero of=$@ count=$(FD_BLOCKS)
	$(DD) if=$(TARGET) of=$@ conv=notrunc

$(POET): $(KERNEL_EXE)
	$(OBJCOPY) -S -O binary $^ $@

$(KERNEL_EXE): $(OBJS)
	$(LD) $(LDFLAGS) -T $(LINKER_SCRIPT) -o $@ $^ $(LIB_FLAGS)

os/i386/ipl.o: os/i386/ipl.s
os/i386/setup.o: os/i386/setup.s
os/i386/interrupt.o: os/i386/interrupt.d
os/i386/ihandler.o: os/i386/ihandler.s
os/i386/io.o: os/i386/io.d
os/i386/sync.o: os/i386/sync.d
os/i386/memorymap.o: os/i386/memorymap.d
os/i386/bitmap.o: os/i386/bitmap.d
os/i386/page.o: os/i386/page.d
os/i386/pic8259a.o: os/i386/pic8259a.d
os/i386/cache.o: os/i386/cache.d
os/i386/segment.o: os/i386/segment.d
os/i386/serial.o: os/i386/serial.d
os/i386/startup.o: os/i386/startup.d
os/i386/process.o: os/i386/process.d
os/i386/switchto.o: os/i386/switchto.s
os/i386/tss.o: os/i386/tss.d
os/i386/systemcall.o: os/i386/systemcall.d
drt/algorithm.o: drt/algorithm.d
drt/format.o: drt/format.d
drt/list.o: drt/list.d
drt/stream.o: drt/stream.d
object.o: object.d
std/array.o: std/array.d
std/c/stdarg.o: std/c/stdarg.d
std/c/string.o: std/c/string.d
std/gc.o: std/gc.d
std/llmath.o: std/llmath.d
std/math.o: std/math.d
std/metastrings.o: std/metastrings.d
std/moduleinit.o: std/moduleinit.d
std/stdarg.o: std/stdarg.d
std/stdint.o: std/stdint.d
std/string.o: std/string.d
std/typeinfo/ti_Aa.o: std/typeinfo/ti_Aa.d
std/typeinfo/ti_AC.o: std/typeinfo/ti_AC.d
std/typeinfo/ti_Acdouble.o: std/typeinfo/ti_Acdouble.d
std/typeinfo/ti_Acfloat.o: std/typeinfo/ti_Acfloat.d
std/typeinfo/ti_Acreal.o: std/typeinfo/ti_Acreal.d
std/typeinfo/ti_Adchar.o: std/typeinfo/ti_Adchar.d
std/typeinfo/ti_Adouble.o: std/typeinfo/ti_Adouble.d
std/typeinfo/ti_Afloat.o: std/typeinfo/ti_Afloat.d
std/typeinfo/ti_Ag.o: std/typeinfo/ti_Ag.d
std/typeinfo/ti_Aint.o: std/typeinfo/ti_Aint.d
std/typeinfo/ti_Along.o: std/typeinfo/ti_Along.d
std/typeinfo/ti_Areal.o: std/typeinfo/ti_Areal.d
std/typeinfo/ti_Ashort.o: std/typeinfo/ti_Ashort.d
std/typeinfo/ti_Aubyte.o: std/typeinfo/ti_Aubyte.d
std/typeinfo/ti_Auint.o: std/typeinfo/ti_Auint.d
std/typeinfo/ti_Aulong.o: std/typeinfo/ti_Aulong.d
std/typeinfo/ti_Aushort.o: std/typeinfo/ti_Aushort.d
std/typeinfo/ti_Awchar.o: std/typeinfo/ti_Awchar.d
std/typeinfo/ti_byte.o: std/typeinfo/ti_byte.d
std/typeinfo/ti_C.o: std/typeinfo/ti_C.d
std/typeinfo/ti_cdouble.o: std/typeinfo/ti_cdouble.d
std/typeinfo/ti_cfloat.o: std/typeinfo/ti_cfloat.d
std/typeinfo/ti_char.o: std/typeinfo/ti_char.d
std/typeinfo/ti_creal.o: std/typeinfo/ti_creal.d
std/typeinfo/ti_dchar.o: std/typeinfo/ti_dchar.d
std/typeinfo/ti_delegate.o: std/typeinfo/ti_delegate.d
std/typeinfo/ti_double.o: std/typeinfo/ti_double.d
std/typeinfo/ti_float.o: std/typeinfo/ti_float.d
std/typeinfo/ti_idouble.o: std/typeinfo/ti_idouble.d
std/typeinfo/ti_ifloat.o: std/typeinfo/ti_ifloat.d
std/typeinfo/ti_int.o: std/typeinfo/ti_int.d
std/typeinfo/ti_ireal.o: std/typeinfo/ti_ireal.d
std/typeinfo/ti_long.o: std/typeinfo/ti_long.d
std/typeinfo/ti_ptr.o: std/typeinfo/ti_ptr.d
std/typeinfo/ti_real.o: std/typeinfo/ti_real.d
std/typeinfo/ti_short.o: std/typeinfo/ti_short.d
std/typeinfo/ti_ubyte.o: std/typeinfo/ti_ubyte.d
std/typeinfo/ti_uint.o: std/typeinfo/ti_uint.d
std/typeinfo/ti_ulong.o: std/typeinfo/ti_ulong.d
std/typeinfo/ti_ushort.o: std/typeinfo/ti_ushort.d
std/typeinfo/ti_void.o: std/typeinfo/ti_void.d
std/typeinfo/ti_wchar.o: std/typeinfo/ti_wchar.d
std/unwind.o: std/unwind.d
