include $(ROOT)/usr/include/make/NGdefs
include $(ROOT)/usr/include/make/commonrules

INSTALLDIR=$(ROOT)/usr/bin/rvl/ios_images
BIN_ROOT=$(ROOT)/usr/bin/rvl
TOOLS_DIR=$(ROOT)/usr/bin/x86

SHARED=-s $(MK_SHARED_START)
SIZE=-z $(MK_SHARED_SIZE)
#
# Non-crypto versions of files below:
#


IOS=-k $(BIN_ROOT)/ios_noshell.elf
DI=-d $(BIN_ROOT)/di_boot_nocrypto.elf
FS=-f $(BIN_ROOT)/fs_nocrypto.elf
PPCBOOT=-b $(BIN_ROOT)/ppcboot.elf
OH0= -u $(BIN_ROOT)/ohci0.elf
OH1= -v $(BIN_ROOT)/ohci1.elf
SDI= -c $(BIN_ROOT)/sdi.elf
STR= -i $(BIN_ROOT)/stress/stress_ddr3.elf

FILES = $(IOS) $(SHARED) $(SIZE) $(FS) $(PPCBOOT) $(OH0) $(OH1) $(SDI) $(DI)

ifeq ($(STRESS), 1)
FILES = $(IOS) $(SHARED) $(SIZE) $(FS) $(PPCBOOT) $(SDI) $(STR)
endif

#
# Crypto versions of files below
#


IOS_C=-k $(BIN_ROOT)/ios_real.elf
DI_C=-d $(BIN_ROOT)/di_boot.elf
FS_C=-f $(BIN_ROOT)/fs.elf
ES_C=-e $(BIN_ROOT)/es.elf
PPCBOOT_C=-b $(BIN_ROOT)/ppcboot.elf
OH0_C= -u $(BIN_ROOT)/ohci0.elf
OH1_C= -v $(BIN_ROOT)/ohci1.elf
SDI_C= -c $(BIN_ROOT)/sdi.elf
STR_C= -i $(BIN_ROOT)/stress/str_crypto.elf

FILES_C = $(IOS_C) $(SHARED) $(SIZE) $(FS_C) $(ES_C) \
	  $(PPCBOOT_C) $(OH0_C) $(OH1_C) $(SDI_C) 

ifeq ($(STRESS), 1)
FILES_C = $(IOS_C) $(SHARED) $(SIZE) $(FS_C) $(ES_C) $(PPCBOOT) \
	$(SDI_C) $(STR_C)
endif

FLASHES = \
	block0.flash \
	block1.flash \
	block2.flash \
	block3.flash \
	block4.flash

TARGETS = *.flash RVL* 

DIRT += bin *.bin ios* 


headers all default exports:

flash: 
	mkdir -p bin/nintendo
	mkdir -p bin/broadon
	cp -lrf $(ROOT)/usr/bin/nintendo bin
ifeq ($(origin  NOCRYPTO), undefined)
	@echo ""
	@echo "---- BUILDING CRYPTO VERSION ----"
	$(TOOLS_DIR)/arm-elf-merge $(FILES_C) -o ios.merged
else
	@echo ""
	@echo "---- BUILDING NOCRYPTO VERSION ----"
	$(TOOLS_DIR)/arm-elf-merge $(FILES) -o ios.merged
endif
	cp ios.merged bin/broadon/ios.merged
	$(TOOLS_DIR)/createIOSFlashImg.sh

install: flash
	. boot1.sh
	mkdir -p $(INSTALLDIR)
	$(INSTALL) -m 755 $(FLASHES) $(INSTALLDIR)
	make clean
	@echo ""
	@echo ""
	@echo "Flash files installed into $(INSTALLDIR)"
	@echo ""

files:
	cd ../../; make clobber; make headers
	cd ../../tools/conv; make install 
	cd ../../tools/elf-merge; make install
	cd ../../server; make exports
	cd ../../nintendo/boot; make install
	cd ../../rvl; make exports; make install

64:
	. ../rvl_64.sh; make files install

128:
	. ../rvl_128.sh; make files install

both:
	make 64; mkdir RVL_64; cp *.flash RVL_64; make clean;
	make 128; mkdir RVL_128; cp *.flash RVL_128; make clean;
