###############################################################################
# Makefile for rmown
#
# 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: $
#
###############################################################################

default: all

GBA_SOURCE=../../../../..
SDK_NAME=ecshop_3.3.1
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:    setup build myinstall install

headers:
# do nothing

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

# ends up being BUILD_ROOT, the core of MODULE_ROOT
REX_BUILDDIR = ../../../

MODULENAME  = rmown
REX_TOOL    = TRUE

# 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         =   rmown_init.c  rmown_netconfig.c
CPPSRCS       =   rmown_main.cpp  rmown.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)

BINNAMES    = rmown
#TARGET_ELF  = $(FULLBIN_ROOT)/rmown$(BINSUFFIX)

# additional libraries not defined as REVOLUTION_LIBS

REX_LIBNAMES += nhttp ssl so

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

CCFLAGS_WARNING =

ifdef RVL_IPL_ROOT
    IPL_ROOT = $(subst $(space),\$(space),$(subst \,/,$(RVL_IPL_ROOT)))
endif


RMOWN_DIR := $(shell cygpath -m $(shell pwd))
EXTRA_RVL_SDK = $(RMOWN_DIR)/RVL_SDK

INCLUDES   := -i- -ir $(MWDIR)/PowerPC_EABI_Support/MSL/MSL_C++ $(INCLUDES)
INCLUDES   += -Iinclude #-I$(REX_DIR)/build/libraries/ecshop/include
INCLUDES   += -I$(REX_BUILDDIR)/libraries/ecshop/include
INCLUDES   += -I$(GBA_SOURCE)/sw/common/lib/ec/include
INCLUDES   += -I$(EXTRA_RVL_SDK)/include
INCLUDES   += -I$(EXTRA_RVL_SDK)/include/private -I$(EXTRA_RVL_SDK)/include/secure
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) \
                   $(EXTRA_RVL_SDK)/RVL/lib/es$(LIBSUFFIX) \
                   $(REX_DIR)/RVL/lib/ecshop$(LIBSUFFIX)
                   

$(FULLBIN_ROOT)/rmown$(BINSUFFIX):   $(ALLOBJECTS)\
    $(REVOLUTION_LIBS) $(REX_LIBS) 

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

setup:
	@$(INSTALL) RmownReadme.txt $(REVOLUTION_EXT_ROOT)/docs
	@mkdir -p $(DEP_ROOT)

myinstall: SDK_NAME=ecdk_current
myinstall:
	@$(INSTALL) $(FULLBIN_ROOT)/rmown$(BINSUFFIX) $(REVOLUTION_EXT_ROOT)/RVL/bin/tools

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