APP      = gview
STACK    = 16m
MALLOC   = 0k
EXT = hrb

TOOLPATH = ../../z_tools/
INCPATH  = ../../z_tools/haribote/
APILIBPATH   = ../apilib/
HARIBOTEPATH = ../kernel/

MAKE       = $(TOOLPATH)make.exe -r
NASK       = $(TOOLPATH)nask.exe
CC1        = $(TOOLPATH)cc1.exe -I$(INCPATH) -I../ -Os -Wall -quiet
GAS2NASK   = $(TOOLPATH)gas2nask.exe -a
OBJ2BIM    = $(TOOLPATH)obj2bim.exe
MAKEFONT   = $(TOOLPATH)makefont.exe
BIN2OBJ    = $(TOOLPATH)bin2obj.exe
BIM2$(EXT) = $(TOOLPATH)bim2$(EXT).exe
BIM2BIN    = $(TOOLPATH)bim2bin.exe
RULEFILE   = ../tuos.rul
EDIMG      = $(TOOLPATH)edimg.exe
IMGTOL     = $(TOOLPATH)imgtol.com
GOLIB      = $(TOOLPATH)golib00.exe 
COPY       = copy
DEL        = del

# デフォルト動作

default :
	$(MAKE) $(APP).$(EXT)

# ファイル生成規則

$(APP).bim : $(APP).obj bmp.obj jpeg.obj $(APILIBPATH)apilib.lib Makefile
	$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \
		$(APP).obj jpeg.obj bmp.obj $(APILIBPATH)apilib.lib

tuos.img : ../kernel/$(IPLNAME).bin ../kernel/tuos.sys $(APP).$(EXT) \
		Makefile ../app_make.txt
	$(EDIMG)   imgin:../../z_tools/fdimg0at.tek \
		wbinimg src:../kernel/$(IPLNAME).bin len:512 from:0 to:0 \
		copy from:../kernel/tuos.sys to:@: \
		copy from:$(APP).$(EXT) to:@: \
		copy from:../nihongo/nihongo.fnt to:@: \
		imgout:tuos.img

# 一般規則

%.gas : %.c ../apilib.h Makefile
	$(CC1) -o $*.gas $*.c

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

%.obj : %.nas Makefile
	$(NASK) $*.nas $*.obj $*.lst

%.org : %.bim Makefile
	$(BIM2$(EXT)) $*.bim $*.org $(MALLOC)

%.$(EXT): %.org Makefile
	$(BIM2BIN) -osacmp in:$*.org out:$*.$(EXT)

# コマンド

run :
	$(MAKE) tuos.img
	$(COPY) tuos.img ..\..\z_tools\qemu\fdimage0.bin
	$(MAKE) -C ../../z_tools/qemu

full :
	$(MAKE) -C $(APILIBPATH)
	$(MAKE) $(APP).$(EXT)

run_full :
	$(MAKE) -C $(APILIBPATH)
	$(MAKE) -C ../tuos
	$(MAKE) run

clean :
	-$(DEL) *.lst
	-$(DEL) gview.obj
	-$(DEL) jpeg.obj
	-$(DEL) *.bim
	-$(DEL) *.org
	-$(DEL) tuos.img

src_only :
	$(MAKE) clean
	-$(DEL) $(APP).$(EXT)
