# *************************************************************************************
# * FILE PURPOSE: Build the ARM testsmall code
# *************************************************************************************
# * FILE NAME: makeArm
# *
# * DESCRIPTION: Builds the testsmall arm code
# *
# *	     invocation: make -f makeArm
# *
# *  Predifinition requirements: NGEMS, NARMS, MAXGEMS, MAXARMS, LNKFILE, RMDFILE, ENDIAN
# * 							 ARM_ENDIAN
# *
# *************************************************************************************

RTL=$(TOOLSARMDOS)\lib\libc.a

OPTS= -c -g -mv7a8 --optlevel=0 -as -ss --code_state=32 --abi=ti_arm9_abi --diag_warning=225
CDEFS= -DNGEMS=$(NGEMS) -DNARMS=$(NARMS) -DMAXGEMS=$(MAXGEMS) -DMAXARMS=$(MAXARMS)

ifeq ($(ARM_ENDIAN),little)
 OPTS+= --endian=little
else
 OPTS+= --endian=big
endif




# For differing endian builds the arm data must be byte swapped since the GEM will be mastering 
# the writes to memory
ifneq ($(ENDIAN),$(ARM_ENDIAN))
 BOPT= -swap
endif

all: gen_cdefdep util testsmall_arm.btbl.ccs

testsmall_arm.btbl.ccs: testsmall_arm.out
#	$(ARM_COMPILER_FOLDER)/bin/armhex $(RMDFILE) $<
	$(ARM_COMPILER_FOLDER)/bin/hex470 $(RMDFILE) $<
	../util/btoccs/bblobToBtblCcs $(BOPT) testsmall_arm.b $@



testsmall_arm.out: testsmall.arm.oc testsmall.arm.oa
	$(ARM_COMPILER_FOLDER)/bin/cl470 -z $(LNKFILE) $(RTL) -m testsmall_arm.map -o $@

%.arm.oc: %.c cdefdep2
	$(ARM_COMPILER_FOLDER)/bin/cl470 $(OPTS) $(INC) $(CDEFS) -eo.arm.oc $<

%.arm.oa: %.s cdefdep2
	$(ARM_COMPILER_FOLDER)/bin/cl470 $(OPTS) $(INC) $(CDEFS) -eo.arm.oa $<


util:
	make -C ../util/btoccs
	make -C ../util/ccsutil

gen_cdefdep:
	@echo $(LNKFILE) $(ENDIAN) $(ARM_ENDIAN) > cdefdep.tmp
	@sh -c 'if diff -q cdefdep.tmp cdefdep2 ; then echo same ; else cp cdefdep.tmp cdefdep2 ; fi '
	


