GDK= E:/MDKit/
CC= $(GDK)bin/gcc
OBJC= $(GDK)bin/objcopy
ASMZ80= $(GDK)bin/asmz80
BINTOC= $(GDK)bin/bintoc
NM= $(GDK)bin/nm
NM2WCH= $(GDK)bin/nm2wch
OUTPUT= tfm-player
RESOL=bin

SRC_HEADER= sega.s
SRC_C= $(wildcard *.c)
SRC_SZ80= $(wildcard *.s80)


OBJ= $(SRC_HEADER:.s=.o)
OBJ+= $(SRC_SZ80:.s80=.o)
OBJ+= $(SRC_C:.c=.o)


LINKOBJ= $(OBJ)




FLAGS= $(OPTION) -m68000 -Wall -O1 -fomit-frame-pointer $(INCS)
FLAGSZ80= -c -i -x1 -x2 -x3 -z -lnul

all: $(OUTPUT).$(RESOL)


$(OUTPUT).$(RESOL): $(OUTPUT).out
	$(NM) -n -S -t x $(OUTPUT).out >$(OUTPUT).nm
	$(NM2WCH) $(OUTPUT).nm $(OUTPUT).wch
	$(OBJC) --pad-to 16384 -O binary $(OUTPUT).out $(OUTPUT).$(RESOL)

$(OUTPUT).out: $(OBJ)
	$(CC) -T $(GDK)bin/md.ld -nostdlib $(LINKOBJ) $(GDK)bin/libgcc.a -o $(OUTPUT).out


%.o80: %.s80
	$(ASMZ80) $(FLAGSZ80) -o$@ $<

%.c: %.o80
	$(BINTOC) $<

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

%.o: %.s
	$(CC) $(FLAGS) -c $< -o $@

clean:
	$(RM) *.o
	$(RM) $(OUTPUT).$(RESOL)
	$(RM) *.out
	$(RM) *.wch
	$(RM) *.nm
	$(RM) header/*.o
