###############################################################################
#
# Copyright 2005 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.
#
# Revision 1.1  2006/02/6 02:52:01  orest 
# Initial check-in.
#
###############################################################################

include ../../../../devroot/include/make/SDKdefs

# ensures that 'make' does 'make all' instead of first target
default:  all

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

REVOLUTION_EXT_INSTALL_ROOT := $(REVOLUTION_P2P_ROOT)
P2P_INC_ROOT                 = "$(REVOLUTION_EXT_INSTALL_ROOT)\include"

REX_TITLEID = 34
REX_TITLEFW = noFW

TICKET             = $(REVOLUTION_EXT_ROOT)/X86/bin/rvl.no.34.bin
#BANNER             = vcmvtest.met
TITLE_ID           = 34343440
APP_TYPE           = RVL_APP
VERSION_NUM       ?= 0

WAD_OPTION  = -I "$(VERSION_NUM)" -gc "0x$(TITLE_ID)" -m "$(BANNER)" -t "$(TICKET)"

# 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: 	setup build 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
include $(GBA_SOURCE)/sw/bw/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	= p2p_echoping
MODULE_ROOT	= .
TEST	 	= TRUE
TEST_ROOT	= ..
SAMPLE	 	=

SRCDIR          = $(GBA_SOURCE)/sw/common/lib/p2p/test/echoping

# 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		= main.c echo.c ping.c #netconfig.c

# 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)

BINNAMES 	= echopingPing #echopingEcho 
INCLUDES       += -i- -Iinclude\
                  -I$(P2P_INC_ROOT)

ifdef EPPC
# 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
endif

# 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

CCFLAGS_WARNING = -W padding,nounused
#INCLUDES += -I$(INC_ROOT)/private

REX_DIR	               ?= $(subst $(space),\$(space),$(subst \,/,$(REVOLUTION_EXT_ROOT)))
REX_INCDIR             := $(REX_DIR)/include
REX_LIBNAMES            = ncd so nwc24
REX_LIBTYPE		= $(ARCH_TARGET)/lib
REX_LIBDIR		= $(REX_DIR)/$(REX_LIBTYPE)
REX_LIBFILES            = $(addsuffix $(LIBSUFFIX),$(REX_LIBNAMES)) 
REX_LIBS		= $(addprefix $(REX_LIBDIR)/,$(REX_LIBFILES))
GINCLUDES              += -I$(REX_INCDIR)
CCFLAGS                += -DUSE_REVOEX


# 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 Dolphin libraries.
REVOLUTION_LIBS += $(REVOLUTION_P2P_ROOT)/RVL/lib/p2p$(LIBSUFFIX) \
		   $(REVOLUTION_P2P_ROOT)/RVL/lib/p2p_services$(LIBSUFFIX) \
		   $(REVOLUTION_P2P_ROOT)/RVL/lib/p2p_servicesmodules$(LIBSUFFIX) \
		   $(REVOLUTION_P2P_ROOT)/RVL/lib/p2p_testframework$(LIBSUFFIX) 


$(FULLBIN_ROOT)/echopingEcho$(BINSUFFIX):	main.o echo.o \
	$(REVOLUTION_LIBS) $(REX_LIBS)

$(FULLBIN_ROOT)/echopingPing$(BINSUFFIX):	main.o ping.o \
	$(REVOLUTION_LIBS) $(REX_LIBS)

CP		= /usr/bin/cp
CPFLAGS		= -f

setup:	
	@if [ -z '$(REVOLUTION_P2P_ROOT)' ]; then\
	    echo "You must establish environment variable REVOLUTION_P2P_ROOT before proceeding."; \
	    exit 1; \
	fi
	@if [ ! -w '$(REVOLUTION_P2P_ROOT)' -o ! -d '$(REVOLUTION_P2P_ROOT)' ]; then\
	    mkdir -p '$(REVOLUTION_P2P_ROOT)'; \
	fi
# $(SETUP_ROOTS) does not create directory $(DEP_ROOT), without which build will fail
	@mkdir -p $(DEP_ROOT)

dummy:
	rsync -avz $(GBA_SOURCE_UNIX)/sw/common/lib/p2p/test/p2p_testcfg.h $(REVOLUTION_SDK_ROOT_UNIX)/build/tests/p2p_echoping/include
	rsync -avz $(GBA_SOURCE_UNIX)/sw/common/lib/p2p/test/echoping/porting.h $(REVOLUTION_SDK_ROOT_UNIX)/build/tests/p2p_echoping/include
	rsync -avz $(GBA_SOURCE_UNIX)/sw/common/lib/p2p/test/echoping/config.h $(REVOLUTION_SDK_ROOT_UNIX)/build/tests/p2p_echoping/include
	rsync -avz $(GBA_SOURCE_UNIX)/sw/common/lib/p2p//share/shr_trace.h $(REVOLUTION_SDK_ROOT_UNIX)/build/tests/p2p_echoping/include

### - END HACK TO copy files from GBA tree instead of moving it all over  ###


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