1# SPDX-License-Identifier: Apache-2.0
2
3find_package(Deprecated COMPONENTS XTOOLS)
4
5zephyr_get(XTOOLS_TOOLCHAIN_PATH)
6assert(    XTOOLS_TOOLCHAIN_PATH      "XTOOLS_TOOLCHAIN_PATH is not set")
7
8set(TOOLCHAIN_HOME ${XTOOLS_TOOLCHAIN_PATH})
9
10set(COMPILER gcc)
11set(LINKER ld)
12set(BINTOOLS gnu)
13
14# Choose one of the toolchains in 'TOOLCHAIN_HOME' at random to use as
15# a 'generic' toolchain until we know for sure which toolchain we
16# should use. Note that we can't use ARCH to distinguish between
17# toolchains because choosing between iamcu and non-iamcu is dependent
18# on Kconfig, not ARCH.
19if("${ARCH}" STREQUAL "xtensa")
20  file(GLOB toolchain_paths ${TOOLCHAIN_HOME}/xtensa/*/*)
21else()
22  file(GLOB toolchain_paths ${TOOLCHAIN_HOME}/*)
23endif()
24list(REMOVE_ITEM toolchain_paths ${TOOLCHAIN_HOME}/sources)
25list(GET  toolchain_paths 0 some_toolchain_path)
26
27get_filename_component(some_toolchain_root "${some_toolchain_path}" DIRECTORY)
28get_filename_component(some_toolchain "${some_toolchain_path}" NAME)
29
30set(CROSS_COMPILE_TARGET ${some_toolchain})
31
32set(SYSROOT_TARGET ${CROSS_COMPILE_TARGET})
33
34set(CROSS_COMPILE ${some_toolchain_root}/${CROSS_COMPILE_TARGET}/bin/${CROSS_COMPILE_TARGET}-)
35set(SYSROOT_DIR   ${some_toolchain_root}/${SYSROOT_TARGET}/${SYSROOT_TARGET})
36set(TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib")
37
38unset(some_toolchain_root)
39unset(some_toolchain)
40
41message(STATUS "Found toolchain: xtools (${XTOOLS_TOOLCHAIN_PATH})")
42