PICCFLAGS ?= -16f627a -DPIC -O -Zg 
PICLDFLAGS ?= -16f627a
PICC ?= picl

%.d: %.c
	$(SHELL) -ec '$(CC) -MM $(CPPFLAGS) $< \
		| sed '\''s/\($*\)\.o[ :]*/\1.obj $@ : /g'\'' > $@; \
		[ -s $@ ] || rm -f $@'

include $(sources:.c=.d)

.PHONY: clean burn

clean: 
	rm -f *.{d*,o,obj,sym,lst,map,cod,cof,dep,hex,as,rlf} *~

%.lst %.hex : %.asm
	gpasm $<

%.as : %.c
	cd $(dir $<) && $(PICC) $(PICCFLAGS) -S -c $(notdir $<)

%.o : %.asm
	gpasm -c $<

%.o : %.pal
	gpal -t -c $<

%.obj : %.c
	cd $(dir $<) && $(PICC) $(PICCFLAGS) -c $(notdir $<)

%.hex : %.obj
	$(PICC) $(PICLDFLAGS) -O$@ -o $^
