CC=sdcc -mz80
AS=sdasz80
BIN=makebin
SMS=../tools/smscheckhead/smscheckhead
CFLAGS=-I../mggl/include -I../include
# We set the data location (for globals and statics) in the middle of the RAM
LDFLAGS=--no-std-crt0 --data-loc 0xD000

TARGET=newduel
SRCS=$(TARGET).c

DEPDIR = .deps
DEPS=$(SRCS:%.c=$(DEPDIR)/%.d)

# Remember, crt0.rel must always be first
OBJS=crt0.rel $(SRCS:%.c=%.rel)

all: $(DEPS) $(OBJS)
	$(CC) $(LDFLAGS) -o $(TARGET).ihx $(OBJS) ../mggl/src/mggl.lib
	$(BIN) $(TARGET).ihx $(TARGET).sms
	$(SMS) -f $(TARGET).sms

%.rel: %.c
	$(CC) $(CFLAGS) -c $<

%.rel: %.s
	$(AS) -o $@ $<

$(DEPDIR)/%.d: %.c
	@mkdir -p  $(DEPDIR)
	@$(CC) -M $(CFLAGS) $< > $(DEPDIR)/$*.d

clean:
	rm -f $(TARGET).bin* $(TARGET).sms* *~ *.rel *.sym *.lst *.asm *.noi *.map *.lnk *.ihx $(DEPS)

-include $(DEPS)
