#
# target definitions
#

MULTILIB_TARGET = 

ifdef SEMIHOSTING
HOSTED=-D_EWL_OS_DISK_FILE_SUPPORT=1
endif

THUMB_V7M = Thumb_v7M
THUMB_F_V7M = Thumb_F_v7M
THUMB_SPF_V7M = Thumb_SPF_v7M
THUMB_V6M = Thumb_v6M
THUMB_SOFTFP_V7M = Thumb_SOFTFP_v7M
THUMB_V7A = Thumb_v7A
THUMB_F_V7A = Thumb_F_v7A
THUMB_SOFTFP_V7A = Thumb_SOFTFP_v7A

CORTEX_M7 = Cortex_M7
CORTEX_SOFT_SP_M7 = Cortex_SOFT_SP_M7
CORTEX_SOFT_M7 = Cortex_SOFT_M7
CORTEX_F_SP_M7 = Cortex_F_SP_M7
CORTEX_F_M7 = Cortex_F_M7

BASIC_ALIGN_4_CFLAGS	= -funsigned-char -mabi=aapcs -mthumb  $(HOSTED)

THUMB_V7M_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m4 -mfloat-abi=soft
THUMB_F_V7M_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
THUMB_SOFTFP_V7M_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16
THUMB_SPF_V7M_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fshort-double -D_EWL_USES_SUN_DP_MATH_LIB=0
THUMB_V6M_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m0 -msoft-float 
THUMB_V7A_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-a5 -mfloat-abi=soft
THUMB_F_V7A_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-a5 -mfloat-abi=hard -mfpu=vfpv3-d16
THUMB_SOFTFP_V7A_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-a5 -mfloat-abi=softfp -mfpu=vfpv3-d16

CORTEX_M7_CFLAGS			= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m7 -mfloat-abi=soft
CORTEX_SOFT_SP_M7_CFLAGS	= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv5-sp-d16
CORTEX_SOFT_M7_CFLAGS		= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m7 -mfloat-abi=softfp -mfpu=fpv5-d16
CORTEX_F_SP_M7_CFLAGS		= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16
CORTEX_F_M7_CFLAGS			= $(BASIC_ALIGN_4_CFLAGS) -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16

TOOLS_ROOT = $(ARM_TOOLS)
TOOLS = $(TOOLS_ROOT)/bin
CC = "$(TOOLS)/arm-none-eabi-gcc"
AR = "$(TOOLS)/arm-none-eabi-ar"

#
#
# End tools definition


OPTS=-Os -gdwarf-2 -gstrict-dwarf -ffunction-sections -fdata-sections
#OPTS=-Os -fkeep-inline-functions -ftracer -ffunction-sections -fdata-sections
#OPTS=-O0 -gdwarf-2 -gstrict-dwarf

PLATFORM_FLAGS	= $(OPTS)
DEBUG_PREFIX	= S32DS/arm_ewl2

# Target name definition and target specific build flags
#
TSTDCPP_$(THUMB_V7M) = $(MULTILIB_TARGET)/armv7e-m/libstdc++
TSTDCPP_$(THUMB_V7M)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_V7M_CFLAGS)
TSTDCPP_$(THUMB_V7M)LFLAGS =
$(TSTDCPP_$(THUMB_V7M))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(THUMB_F_V7M) = $(MULTILIB_TARGET)/armv7e-m/fpu/libstdc++
TSTDCPP_$(THUMB_F_V7M)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_F_V7M_CFLAGS)
TSTDCPP_$(THUMB_F_V7M)LFLAGS =
$(TSTDCPP_$(THUMB_F_V7M))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(THUMB_SOFTFP_V7M) = $(MULTILIB_TARGET)/armv7e-m/softfp/libstdc++
TSTDCPP_$(THUMB_SOFTFP_V7M)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_SOFTFP_V7M_CFLAGS)
TSTDCPP_$(THUMB_SOFTFP_V7M)LFLAGS =
$(TSTDCPP_$(THUMB_SOFTFP_V7M))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(THUMB_SPF_V7M) = $(MULTILIB_TARGET)/armv7e-m/spfp/libstdc++
TSTDCPP_$(THUMB_SPF_V7M)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_SPF_V7M_CFLAGS)
TSTDCPP_$(THUMB_SPF_V7M)LFLAGS =
$(TSTDCPP_$(THUMB_SPF_V7M))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(THUMB_V6M) = $(MULTILIB_TARGET)/armv6-m/libstdc++
TSTDCPP_$(THUMB_V6M)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_V6M_CFLAGS)
TSTDCPP_$(THUMB_V6M)LFLAGS =
$(TSTDCPP_$(THUMB_V6M))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(THUMB_V7A) = $(MULTILIB_TARGET)/armv7-ar/thumb/libstdc++
TSTDCPP_$(THUMB_V7A)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_V7A_CFLAGS)
TSTDCPP_$(THUMB_V7A)LFLAGS =
$(TSTDCPP_$(THUMB_V7A))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(THUMB_F_V7A) = $(MULTILIB_TARGET)/armv7-ar/thumb/fpu/libstdc++
TSTDCPP_$(THUMB_F_V7A)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_F_V7A_CFLAGS)
TSTDCPP_$(THUMB_F_V7A)LFLAGS =
$(TSTDCPP_$(THUMB_F_V7A))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(THUMB_SOFTFP_V7A) = $(MULTILIB_TARGET)/armv7-ar/thumb/softfp/libstdc++
TSTDCPP_$(THUMB_SOFTFP_V7A)CFLAGS = -std=c++0x -include lib_c++.prefix $(THUMB_SOFTFP_V7A_CFLAGS)
TSTDCPP_$(THUMB_SOFTFP_V7A)LFLAGS =
$(TSTDCPP_$(THUMB_SOFTFP_V7A))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(CORTEX_M7) = $(MULTILIB_TARGET)/cortex-m7/libstdc++
TSTDCPP_$(CORTEX_M7)CFLAGS = -std=c++0x -include lib_c++.prefix $(CORTEX_M7_CFLAGS)
TSTDCPP_$(CORTEX_M7)LFLAGS =
$(TSTDCPP_$(CORTEX_M7))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(CORTEX_SOFT_SP_M7) = $(MULTILIB_TARGET)/cortex-m7/softfp/fpv5-sp-d16/libstdc++
TSTDCPP_$(CORTEX_SOFT_SP_M7)CFLAGS = -std=c++0x -include lib_c++.prefix $(CORTEX_SOFT_SP_M7_CFLAGS)
TSTDCPP_$(CORTEX_SOFT_SP_M7)LFLAGS =
$(TSTDCPP_$(CORTEX_SOFT_SP_M7))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(CORTEX_SOFT_M7) = $(MULTILIB_TARGET)/cortex-m7/softfp/fpv5-d16/libstdc++
TSTDCPP_$(CORTEX_SOFT_M7)CFLAGS = -std=c++0x -include lib_c++.prefix $(CORTEX_SOFT_M7_CFLAGS)
TSTDCPP_$(CORTEX_SOFT_M7)LFLAGS =
$(TSTDCPP_$(CORTEX_SOFT_M7))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(CORTEX_F_SP_M7) = $(MULTILIB_TARGET)/cortex-m7/fpu/fpv5-sp-d16/libstdc++
TSTDCPP_$(CORTEX_F_SP_M7)CFLAGS = -std=c++0x -include lib_c++.prefix $(CORTEX_F_SP_M7_CFLAGS)
TSTDCPP_$(CORTEX_F_SP_M7)LFLAGS =
$(TSTDCPP_$(CORTEX_F_SP_M7))OBJECTS = $(CPPOBJECTS)

TSTDCPP_$(CORTEX_F_M7) = $(MULTILIB_TARGET)/cortex-m7/fpu/fpv5-d16/libstdc++
TSTDCPP_$(CORTEX_F_M7)CFLAGS = -std=c++0x -include lib_c++.prefix $(CORTEX_F_M7_CFLAGS)
TSTDCPP_$(CORTEX_F_M7)LFLAGS =
$(TSTDCPP_$(CORTEX_F_M7))OBJECTS = $(CPPOBJECTS)

PLATFORM_TARGETS_STDCPP = $(TSTDCPP_$(THUMB_V7M)) $(TSTDCPP_$(THUMB_F_V7M)) $(TSTDCPP_$(THUMB_SPF_V7M)) \
			  $(TSTDCPP_$(THUMB_V6M)) $(TSTDCPP_$(THUMB_SOFTFP_V7M)) $(TSTDCPP_$(THUMB_V7A)) \
			  $(TSTDCPP_$(THUMB_F_V7A)) $(TSTDCPP_$(THUMB_SOFTFP_V7A))
PLATFORM_TARGETS_STDCPP += $(TSTDCPP_$(CORTEX_M7)) $(TSTDCPP_$(CORTEX_SOFT_SP_M7)) $(TSTDCPP_$(CORTEX_SOFT_M7)) $(TSTDCPP_$(CORTEX_F_SP_M7)) $(TSTDCPP_$(CORTEX_F_M7))

TCPP_$(THUMB_V7M) = $(MULTILIB_TARGET)/armv7e-m/libc++
TCPP_$(THUMB_V7M)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_V7M_CFLAGS)
TCPP_$(THUMB_V7M)LFLAGS =
$(TCPP_$(THUMB_V7M))OBJECTS = $(CPPOBJECTS)

TCPP_$(THUMB_F_V7M) = $(MULTILIB_TARGET)/armv7e-m/fpu/libc++
TCPP_$(THUMB_F_V7M)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_F_V7M_CFLAGS)
TCPP_$(THUMB_F_V7M)LFLAGS =
$(TCPP_$(THUMB_F_V7M))OBJECTS = $(CPPOBJECTS)

TCPP_$(THUMB_SOFTFP_V7M) = $(MULTILIB_TARGET)/armv7e-m/softfp/libc++
TCPP_$(THUMB_SOFTFP_V7M)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_SOFTFP_V7M_CFLAGS)
TCPP_$(THUMB_SOFTFP_V7M)LFLAGS =
$(TCPP_$(THUMB_SOFTFP_V7M))OBJECTS = $(CPPOBJECTS)

TCPP_$(THUMB_V7A) = $(MULTILIB_TARGET)/armv7-ar/thumb/libc++
TCPP_$(THUMB_V7A)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_V7A_CFLAGS)
TCPP_$(THUMB_V7A)LFLAGS =
$(TCPP_$(THUMB_V7A))OBJECTS = $(CPPOBJECTS)

TCPP_$(THUMB_F_V7A) = $(MULTILIB_TARGET)/armv7-ar/thumb/fpu/libc++
TCPP_$(THUMB_F_V7A)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_F_V7A_CFLAGS)
TCPP_$(THUMB_F_V7A)LFLAGS =
$(TCPP_$(THUMB_F_V7A))OBJECTS = $(CPPOBJECTS)

TCPP_$(THUMB_SOFTFP_V7A) = $(MULTILIB_TARGET)/armv7-ar/thumb/softfp/libc++
TCPP_$(THUMB_SOFTFP_V7A)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_SOFTFP_V7A_CFLAGS)
TCPP_$(THUMB_SOFTFP_V7A)LFLAGS =
$(TCPP_$(THUMB_SOFTFP_V7A))OBJECTS = $(CPPOBJECTS)

TCPP_$(THUMB_SPF_V7M) = $(MULTILIB_TARGET)/armv7e-m/spfp/libc++
TCPP_$(THUMB_SPF_V7M)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_SPF_V7M_CFLAGS)
TCPP_$(THUMB_SPF_V7M)LFLAGS =
$(TCPP_$(THUMB_SPF_V7M))OBJECTS = $(CPPOBJECTS)

TCPP_$(THUMB_V6M) = $(MULTILIB_TARGET)/armv6-m/libc++
TCPP_$(THUMB_V6M)CFLAGS = -include lib_ewl_c++.prefix $(THUMB_V6M_CFLAGS)
TCPP_$(THUMB_V6M)LFLAGS =
$(TCPP_$(THUMB_V6M))OBJECTS = $(CPPOBJECTS)

TCPP_$(CORTEX_M7) = $(MULTILIB_TARGET)/cortex-m7/libc++
TCPP_$(CORTEX_M7)CFLAGS = -include lib_ewl_c++.prefix $(CORTEX_M7_CFLAGS)
TCPP_$(CORTEX_M7)LFLAGS =
$(TCPP_$(CORTEX_M7))OBJECTS = $(CPPOBJECTS)

TCPP_$(CORTEX_SOFT_SP_M7) = $(MULTILIB_TARGET)/cortex-m7/softfp/fpv5-sp-d16/libc++
TCPP_$(CORTEX_SOFT_SP_M7)CFLAGS = -include lib_ewl_c++.prefix $(CORTEX_SOFT_SP_M7_CFLAGS)
TCPP_$(CORTEX_SOFT_SP_M7)LFLAGS =
$(TCPP_$(CORTEX_SOFT_SP_M7))OBJECTS = $(CPPOBJECTS)

TCPP_$(CORTEX_SOFT_M7) = $(MULTILIB_TARGET)/cortex-m7/softfp/fpv5-d16/libc++
TCPP_$(CORTEX_SOFT_M7)CFLAGS = -include lib_ewl_c++.prefix $(CORTEX_SOFT_M7_CFLAGS)
TCPP_$(CORTEX_SOFT_M7)LFLAGS =
$(TCPP_$(CORTEX_SOFT_M7))OBJECTS = $(CPPOBJECTS)

TCPP_$(CORTEX_F_SP_M7) = $(MULTILIB_TARGET)/cortex-m7/fpu/fpv5-sp-d16/libc++
TCPP_$(CORTEX_F_SP_M7)CFLAGS = -include lib_ewl_c++.prefix $(CORTEX_F_SP_M7_CFLAGS)
TCPP_$(CORTEX_F_SP_M7)LFLAGS =
$(TCPP_$(CORTEX_F_SP_M7))OBJECTS = $(CPPOBJECTS)

TCPP_$(CORTEX_F_M7) = $(MULTILIB_TARGET)/cortex-m7/fpu/fpv5-d16/libc++
TCPP_$(CORTEX_F_M7)CFLAGS = -include lib_ewl_c++.prefix $(CORTEX_F_M7_CFLAGS)
TCPP_$(CORTEX_F_M7)LFLAGS =
$(TCPP_$(CORTEX_F_M7))OBJECTS = $(CPPOBJECTS)

PLATFORM_TARGETS_CPP = $(TCPP_$(THUMB_V7M)) $(TCPP_$(THUMB_F_V7M)) $(TCPP_$(THUMB_SPF_V7M)) \
		       $(TCPP_$(THUMB_V6M)) $(TCPP_$(THUMB_SOFTFP_V7M)) $(TCPP_$(THUMB_V7A)) \
		       $(TCPP_$(THUMB_F_V7A)) $(TCPP_$(THUMB_SOFTFP_V7A)) 
PLATFORM_TARGETS_CPP += $(TCPP_$(CORTEX_M7)) $(TCPP_$(CORTEX_SOFT_SP_M7)) $(TCPP_$(CORTEX_SOFT_M7)) $(TCPP_$(CORTEX_F_SP_M7)) $(TCPP_$(CORTEX_F_M7))

# Set target specific variables  
# Target specific variables settings take effect when the target found is being processed.
# So it is possible that a make variable will have different values, depending on the target being built.
# Note the scope of the setting follows the dependencies. So whatever objs are required to 
# build this target, the object dependency required to be built will get this setting. 
# E.g. ../lib/t1.a : compiler flags =  t1 flags
# Target specific variables settings are created using the settargetvars macro.
#
settargetvars=$(addprefix $(LIBOUT)/, $(addsuffix $(LIBTYPE),$($1))) : $2FLAGS=$($2XFLAGS) $($1$2FLAGS)

# As an example, the first two macro calls calls below expand to :
# $(addprefix $(LIBOUT)/, $(addsuffix $(LIBTYPE),$(TC99_1))) : CFLAGS=$(CXFLAGS) $(TC99_1CFLAGS)
#
# and utimately to rule such as:
#
# ../lib/<target>.a	: 	CFLAGS=$(CXFLAGS) $(TC99_1CFLAGS)
#
#
# This sets the CFLAGS and LFLAGS variables according to the target being built. The CFLAGS
# and LFLAGS settings is carried to the dependencies of this target also. So any objects
# that need to get built to make the target library get these CFLAGS and LFLAGS settings, also.
#

$(call settargetvars,TSTDCPP_$(THUMB_V7M),C)
$(call settargetvars,TSTDCPP_$(THUMB_F_V7M),C)
$(call settargetvars,TSTDCPP_$(THUMB_SPF_V7M),C)
$(call settargetvars,TSTDCPP_$(THUMB_SOFTFP_V7M),C)
$(call settargetvars,TSTDCPP_$(THUMB_V6M),C)
$(call settargetvars,TSTDCPP_$(THUMB_V7A),C)
$(call settargetvars,TSTDCPP_$(THUMB_F_V7A),C)
$(call settargetvars,TSTDCPP_$(THUMB_SOFTFP_V7A),C)
$(call settargetvars,TSTDCPP_$(CORTEX_M7),C)
$(call settargetvars,TSTDCPP_$(CORTEX_SOFT_SP_M7),C)
$(call settargetvars,TSTDCPP_$(CORTEX_SOFT_M7),C)
$(call settargetvars,TSTDCPP_$(CORTEX_F_SP_M7),C)
$(call settargetvars,TSTDCPP_$(CORTEX_F_M7),C)

$(call settargetvars,TCPP_$(THUMB_V7M),C)
$(call settargetvars,TCPP_$(THUMB_F_V7M),C)
$(call settargetvars,TCPP_$(THUMB_SPF_V7M),C)
$(call settargetvars,TCPP_$(THUMB_SOFTFP_V7M),C)
$(call settargetvars,TCPP_$(THUMB_V6M),C)
$(call settargetvars,TCPP_$(THUMB_V7A),C)
$(call settargetvars,TCPP_$(THUMB_F_V7A),C)
$(call settargetvars,TCPP_$(THUMB_SOFTFP_V7A),C)
$(call settargetvars,TCPP_$(CORTEX_M7),C)
$(call settargetvars,TCPP_$(CORTEX_SOFT_SP_M7),C)
$(call settargetvars,TCPP_$(CORTEX_SOFT_M7),C)
$(call settargetvars,TCPP_$(CORTEX_F_SP_M7),C)
$(call settargetvars,TCPP_$(CORTEX_F_M7),C)

# Search paths for files
#
PLATFORM_SRCDIR = src/arm

# Determine the library components
#

PLATFORM_CFILES = 
PLATFORM_CPPFILES = 


#
# Exclude these files from the library
#



