#! make -f
#----------------------------------------------------------------------------
# Project:  TwlSDK
# File:     commondefs
#
#  Copyright 2007-2009 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.
#
# $Date:: 2009-06-04#$
# $Rev: 10698 $
# $Author: okubata_ryoma $
#----------------------------------------------------------------------------
ifndef TWLSDK_NITRO_COMMONDEFS_
TWLSDK_NITRO_COMMONDEFS_ = TRUE

#
# SDK Major Version
#

NITROSDK_VERSION_MAJOR	?= 5

#
# CodeGen Target
#
#	NITRO_PLATFORM  = [TS]
#	NITRO_MEMSIZE   = [4M/8M]
#	NITRO_PROC      = [ARM9/ARM7]
#

NITRO_PLATFORM			?= TS
NITRO_MEMSIZE			?= 4M
NITRO_PROC				?= ARM9

CODEGEN_PROC			 = $(strip $(NITRO_PROC))


#
# C Compiler type
#
#	NITRO_CCTYPE = [CW]
#

NITRO_CCTYPE		?= CW


#
# Binary build tool switch
#
NITRO_MAKEROM		?= TRUE

#
# RomSpeedType for makerom.exe
#
#	one of [MROM/1TROM/UNDEFINED]
#

NITRO_ROMSPEED		?= UNDEFINED

#
# SDK build type
#
#	one of [NITRO_DEBUG/NITRO_RELEASE/NITRO_FINALROM]
#

ifneq	($(TARGET_DEBUG),)
NITRO_BUILD_TYPE	?= DEBUG
NITRO_BUILD_DIR		?= Debug

else
ifneq	($(TARGET_FINALROM),)
NITRO_BUILD_TYPE	?= FINALROM
NITRO_BUILD_DIR		?= Rom

else	#NITRO_RELEASE(default)
NITRO_BUILD_TYPE	?= RELEASE
NITRO_BUILD_DIR		?= Release

endif
endif

#----------------------------------------------------------------------------
#  NITRO-SDK path settings
#

NITRO_INCDIR			:= $(ROOT)/include
NITRO_TOOLSDIR			:= $(TOOLSDIR)
NITRO_COMPONENTSDIR		:= $(COMPONENTSDIR)
NITRO_ADDINS			?= $(ADDINSDIR)

NITRO_BUILDARCH			?= $(CODEGEN_PROC)-$(NITRO_PLATFORM)$(CODEGEN_ARCH)
NITRO_BUILDARCH_ARM9	 = ARM9-$(NITRO_PLATFORM)$(CODEGEN_ARCH)
ifeq ($(DEMO_CHECK_BUILD),)
NITRO_BUILDARCH_ARM7	 = ARM7-$(NITRO_PLATFORM)$(ARCHGEN_TYPE)$(CODEGEN_ARCH)
else
NITRO_BUILDARCH_ARM7	 = ARM7-$(NITRO_PLATFORM)$(ARCHGEN_TYPE)$(CODEGEN_ARCH_ARM7)
endif

NITRO_BUILDTYPE			?= $(NITRO_BUILDARCH)/$(NITRO_BUILD_DIR)
NITRO_BUILDTYPE_ARM9	 = $(NITRO_BUILDARCH_ARM9)/$(NITRO_BUILD_DIR)
NITRO_BUILDTYPE_ARM7	 = $(NITRO_BUILDARCH_ARM7)/$(NITRO_BUILD_DIR)

NITRO_LIBARCH			 = $(CODEGEN_PROC)-$(NITRO_PLATFORM)
NITRO_LIBTYPE			 = $(NITRO_LIBARCH)/$(NITRO_BUILD_DIR)
NITRO_LIBDIR			 = $(ROOT)/lib/$(NITRO_LIBTYPE)
NITRO_LIBSYSCALLDIR		 = $(ROOT)/lib/$(NITRO_LIBARCH)/etc
NITRO_LIBSUFFIX			?= $(CODEGEN_ARCH)


#----------------------------------------------------------------------------
#  TWL-SYSTEM path settings
#

ifdef	TWLSYSTEM_ROOT
TWLSYSTEM_ROOT_		:= $(subst $(SPACE),\ ,$(subst \,/,$(TWLSYSTEM_ROOT)))
-include $(TWLSYSTEM_ROOT_)/build/buildtools/nnslibdefs
endif

#----------------------------------------------------------------------------
#  Compiler settings
#

ifneq	($(FORCE_BUILD),)

### module subdir src/ obj/ lib/ include/

LCF_SUFFIX_				= $(if $(NITRO_DIGEST),-C)
NITRO_SPECDIR			= $(NITRO_INCDIR)/nitro/specfiles

ifneq	($(filter NITRO,$(TARGET_PLATFORM_LIST)),)
DEFAULT_LCFILE			= $(NITRO_SPECDIR)/$(NITRO_LIBARCH).lcf
DEFAULT_LCFILE_TEMPLATE	= $(NITRO_SPECDIR)/$(NITRO_LIBARCH)$(LCF_SUFFIX_).lcf.template
DEFAULT_LCFILE_SPEC		= $(NITRO_SPECDIR)/$(NITRO_LIBARCH).lsf
DEFAULT_ROM_SPEC		= $(NITRO_SPECDIR)/ROM-$(NITRO_PLATFORM).rsf
endif

SRCDIR					?= $(DEFAULT_SRCDIR)
INCDIR					?= $(DEFAULT_INCDIR)
ETCDIR					?= $(DEFAULT_ETCDIR)
OBJDIR					?= ./obj/$(NITRO_BUILDTYPE)
BINDIR					?= ./bin/$(NITRO_BUILDTYPE)
LIBDIR					?= ./lib/$(NITRO_BUILDTYPE)

ifdef	MSYSTEM
DEPENDDIR				?= ./depend.MinGW/$(NITRO_BUILDTYPE)
else
DEPENDDIR				?= ./depend/$(NITRO_BUILDTYPE)
endif

LIBSYSCALL_				 = $(if $(LIBSYSCALL),$(LIBSYSCALL),$(NITRO_LIBSYSCALLDIR)/libsyscall.a)

### Compiler & Linker settings

-include $(NITRO_BUILDTOOLSDIR)/commondefs.cctype.$(NITRO_CCTYPE)

ifneq	($(NITRO_MAKEROM),)
LCFILE_TEMPLATE			?= $(DEFAULT_LCFILE_TEMPLATE)
LCFILE_SPEC				?= $(DEFAULT_LCFILE_SPEC)
LCFILE_AUTOGEN			?= $(BINDIR)/$(notdir $(LCFILE_SPEC:.lsf=.autogen.lcf))
LCFILE					?= $(LCFILE_AUTOGEN)
DEFAULT_LDRES_TEMPLATE	:= $(NITRO_SPECDIR)/$(basename $(word $(words $(subst /, ,$(LD))),$(subst /, ,$(LD)))).response.template
LDRES_TEMPLATE			?= $(DEFAULT_LDRES_TEMPLATE)
LDRES_AUTOGEN			?= $(BINDIR)/$(notdir $(LCFILE_SPEC:.lsf=.autogen.response))
LDRES_FILE				?= $(LDRES_AUTOGEN)
else
LCFILE					?= $(DEFAULT_LCFILE)
endif

TARGETS					?= $(addprefix $(BINDIR)/,$(TARGET_BIN) $(TARGET_ELF) $(TARGET_SIGN_BIN)) \
						   $(addprefix $(OBJDIR)/,$(TARGET_OBJ)) 		\
						   $(addprefix $(LIBDIR)/,$(TARGET_LIB))

TARGET_BIN_BASENAME		 = $(notdir $(basename $(firstword $(TARGET_BIN) $(TARGET_ELF))))
TARGET_NAME				?= $(TARGET_BIN_BASENAME)

### Debugger settings

-include $(NITRO_BUILDTOOLSDIR)/commondefs.emtype.IS


### SDK Library settings

CRT0_O			?=  crt0.o

ifeq	($(CODEGEN_PROC),ARM9)

NITRO_LIBS		?= 									\
				   libcard$(NITRO_LIBSUFFIX).a		\
				   libcp$(NITRO_LIBSUFFIX).a		\
				   libenv$(NITRO_LIBSUFFIX).a		\
				   libext$(NITRO_LIBSUFFIX).a		\
				   libfs$(NITRO_LIBSUFFIX).a		\
				   libfx$(NITRO_LIBSUFFIX).a		\
				   libgx$(NITRO_LIBSUFFIX).a		\
				   libmath$(NITRO_LIBSUFFIX).a		\
				   libmb$(NITRO_LIBSUFFIX).a		\
				   libmi$(NITRO_LIBSUFFIX).a		\
				   libnvram$(NITRO_LIBSUFFIX).a		\
				   libos$(NITRO_LIBSUFFIX).a		\
				   libprc$(NITRO_LIBSUFFIX).a		\
				   libpxi$(NITRO_LIBSUFFIX).a		\
				   librtc$(NITRO_LIBSUFFIX).a		\
				   libsnd$(NITRO_LIBSUFFIX).a		\
				   libspi$(NITRO_LIBSUFFIX).a		\
				   libstd$(NITRO_LIBSUFFIX).a		\
				   libwbt$(NITRO_LIBSUFFIX).a		\
				   libwfs$(NITRO_LIBSUFFIX).a		\
				   libwm$(NITRO_LIBSUFFIX).a		\
				   libcrypto$(NITRO_LIBSUFFIX).a	\
				   libctrdg$(NITRO_LIBSUFFIX).a		\
			       libcht$(NITRO_LIBSUFFIX).a		\
				   libssp$(NITRO_LIBSUFFIX).a		\
				   libwxc$(NITRO_LIBSUFFIX).a		\
				   $(notdir $(LIBSYSCALL_))			\
				   $(CRT0_O)

NITRO_LIBS		+= $(if $(NITRO_PROFILE_TYPE),libos.$(NITRO_PROFILE_TYPE)$(NITRO_LIBSUFFIX).a)

else #	($(CODEGEN_PROC),ARM7)

NITRO_LIBS		?= 									\
				   libcard_sp$(NITRO_LIBSUFFIX).a	\
				   libexi_sp$(NITRO_LIBSUFFIX).a	\
				   libfs_sp$(NITRO_LIBSUFFIX).a		\
				   libmi_sp$(NITRO_LIBSUFFIX).a		\
				   libmic_sp$(NITRO_LIBSUFFIX).a	\
				   libnvram_sp$(NITRO_LIBSUFFIX).a	\
				   libos_sp$(NITRO_LIBSUFFIX).a		\
				   libpad_sp$(NITRO_LIBSUFFIX).a	\
				   libpm_sp$(NITRO_LIBSUFFIX).a		\
				   libpxi_sp$(NITRO_LIBSUFFIX).a	\
				   librtc_sp$(NITRO_LIBSUFFIX).a	\
				   libsnd_sp$(NITRO_LIBSUFFIX).a	\
				   libspi_sp$(NITRO_LIBSUFFIX).a	\
				   libstd_sp$(NITRO_LIBSUFFIX).a	\
				   libtp_sp$(NITRO_LIBSUFFIX).a		\
				   libwvr_sp$(NITRO_LIBSUFFIX).a	\
				   libctrdg_sp$(NITRO_LIBSUFFIX).a	\
				   libsubpsyscall.a					\
				   $(CRT0_O)


NITRO_LIBS		+= $(if $(NITRO_PROFILE_TYPE),libos_sp.$(NITRO_PROFILE_TYPE)$(NITRO_LIBSUFFIX).a)

endif

### Global Library settings

SYSTEM_GINCLUDES		 = $(NITROWIRELESS_INCDIR)							\
						   $(NITRO_INCDIR) $(ISDBG_INCDIRS)

DEFAULT_GINCLUDES		 = $(INCDIR) $(SRCDIR)								\
						   $(NITROSYSTEM_INCDIR) $(SYSTEM_GINCLUDES)

DEFAULT_GLIBRARY_DIRS	 = $(LIBDIR) $(dir $(LIBSYSCALL_))					\
						   $(NITROSYSTEM_LIBDIR) $(NITROWIRELESS_LIBDIR)	\
						   $(NITRO_LIBDIR) $(ISDBG_LIBDIRS)

DEFAULT_GLIBRARIES		 = $(NITROSYSTEM_LIBS) $(NITRO_LIBS) $(STUBS_LIBS) $(ISDBG_LIBS)

GINCLUDES				?= $(DEFAULT_GINCLUDES)
GLIBRARY_DIRS			?= $(DEFAULT_GLIBRARY_DIRS)
GLIBRARIES				?= $(DEFAULT_GLIBRARIES)

LINCLUDES				?=
LLIBRARY_DIRS			?=
LLIBRARIES				?=
LNEWDIRS				?=

NEWDIRS					?= $(strip $(if $(SRCS),$(OBJDIR) $(DEPENDDIR))			\
						   $(if $(TARGET_LIB),$(LIBDIR))				\
						   $(if $(TARGET_BIN)$(TARGET_ELF),$(BINDIR))	\
						   $(LNEWDIRS))

GDIRT_CLEAN_DIRS		:= ./obj ./bin ./lib ./depend
GDIRT_CLOBBER_DIRS		:=

endif

#----------------------------------------------------------------------------
#  MY BUILD TOOLS
#

MAKELCF			:= $(NITRO_TOOLSDIR)/bin/makelcf.exe
MAKEBANNER		:= $(NITRO_TOOLSDIR)/bin/makebanner.exe
ADDBANNER		:= $(NITRO_TOOLSDIR)/bin/addbanner.exe
NTEXCONV		:= $(NITRO_TOOLSDIR)/bin/ntexconv.exe
COMPSTATIC		:= $(NITRO_TOOLSDIR)/bin/compstatic.exe
MAKEROM			:= $(NITRO_TOOLSDIR)/bin/makerom.exe
EMUCHILD		:= $(NITRO_TOOLSDIR)/bin/emuchild.exe
ATTACHSIGN		:= $(NITRO_TOOLSDIR)/bin/attachsign.exe
BIN2OBJ			:= $(NITRO_TOOLSDIR)/bin/bin2obj.exe
MAKELST			:= $(NITRO_TOOLSDIR)/bin/makelst.exe
STRIPDEBUG		:= $(NITRO_TOOLSDIR)/bin/stripdebug.exe
LOADRUN			:= $(NITRO_TOOLSDIR)/bin/loadrun.exe

MAKELCF_FLAGS	 			?=
MAKEBANNER_FLAGS			?=
MAKEROM_FLAGS	 			?=
COMPSTATIC_FLAGS			?=
LOADRUN_FLAGS				?=
DEFAULT_COMP_ARM7			?= mongoose
DEFAULT_ADDRESS_STATIC		?= 0x02000000
DEFAULT_ADDRESS_ITCM		?= 0x01FF8000
DEFAULT_ADDRESS_DTCM		?= 0x027e0000
DEFAULT_COMPSUFFIX			?= _LZ
DEFAULT_MAKEROM_ARM9		 = $(NITRO_COMPONENTSDIR)/printserver/$(NITRO_BUILDTYPE_ARM9)/main.$(NITRO_ELF_EXT)
DEFAULT_MAKEROM_ARM7		 = $(NITRO_COMPONENTSDIR)/$(DEFAULT_COMP_ARM7)/$(NITRO_BUILDTYPE_ARM7)/$(DEFAULT_COMP_ARM7)_sub.$(NITRO_ELF_EXT)

DEFAULT_MAKEROM_ROMROOT		:= ./files
DEFAULT_MAKEROM_ROMFILES	:=
DEFAULT_MAKEROM_ROMSPEED	?= $(NITRO_ROMSPEED)


#----------------------------------------------------------------------------
#  LIST OF JUNKS for "make 
#

GDIRT_CLEAN	= a.out core *~ *.bak \\\#*\\\# $(GDIRT_CLEAN_DIRS)

GDIRT_CLOBBER	= $(GDIRT_CLOBBER_DIRS)

GDIRT_INSTALLED	= $(addprefix $(INSTALL_DIR)/,$(notdir $(INSTALL_TARGETS)))


#----------------------------------------------------------------------------
#  Load add-ins' commondefs
#
#-include $(NITRO_BUILDTOOLSDIR)/commondefs.add-ins.*


#----------------------------------------------------------------------------
#  DEFAULT TARGET
#
ifdef NITRO_UTEST
default all:	utest
else
default all:	build
endif

#----------------------------------------------------------------------------
endif	# TWLSDK_NITRO_COMMONDEFS_
#----- End of commondefs -----
