set(CMAKE_SYSTEM_NAME  Generic)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CROSSCOMPILING  1)
set(CMAKE_C_COMPILER_WORKS 1)

IF(WIN32)
  set(EXE_SUFFIX  ".exe")
ELSE()
  set(EXE_SUFFIX  "")
ENDIF()

set(RTEMS_CC_PREFIX  "${RTEMS_TOP_ARCH}-rtems5")

set(RTEMS_TOOLCHAIN_ROOT $ENV{RTEMS_TOOLCHAIN_ROOT})
string(REGEX REPLACE "\\\\" "/" RTEMS_TOOLCHAIN_ROOT ${RTEMS_TOOLCHAIN_ROOT})

set(CMAKE_C_COMPILER  ${RTEMS_TOOLCHAIN_ROOT}/bin/${RTEMS_CC_PREFIX}-gcc${EXE_SUFFIX} CACHE INTERNAL "C Compiler")
set(CMAKE_CXX_COMPILER  ${RTEMS_TOOLCHAIN_ROOT}/bin/${RTEMS_CC_PREFIX}-g++${EXE_SUFFIX} CACHE INTERNAL "C++ Compiler")
set(CMAKE_OBJCOPY  ${RTEMS_TOOLCHAIN_ROOT}/bin/${RTEMS_CC_PREFIX}-objcopy${EXE_SUFFIX} CACHE INTERNAL "Objcopy")
set(CMAKE_SIZE_UTIL  ${RTEMS_TOOLCHAIN_ROOT}/bin/${RTEMS_CC_PREFIX}-size${EXE_SUFFIX} CACHE INTERNAL "Size")
set(CMAKE_AR  ${RTEMS_TOOLCHAIN_ROOT}/bin/${RTEMS_CC_PREFIX}-ar${EXE_SUFFIX} CACHE INTERNAL "Archiver")
set(CMAKE_RANLIB  ${RTEMS_TOOLCHAIN_ROOT}/bin/${RTEMS_CC_PREFIX}-ranlib${EXE_SUFFIX} CACHE INTERNAL "Ranlib")
set(CMAKE_LINKER  ${RTEMS_TOOLCHAIN_ROOT}/bin/${RTEMS_CC_PREFIX}-ld${EXE_SUFFIX} CACHE INTERNAL "Linker")



set(RTEMS_COMMON_FLAGS "-ffunction-sections -fdata-sections")
set(RTEMS_COMMON_C_FLAGS "-std=gnu99")
set(RTEMS_COMMON_CXX_FLAGS "")

string (REPLACE ";" " " RTEMS_CPU_FLAGS "${RTEMS_CPU_FLAGS}")


set(CMAKE_C_FLAGS "${RTEMS_CPU_FLAGS} ${RTEMS_COMMON_FLAGS} ${RTEMS_COMMON_C_FLAGS}"  CACHE INTERNAL "C Flags")
set(CMAKE_CXX_FLAGS "${RTEMS_CPU_FLAGS} ${RTEMS_COMMON_FLAGS} ${RTEMS_COMMON_CXX_FLAGS}"  CACHE INTERNAL "CXX Flags")

set(CMAKE_ASM_FLAGS "${CPU_FLAGS} -x assembler-with-cpp")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--gc-sections -Wl,-print-memory-usage -Wl,-Map=out.map")