ifeq ($(CCS_HOST_OS),linux)
    CHECK_PYTHON3 = $(shell command -v python3 2>/dev/null)
    ifeq ($(CHECK_PYTHON3), )
        PYTHON := python
    else
        PYTHON := python3
    endif
	RENAME  := mv
    DELETE  := rm
    COPY    := cp
else ifeq ($(CCS_HOST_OS),win32)
	PYTHON  := py
    RENAME  := ren
    DELETE  := del
    COPY    := copy
else
    PYTHON  := python3
	RENAME  := mv
    DELETE  := rm
    COPY    := cp
endif

ifeq ($(CCS_HOST_OS),win32)
    CPU2APP_REL_PATH        := ..\\..\\cpu2App.bin
    CPU3APP_REL_PATH        := ..\\..\\cpu3App.bin
    CPU3APP_CERT_REL_PATH   := ..\\..\\cpu3App.cert.bin
    SECCFGCPU3_REL_PATH     := ..\\..\\seccfgCpu3.bin
    SECCFGCPU2_REL_PATH     := ..\\..\\seccfgCpu2.bin
    DUMMY_CERT_RAM          := ..\\dummy_cert_crypto_unlock_ram.cert
    DUMMY_CERT_FLASH        := ..\\dummy_cert_crypto_unlock_flash.cert
    DUMMY_CERT_FLASH_CPU3   := ..\\dummy_cert_flash_cpu3.cert
    UPDATEDUMMYCERT         := updateDummyCert.exe
    UPDATECPUBINSIZE        := updateCpuBinSize.exe
    CONCAT                  := type
    IF_EQUAL_CLOSE          :=
else
    CPU2APP_REL_PATH        := ../../cpu2App.bin
    CPU3APP_REL_PATH        := ../../cpu3App.bin
    CPU3APP_CERT_REL_PATH   := ../../cpu3App.cert.bin
    SECCFGCPU3_REL_PATH     := ../../seccfgCpu3.bin
    SECCFGCPU2_REL_PATH     := ../../seccfgCpu2.bin
    DUMMY_CERT_RAM          := ../dummy_cert_crypto_unlock_ram.cert
    DUMMY_CERT_FLASH        := ../dummy_cert_crypto_unlock_flash.cert
    DUMMY_CERT_FLASH_CPU3   := ../dummy_cert_flash_cpu3.cert
    CONCAT                  := cat
    IF_EQUAL_CLOSE          :=  || :
    ifeq ($(CCS_HOST_OS),linux)
        UPDATEDUMMYCERT         := updateDummyCert.bin
        UPDATECPUBINSIZE        := updateCpuBinSize.bin
    else
        UPDATEDUMMYCERT         := updateDummyCert.mac.bin
        UPDATECPUBINSIZE        := updateCpuBinSize.mac.bin
    endif
endif

ifeq ($(CCS_HOST_OS),win32)
    define CREATE_DIAGRAM
        $(eval $@_FLAG= $(1))
        $(eval $@_NODE_TOOL= $(2))
        $(eval $@_COM_TI_MCU_SDK_INSTALL_DIR= $(3))
        $(eval $@_BuildDirectory= $(4))
        if ${$@_FLAG} == 1  ${$@_NODE_TOOL} "${$@_COM_TI_MCU_SDK_INSTALL_DIR}/tools/clb_tool/clb_syscfg/dot_file_libraries/clbDotUtility.js"  "${$@_COM_TI_MCU_SDK_INSTALL_DIR}/tools/clb_tool/clb_syscfg/" "${$@_BuildDirectory}/syscfg" "${$@_BuildDirectory}/syscfg/clb.dot"
        if ${$@_FLAG} == 1  rd /s /q "${$@_BuildDirectory}/diagrams"
        if ${$@_FLAG} == 1  mkdir "${$@_BuildDirectory}/diagrams"
        if ${$@_FLAG} == 1  ${$@_NODE_TOOL} "${$@_COM_TI_MCU_SDK_INSTALL_DIR}/source/driverlib/.meta/generate_diagrams.js" "${$@_COM_TI_MCU_SDK_INSTALL_DIR}" "${$@_BuildDirectory}/diagrams" "${$@_BuildDirectory}/syscfg"
    endef
    define IF_EQUAL_OPEN
        $(eval $@_LHS= $(1))
        $(eval $@_RHS= $(2))
        if ${$@_LHS} == ${$@_RHS}
    endef
else
    define CREATE_DIAGRAM
        $(eval $@_FLAG= $(1))
        $(eval $@_NODE_TOOL= $(2))
        $(eval $@_COM_TI_MCU_SDK_INSTALL_DIR= $(3))
        $(eval $@_BuildDirectory= $(4))
        [ ${$@_FLAG} -eq 1 ] && ${$@_NODE_TOOL} "${$@_COM_TI_MCU_SDK_INSTALL_DIR}/tools/clb_tool/clb_syscfg/dot_file_libraries/clbDotUtility.js" "${$@_COM_TI_MCU_SDK_INSTALL_DIR}/tools/clb_tool/clb_syscfg/" "${$@_BuildDirectory}/syscfg" "${$@_BuildDirectory}/syscfg/clb.dot" || :
        [ ${$@_FLAG} -eq 1 ] &&  rm -r "${$@_BuildDirectory}/diagrams" || :
        [ ${$@_FLAG} -eq 1 ] &&  mkdir "${$@_BuildDirectory}/diagrams" || :
        [ ${$@_FLAG} -eq 1 ] && ${$@_NODE_TOOL} "${$@_COM_TI_MCU_SDK_INSTALL_DIR}/source/driverlib/.meta/generate_diagrams.js" "${$@_COM_TI_MCU_SDK_INSTALL_DIR}" "${$@_BuildDirectory}/diagrams" "${$@_BuildDirectory}/syscfg" || :
    endef
    define IF_EQUAL_OPEN
        $(eval $@_LHS= $(1))
        $(eval $@_RHS= $(2))
        [ ${$@_LHS} -eq ${$@_RHS} ] &&
    endef
endif

ALGORITHM := RSA4k

ifeq ($(ALGORITHM),RSA4k)
        SIGNING_KEY=tools/boot/signing/mcu_custMpk.pem
endif
ifeq ($(ALGORITHM),ECDSA256R1)
        SIGNING_KEY=tools/boot/signing/mcu_custMpk_secp256r1.pem
endif
ifeq ($(ALGORITHM),ECDSA384R1)
        SIGNING_KEY=tools/boot/signing/mcu_custMpk_secp384r1.pem
endif
ifeq ($(ALGORITHM),ECDSA521R1)
        SIGNING_KEY=tools/boot/signing/mcu_custMpk_secp521r1.pem
endif
ifeq ($(ALGORITHM),BRAINPOOL512)
        SIGNING_KEY=tools/boot/signing/mcu_custMpk_brainpool512.pem
endif