###############################################################################
# Makefile for ectest_nofilter
#
# Copyright 2006 Nintendo.  All rights reserved.
#
# These coded instructions, statements, and computer programs contain
# proprietary information of Nintendo of America Inc. and/or Nintendo
# Company Ltd., and are protected by Federal copyright law.  They may
# not be disclosed to third parties or copied or duplicated in any form,
# in whole or in part, without the prior written consent of Nintendo.
#
#
# $NoKeywords: $
#
###############################################################################

GBA_SOURCE  = ../../../../../../

SDK_NAME = ec_prerelease5
include $(GBA_SOURCE)/sw/devroot/include/make/SDKdefs

# All modules have "setup" and "build" as targets.  System libraries 
# and demo programs also have an "install" target that copies the compiled
# binaries to the binary tree (/$(ARCH_TARGET)).

all:    install

# commondefs must be included near the top so that all common variables
# will be defined before their use.

include $(REVOLUTION_EXT_ROOT)/build/buildtools/commondefs

# module name should be set to the name of this subdirectory
# DEMO = TRUE indicates that this module resides under the "demos" subtree.
# The list of selectable paths can be found in modulerules.

MODULENAME  = ectest_nofilter
MODULE_ROOT = .
TEST        = TRUE
TEST_ROOT   = ..


# CSRCS lists all C files that should be built
# The makefile determines which objects are linked into which binaries
# based on the dependencies you fill in at the bottom of this file

CSRCS         =   ectest_init.c  ectest_netconfig.c
CPPSRCS       =   ectest_main.cpp  ectest.cpp 


# BINNAMES lists all binaries that will be linked.  Note that no suffix is
# required, as that will depend on whether this is a DEBUG build or not.
# The final name of the binaries will be $(BINNAME)$(BINSUFFIX)

EC_TEST_BIN = ectest_nofilter
BINNAMES    = $(EC_TEST_BIN)
TARGET_ELF  = $(FULLBIN_ROOT)/$(EC_TEST_BIN)$(BINSUFFIX)

# additional libraries not defined as REVOLUTION_LIBS

REX_LIBNAMES += nhttp ssl so ec

CCFLAGS     += -dialect c99
CCFLAGS     += -msgstyle gcc

CCFLAGS_WARNING =

INCLUDES   := -i- -ir $(MWDIR)/PowerPC_EABI_Support/MSL/MSL_C++ $(INCLUDES)
INCLUDES   += -Iinclude
INCLUDES   += -I$(INC_ROOT)/private -I$(INC_ROOT)/secure


ifndef SDATA
    CCFLAGS  += -sdata 0 -sdata2 0
    LDFLAGS  += -sdata 0 -sdata2 0
endif
    
# defining a linker command file will have the build system generate it
# automatically and include it on the linker invocation line

LCF_FILE    = $(INC_ROOT)/revolution/eppc.$(ARCH_TARGET).lcf

# modulerules contains the rules that will use the above variables 
# and dependencies below to construct the binaries specified.

include $(REVOLUTION_EXT_ROOT)/build/buildtools/modulerules

# Dependencies for the binaries listed in BINNAMES should come here
# They are your typical makefile rule, with extra variables to ensure
# that the names and paths match up.
# $(FULLBIN_ROOT) is the location of the local bin directory
# $(BINSUFFIX) depends on whether this is a debug build or not
# $(REVOLUTION_LIBS) includes all the Revolution libraries.


REVOLUTION_LIBS += $(INSTALL_ROOT)/lib/cnt$(LIBSUFFIX) \
                   $(INSTALL_ROOT)/lib/scutil$(LIBSUFFIX) 

$(FULLBIN_ROOT)/$(EC_TEST_BIN)$(BINSUFFIX):   ectest_init.o ectest_main.o ectest.o ectest_netconfig.o\
    $(REVOLUTION_LIBS) $(REX_LIBS)
    

wad:
	make NANDAPP=TRUE NOEXPORT=TRUE
	makedol -f $(FULLBIN_ROOT)/$(EC_TEST_BIN)$(BINSUFFIX) -d $(FULLBIN_ROOT)/$(EC_TEST_BIN)$(DOLSUFFIX)
	makeWad -n ectest1$(ASUFFIX) -l $(FULLBIN_ROOT)/$(EC_TEST_BIN)$(DOLSUFFIX)
	mv $(EC_TEST_BIN)$(WADSUFFIX) $(FULLBIN_ROOT)/


datatitle1:
	@echo "------------------------------------------"
	@echo "Make datatitle 1 wad file"
	cd dt1; \
	mkdir -p tmp; \
	mkdir -p archives; \
	cd tmp; \
	for CFN in 1 2 3 4 5 6; do \
	rm -f content; \
	cp -f ../contents/c$$CFN.txt content; \
	darchD -c content ../archives/c$$CFN.arc; \
	rm -f content; \
	done; \
	cd  ../archives; \
	makeWad -I 2 -f -n ecdt1 -l c1.arc,c2.arc,c3.arc,c4.arc,c5.arc,c6.arc -gc e100; \
	mv ecdt1.wad ..

datatitle2:
	@echo "------------------------------------------"
	@echo "Make datatitle 2 wad file"
	cd dt2; \
	mkdir -p tmp; \
	mkdir -p archives; \
	cd tmp; \
	for CFN in 1 2 3 4 5 6; do \
	rm -f content; \
	cp -f ../contents/c$$CFN.txt content; \
	darchD -c content ../archives/c$$CFN.arc; \
	rm -f content; \
	done; \
	cd  ../archives; \
	makeWad -I 3 -f -n ecdt2 -l c1.arc,c2.arc,c3.arc,c4.arc,c5.arc,c6.arc -gc e200; \
	mv ecdt2.wad ..

setup:
	@mkdir -p $(DEP_ROOT)

headers:

SERIAL_APP    = ndevSerial.exe
SERIAL_SRC_PATH   = $(GBA_SOURCE)/sw/tools/ndev/ndevSerialReader
SERIAL_PATH   = $(REVOLUTION_SDK_ROOT)/X86/bin

SERIAL_READER = $(SERIAL_PATH)/$(SERIAL_APP)

RMOWN_ELF     = $(REVOLUTION_EXT_ROOT)/RVL/bin/tools/rmown.elf
ECTEST_TITLES = \
		0001000565313030 \
		0001000565323030 \
		0001000165313030

RM_LOG        = rmown.log
ECTEST_LOG    = ectest.log

runtests: $(SERIAL_APP)
	@if [ ! -x "$(SERIAL_READER)" ]; then\
	    echo "Reader $(SERIAL_APP) unavailable at $(SERIAL_READER); cannot proceed";\
	    exit 1;\
	fi;
	@if [ ! -e "$(RMOWN_ELF)" ]; then\
	    echo "$(RMOWN_ELF) unavailable; cannot proceed";\
	    exit 1;\
	fi;
	@rm -f $(RM_LOG) $(ECTEST_LOG)	
	@ndrun $(RMOWN_ELF) -a -r $(ECTEST_TITLES)
	@$(SERIAL_READER) com1 $(RM_LOG) "rmown: Done" "no failure" && \
	    ndrun $(TARGET_ELF) && \
	    $(SERIAL_READER) com1 $(ECTEST_LOG) " 0 failed" "EC DEMO: END"; \
	    echo ""
	@echo "" && tail -n 2 $(ECTEST_LOG) && echo "";
	@ndstop

.PHONY: $(SERIAL_APP)
$(SERIAL_APP):
	@$(MAKE) -C $(SERIAL_SRC_PATH) -f Make.common install_tools

#======== End of makefile ========#
