# ************************************************************************************************
# * FILE PURPOSE: Build the GEM testsmall code
# ************************************************************************************************
# * FILE NAME: makeGem
# *
# * DESCRIPTION: Builds the testsmall gem code
# *
# *	   invocation: make -f makeGem 
# *
# *	 Predefinition requirements: NGEMS, NARMS, MAXGEMS, MAXARMS, LNKFILE, ENDIAN
# *
# ************************************************************************************************


COPTS= -g -c -mv6400+ -I $(TOOLSC6X)/include -eo.oc
CDEFS= -DNGEMS=$(NGEMS) -DNARMS=$(NARMS) -DMAXGEMS=$(MAXGEMS) -DMAXARMS=$(MAXARMS)

# always swap the magic address if the GEM is big endian. The arm boot code always runs little endian
ifeq ($(ENDIAN),big)
 CDEFS+= -dSWAP_ARM_MAGIC
endif

ifeq ($(ENDIAN),big)
	COPTS+= -me
	LIB=     $(TOOLSC6X)/lib/rts64pluse.lib
else
	LIB=     $(TOOLSC6X)/lib/rts64plus.lib
endif

all: util testsmall_gem.btbl.ccs

testsmall_gem.btbl.ccs: testsmall_gem.out
	hex6x -a -boot -bootorg 0x400 -romwidth 32 -memwidth 32 $< -o btbl.b
	../util/btoccs/b2ccs btbl.b $@

testsmall_gem.out: testsmall.oc $(LNKFILE)
	cl6x -z $(LNKFILE) $(LIB) -o $@ -m testsmall_gem.map


util:
	make -C ../util/btoccs


%.oc: %.c cdefdep
	cl6x $(COPTS) $(INC) $(CDEFS) $<

%.oa: %.s cdefdep
	cl6x $(AOPTS) $(INC) $<

