#====================================================================================================
#
#    @file        compiler_options.mak
#    @version     1.0.0
#
#    @brief       Integration Framework - Make file used for storing compile and link options
#    @details     This file contains compiler specific options for building the system 
#
#    Platform        : PA
#    Build Version   : MPC5777CXG_MCAL_1_0_0_RTM_ASR_REL_4_3_REV_0001_20190318
#
#   (c) Copyright 2006-2016 Freescale Semiconductor, Inc. 
#       Copyright 2017 - 2018 NXP
#       All Rights Reserved.
#
#    This file contains sample code only. It is not part of the production code deliverables.
#
#====================================================================================================
#
PROD_PAT_MCAL = $(TRESOS_DIR)  $(GENERATE_DIR)
PROD_PAT_OS   = $(SSC_ROOT)  $(OS_TRESOS_WORKSPACE_DIR)
PRJFLAG :=-DMPC$(DERIVATIVE)
VLETYPE = vle


SUBDERIVATIVE_NAME=-DDERIVATIVE_$(DERIVATIVE)
COREIDFLAG=$(CORE_ID)

OBJ_FILE_SUFFIX = o
LIB_FILE_SUFFIX = lib

.SUFFIXES:            # Delete the default suffixes
.SUFFIXES: .c .h .$(OBJ_FILE_SUFFIX) .$(LIB_FILE_SUFFIX)

cpopt      += $(addprefix -I, $(INCLUDE_DIRS)) 
cpopt      += -DSCHM_USE_MACROS

MAPFILE = $(call winpath, $(OUT_DIR)/$(SAMPLE_APP_NAME).map)
EXE_EXT := elf

ifeq ($(CORE_SET),2)
    proc   :=  -cpu=ppc5748gz210
else
    proc   :=  -cpu=ppc5748gz4204
endif
		
ifeq ($(ASR_OS_FLAG), AUTOSAR_OS_USED)
        PREPROCESSOR_DEFINES += osclassname apptypesh oscfgname ospropname
        osclassname_KEY      := __CLASS_SC1
        osclassname_VALUE    := 1
        apptypesh_KEY        := APPTYPESH
        apptypesh_VALUE      := "\".\\..\\..\\..\\common\\memory.h\""
        oscfgname_KEY        := OSCFGH
        oscfgname_VALUE      := "<$(projname)_cfg.h>"
        ospropname_KEY       := OSPROPH
        ospropname_VALUE     :="\"$(call remove_slashes,$(OS_PROPHEADER))\""

        #ifeq ($(CC_I),)
        #CC_I := -I
        #endif

        #ifeq ($(CC_D),)
        #CC_D := -D
        #endif

        $(foreach bsw,$(modulelist),\
        $(eval bsw_name=$(call remove_slashes,$($(bsw)_dir)))\
        $(eval $(bsw)_cfg_dir?=cfgno)\
        $(eval PREPROCESSOR_DEFINES += $(bsw) $(bsw_name) $(bsw)_name_string $(bsw)_cfg_id)\
        $(eval $(bsw)_KEY=$(bsw)_integrated)\
        $(eval $(bsw)_VALUE=1)\
        $(eval $(bsw)_name_string_KEY=$(bsw)_name_string)\
        $(eval $(bsw)_name_string_VALUE=$(bsw_name)_string)\
        $(eval $(bsw)_cfg_id_KEY=$(bsw)_cfg_id)\
        $(eval $(bsw)_cfg_id_VALUE=$(call remove_slashes,$($(bsw)_cfg_dir)_id))\
        $(eval $(bsw_name)_KEY=$(bsw_name))\
        $(eval $(bsw_name)_VALUE=1))
endif


ifeq ($(TOOLCHAIN),ghs)
#\/----------------------------------------------------- GREEN HILLS START -----------------------------------------------------\/
    CC             := $(call winpath, $(TOOLCHAIN_DIR)/ccppc.exe)
    LD             := $(call winpath, $(TOOLCHAIN_DIR)/ccppc.exe)
    AS             := $(call winpath, $(TOOLCHAIN_DIR)/asppc.exe)

    # Compiler paths
    cbin        := $(TOOLCHAIN_DIR)
    cinc        := $(TOOLCHAIN_DIR)/include/ppc
    clibinc     := .
    ceabinc     := .
    ceablib     := .



    # Common Compilers' options
    ccopt   := -DOSGHSPPC \
               -DGHS \
               $(PRJFLAG) \
               $(SUBDERIVATIVE_NAME) \
               $(COREIDFLAG) \
               -DEU_DISABLE_ANSILIB_CALLS \
               -D$(ASR_OS_FLAG) \
               --incorrect_pragma_warnings \
               -$(VLETYPE) \
               -preprocess_assembly_files \
               --no_exceptions \
               -dual_debug \
               --prototype_errors \
               -Wundef \
               -ansi \
               -Ospace \
               -G \
               -noslashcomment \
               -Wimplicit-int \
               -Wshadow \
               -Wtrigraphs \
               -noSPE \
               -nostartfile \
               -sda=0 \
               --short_enum \
               --diag_error 223

    # Common Preprocessor options
    cpopt  :=  


    # Common Assembler options
    asopt    := -G \
                -list


    ldopt   :=   -$(VLETYPE) \
                 -nostartfiles \
                 --nocpp \
                 -Mn \
                 -delete \
                 -ignore_debug_references \
                  -keepmap


    #OS specific compiler options
    ifeq ($(ASR_OS_FLAG), AUTOSAR_OS_USED)
        proc   :=   
        
        # Compilers' options specific to OS
        ccopt     :=   $(ccopt) \
                       $(proc) \
                       -DOSDISABLE_AUTOSAR_VERSION_CHECK

        # Preprocessor options specific to OS
        cpopt       +=  -I$(OTHER_INCLUDES) \
                        -I$(SAMPLE_INCLUDES)

        # Assembler options specific to OS
        asopt       += 

        cpopt       += $(foreach define,$(PREPROCESSOR_DEFINES), -D$($(define)_KEY)=$($(define)_VALUE))

    else
        #processor selection for non OS components
         

        # Compilers' options specific to Drivers
         ccopt    := $(ccopt) \
                     $(proc) \
                     $(MODEFLAG)
    
         # Compilers' options specific to Drivers
         asopt    := $(asopt) \
                     $(proc)
					 
         ldopt   := $(ldopt) \
                   $(proc) 					 
    endif


#/\----------------------------------------------------- GREEN HILLS END -----------------------------------------------------/\

endif
# $(compiler) == ghs





ifeq ($(TOOLCHAIN),diab)
#\/----------------------------------------------------- DIAB START -----------------------------------------------------\/

CC         := $(call winpath, $(TOOLCHAIN_DIR)/WIN32/bin/dcc.exe)
LD         := $(call winpath, $(TOOLCHAIN_DIR)/WIN32/bin/dld.exe)
AS         := $(call winpath, $(TOOLCHAIN_DIR)/WIN32/bin/das.exe)


# Compiler paths
cbin       := $(TOOLCHAIN_DIR)
cinc       := .
clibinc    := .
ceabinc    := .
ceablib    := .


ccopt      :=   $(PRJFLAG) \
                $(SUBDERIVATIVE_NAME) \
                -DDIAB \
                -DAUTOSAR_OS_NOT_USED \
                -DEU_DISABLE_ANSILIB_CALLS \
                -g3 \
                -l \
                -Xdialect-ansi \
                -XO \
                -Xsize-opt \
                -Xsmall-data=0 \
                -Xno-common \
                -Wa,-Xisa-vle \
                -Xdebug-dwarf2 \
                -Xdebug-local-all \
                -Xdebug-local-cie \
                -Xdebug-struct-all \
                -Xforce-declarations \
                -Xmacro-undefined-warn \
                -ee1481 \
                -Xnested-interrupts \
                -Xaddr-sconst=0x11 \
                -Xaddr-sdata=0x11 \
                -Xlink-time-lint
              
asopt    :=  -g \
             -Xisa-vle \
             -Xasm-debug-on \
             -Xdebug-dwarf2
# Preprocessor options
cpopt    :=  

ldopt    :=   -Xelf \
              -m6 \
              -Xlibc-old \
              -lc \
              -Xlink-time-lint \
              $(LIB_PATH)

    #OS specific compiler options
    ifeq ($(ASR_OS_FLAG), AUTOSAR_OS_USED)
        proc   :=   
        
        # Compilers' options specific to OS
        ccopt     :=   $(ccopt) \
                       $(proc) \
                       -DOSDISABLE_AUTOSAR_VERSION_CHECK

        # Preprocessor options specific to OS
        cpopt       +=  -I$(OTHER_INCLUDES) \
                        -I$(SAMPLE_INCLUDES)

        # Assembler options specific to OS
        asopt       += 

        cpopt       += $(foreach define,$(PREPROCESSOR_DEFINES), -D$($(define)_KEY)=$($(define)_VALUE))

    else
        #processor selection for non OS components
         proc   :=   -tPPCE200Z759N3VEG:simple

        # Compilers' options specific to Drivers
         ccopt    := $(ccopt) \
                     $(proc) \
                     $(MODEFLAG)
    
         # Compilers' options specific to Drivers
         asopt    := $(asopt) \
                     $(proc)
					 
         ldopt   := $(ldopt) \
                    $(proc) 					 
    endif

#/\----------------------------------------------------- GCC END -----------------------------------------------------/\

endif
# $(compiler) == gcc
