# Make file for AD9851-based VFO
# 
# targets:
#   hex -- the Intel hex file to be made from the source C file
#   upload -- upload the hex file to the PIC attached to the PICkit2
#   run -- allow the target to run by releasing /MCLR
#   deviceid -- display the device ID, name and revision
#   clean -- tidy the directory of all non-source files
#
# configure by changing down to # <<<<
CHIP=16F887
PROGRAM=vfo-ad9851
ODIR=build
LIBS=
# <<<<

LOWERCASE_CHIP=$(shell echo $(CHIP) | tr '[:upper:]' '[:lower:]')

.DEFAULT_GOAL := upload

HEX=$(ODIR)/$(PROGRAM).hex

$(ODIR):
	mkdir $(ODIR)

$(HEX): $(PROGRAM).c $(ODIR) 
	xc8 $(PROGRAM).c --outdir=$(ODIR) --chip=$(CHIP) --msgdisable=1273,228 $(LIBS)

.PHONY: clean hex upload deviceid run sim

hex: $(HEX)

upload: $(HEX)
	pk2cmd -F$(HEX) -M -PPIC$(CHIP)

deviceid: 
	pk2cmd -I -PPIC$(CHIP)

run: 
	pk2cmd -R -PPIC$(CHIP)
	
sim: $(HEX)
	gpsim -L=.:./$(ODIR) -p p$(LOWERCASE_CHIP) $(HEX)
	
clean:
	rm -rf $(ODIR)
