TARGET= kernel
MAPFILE= kernel.map
START= 0x100000
CC=/usr/bin/gcc
CXX=/usr/bin/g++
CFLAGS= -nostdlib -nostdinc -fno-stack-protector -Wall -fno-builtin -O2
CXXFLAGS= $(CFLAGS) -fno-exceptions -fno-rtti -fno-strict-aliasing -Wno-non-virtual-dtor
INCFLAGS= -I.
LDFLAGS= -Ttext $(START) -e start -Map $(MAPFILE)
OBJS=   boot.o kernel.o asmcore.o gdt.o idt.o intmgr.o crtbegin.o crtend.o memmgr.o timer.o list.o screen.o task.o keyboard.o shell.o

.c.o:
	$(CC) $(CFLAGS) $(INCFLAGS) -c $*.c
.cc.o:
	$(CXX) $(CXXFLAGS) $(INCFLAGS) -c $*.cc
.S.o:
	$(CC) $(CFLAGS) $(INCFLAGS) -c $*.S

all:    $(TARGET)
$(TARGET):      $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $(OBJS) 

clean::
	rm -f $(TARGET) $(MAPFILE) $(OBJS) *~

boot.o: Makefile types.h boot.S multiboot.h
kernel.o: Makefile types.h kernel.cc kernel.h multiboot.h timer.h idt.h gdt.h intmgr.h memmgr.h
gdt.o: Makefile gdt.h gdt.cc descripter.h types.h
idt.o: Makefile idt.h idt.cc descripter.h types.h
intmgr.o: Makefile types.h intmgr.cc intmgr.h ioport.h
memmgr.o: Makefile types.h memmgr.cc memmgr.h multiboot.h
asmcore.o: Makefile asmcore.S
crtbegin.o: Makefile types.h crtbegin.c
crtend.o: Makefile types.h crtend.c
timer.o: Makefile types.h timer.h timer.cc ioport.h list.h
list.o: Makefile types.h list.h list.cc
screen.o: Makefile types.h screen.h screen.cc
task.o: Makefile types.h task.h task.cc
keyboard.o: Makefile types.h keyboard.h keyboard.cc
shell.o: Makefile types.h shell.h shell.cc

install::	$(TARGET)
	sudo mount -t vfat /dev/fd0 ~/floppy
	sudo cp kernel ~/floppy/boot/.
	sudo umount ~/floppy
