TOOLPATH = ../../z_tools/
INCPATH  = ../../z_tools/haribote/
APILIBPATH   = ../apilib/
HARIBOTEPATH = ../haribote/
ASMLIB = asm

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
BIM2HRB  = $(TOOLPATH)bim2hrb.exe
BIM2BIN  = $(TOOLPATH)bim2bin.exe
RULEFILE = ../haribote.rul
EDIMG    = $(TOOLPATH)edimg.exe
IMGTOL   = $(TOOLPATH)imgtol.com
GOLIB    = $(TOOLPATH)golib00.exe 
COPY     = copy
DEL      = del

# デフォルト動作

default :
	$(MAKE) $(ASMLIB).obj
	$(MAKE) $(APP).hrb

# ファイル生成規則

$(APP).bim : $(APP).obj $(APILIBPATH)apilib.lib Makefile ../app_make.txt
	$(OBJ2BIM) @$(RULEFILE) out:$(APP).bim map:$(APP).map stack:$(STACK) \
		$(APP).obj $(ASMLIB).obj $(APILIBPATH)apilib.lib

# 一般規則

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

%.nas : %.gas Makefile ./app_make.txt
	$(GAS2NASK) $*.gas $*.nas

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

%.org : %.bim Makefile ./app_make.txt
	$(BIM2HRB) $*.bim $*.org $(MALLOC)

%.hrb : %.org Makefile ./app_make.txt
	$(BIM2BIN) -osacmp in:$*.org out:$*.hrb

# コマンド

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

clean :
	-$(DEL) *.lst
	-$(DEL) *.obj
	-$(DEL) *.map
	-$(DEL) *.bim
	-$(DEL) *.org

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