# Adjust the EASYDIR value to match your installation
# Adjust the all: rule to match your build requirements
#
EASYDIR= c:/easyC/
VEXDIR=$(EASYDIR)VeX/

# The easyC tools don't deal well with fully qualified
# file names.  Tell them everything we can about where
# to find things.
CC= c:/easyc/mcc18/bin/mcc18.exe
CCOPTS= -p=18F8520 -i"$(EASYDIR)mcc18/h" -i"$(VEXDIR)UserAPI" -i"../inc" -i"../../VexAPI/inc" -O-

LD= c:/easyc/mcc18/bin/MPLink.exe
LDOPTS= -l"$(EASYDIR)mcc18/lib" -l "$(VEXDIR)Library" -l "$(VEXDIR)Object" -k "$(VEXDIR)Linker" 

.PHONY: all clean Vex downloadit
all: Vex
Vex : Vex.hex

# The order of these objects was derived from easyC
# compiler output.  Not sure what will happen if you
# change them so don't do it :-)
EASYOBJS= \
	"ifi_startup.o" \
	"ifi_utilities.o" \
	"printf_lib.o" \
	"Start.o" \
	"user_routines.o" \
	"user_routines_fast.o" \
	"user_api.o"

# The interrupts object needs to be placed specially to 
# minimize jump distances and to generate hex files that
# are identical to those from the GUI
EASYOBJS2= \
	"interrupts.o"

EASYLIBS= \
	"Vex_library.lib"

# Outputs are sent to devnull because they're not generally
# useful even when there's an error.  There is no harm to 
# changing this if you want to see it.
%io.o : ../src/%io.c
	$(CC) $(CCOPTS) ../src/$*io.c -fo $*io.o >/dev/null

%.o : ../src/%.c
	$(CC) $(CCOPTS) ../src/$*.c -fo $*.o  >/dev/null

%.hex: %.o %io.o programs.o
	$(LD) $(LDOPTS) "18f8520user.lkr" $*.o programs.o $(EASYOBJS) $*io.o $(EASYOBJS2) $(EASYLIBS) -m$*.map -o$*.cof

downloadit: %.hex
	$(EASYDIR)/Loader/iLoader.exe -D=%.hex -H -T

# This is lame...
clean:
	-rm Vex.o
	-rm Vexio.o
	-rm Vex.hex Vex.lst Vex.map Vex.cod Vex.cof
