TOOLPATH = ../../z_tools/
INCPATH  = ../../z_tools/haribote/

MAKE     = make.exe -r
ASM     = nasm
GAS2NASK = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM  = $(TOOLPATH)obj2bim.exe
MAKEFONT = $(TOOLPATH)makefont.exe
BIN2OBJ  = $(TOOLPATH)bin2obj.exe
BIM2HRB  = $(TOOLPATH)bim2hrb.exe
RULEFILE = ../haribote.rul
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
GOLIB    = $(TOOLPATH)golib00.exe 
COPY     = cp
DEL      = rm
OBJCOPY  = objcopy
OBJS = filesystem.obj screen.obj timer.obj desctable.obj naskfunc.obj pic.obj startup.obj debug.obj MemMan.obj ProcessMan.obj ThreadMan.obj
CFILES = filesystem.cpp screen.cpp timer.cpp desctable.cpp naskfunc.cpp pic.cpp startup.cpp debug.cpp MemMan.cpp ProcessMan.cpp ThreadMan.cpp
LIBS = ./ata/ataio.lib ../golibc/golibc.lib
CC = g++
BOOTPACKTARGET = bootpack.exe
CFLAGS = -g -c -nostdinc -fno-rtti -fno-builtin-alloca -I../include -Ig:/lib/boost -DBOOST_NO_EXCEPTIONS -DBOOST_SP_DISABLE_THREADS -DBOOST_DISABLE_ASSERTS -DBOOST_NO_AUTO_PTR -DBOOST_NO_IOSTREAM -masm=intel -std=c++0x

# ftHg

default :
	cd ata && $(MAKE)
	$(MAKE) mbr.bin
	$(MAKE) iplhd.bin
	$(MAKE) haribote.sys


# t@CK

mbr.bin : mbr.asm Makefile
	$(ASM) mbr.asm -o mbr.bin -l mbr.lst
	perl mbr.pl >> mbr.bin

iplhd.bin : iplhd.asm Makefile
	$(ASM) iplhd.asm -o iplhd.bin -l iplhd.lst

asmhead.bin : asmhead.asm Makefile
	$(ASM) asmhead.asm -o asmhead.bin -l asmhead.lst

bootpack.obj : bootpack.cpp Makefile
	$(CC) $(CFLAGS) bootpack.cpp -o bootpack.obj

$(BOOTPACKTARGET) : bootpack.obj $(OBJS) $(LIBS) Makefile
	g++ -shared  -Wl,--image-base=0x00280000 -e _user_start -static -nostdlib -lgcc_s -lgcc bootpack.obj $(OBJS) $(LIBS) -o $(BOOTPACKTARGET)
#	objcopy -j .text -I pe-i386 -O binary bootpack.dll bootpack.sys


haribote.sys : asmhead.bin $(BOOTPACKTARGET) Makefile
	cp asmhead.bin haribote.sys
	cat $(BOOTPACKTARGET) >> haribote.sys

naskfunc.obj : naskfunc.asm Makefile
	$(ASM) -f win32 naskfunc.asm -o naskfunc.obj -l naskfunc.lst


# ʋK

%.asm : %.gas Makefile
	$(GAS2NASK) $*.gas $*.asm

%.obj : %.cpp Makefile
	$(CC) $(CFLAGS) $*.cpp -o $*.obj


# R}h

clean :
	-$(DEL) mbr.bin
	-$(DEL) iplhd.bin
	-$(DEL) $(OBJS) bootpack.obj


src_only :
	$(MAKE) clean
	-$(DEL) haribote.sys

depend :
	makedepend --  -- $(CFILES) bootpack.cpp
	
# DO NOT DELETE

filesystem.obj: filesystem.h bootpack.h typedefs.h ata/ataio.h ata\dos.h
filesystem.obj: fat32.h screen.h debug.h
screen.obj: screen.h ata/ataio.h ata\dos.h bootpack.h typedefs.h hankaku.h
timer.obj: bootpack.h typedefs.h timer.h naskfunc.h pic.h
desctable.obj: bootpack.h typedefs.h desctable.h naskfunc.h screen.h
desctable.obj: ata/ataio.h ata\dos.h debug.h processman.h Vector.h MemMan.h
desctable.obj: FileSystem.h fat32.h ThreadMan.h
pic.obj: bootpack.h typedefs.h pic.h naskfunc.h
debug.obj: debug.h screen.h ata/ataio.h ata\dos.h bootpack.h typedefs.h
debug.obj: MemMan.h
MemMan.obj: MemMan.h typedefs.h naskfunc.h debug.h vector.h
ProcessMan.obj: ProcessMan.h typedefs.h Vector.h MemMan.h FileSystem.h
ProcessMan.obj: bootpack.h ata/ataio.h ata\dos.h fat32.h desctable.h
ProcessMan.obj: ThreadMan.h filesystem.h debug.h naskfunc.h
ThreadMan.obj: ThreadMan.h desctable.h typedefs.h MemMan.h Vector.h debug.h
ThreadMan.obj: ProcessMan.h FileSystem.h bootpack.h ata/ataio.h ata\dos.h
ThreadMan.obj: fat32.h
bootpack.obj: bootpack.h typedefs.h filesystem.h ata/ataio.h ata\dos.h
bootpack.obj: fat32.h screen.h timer.h desctable.h pic.h naskfunc.h MemMan.h
bootpack.obj: debug.h ProcessMan.h Vector.h FileSystem.h ThreadMan.h
