MDCDIR = ../mdc
AS = asw
P2HEX = p2hex
PATCH_PREFIX = patch.

all: $(TARGET)
clean:
	rm -f $(subst .mdc,.o,$(TARGET)) $(subst .mdc,.lst,$(TARGET)) $(subst .mdc,.o,$(TARGET)) $(TARGET)
$(TYPE)mdc.d:
	ruby dep.rb $(MDCDIR) $(TARGET) > $@
-include $(TYPE)mdc.d

.SUFFIXES: .s .o .mot .mdc
.s.o:
	$(AS) $(ASFLAG) -L -o $@ $<
.o.mot:
	$(P2HEX) $< $@ -r $(ADDRESS_RANGE) -F moto
.mot.mdc:
	cat $(MDCDIR)/$(subst .mdc,.mdt,$@) > $@
	printf "$(PATCH_PREFIX)start\r\n" >> $@
	cat $< >> $@
	printf "$(PATCH_PREFIX)end\r\n" >> $@
	cp $@ $(MDCDIR)
