@@ -21,11 +21,41 @@ if((NOT (DEFINED CROSS_COMPILE)) AND (DEFINED ENV{CROSS_COMPILE}))
2121 set (CROSS_COMPILE $ENV{CROSS_COMPILE} )
2222endif ()
2323
24+ if ((NOT (DEFINED CROSS_COMPILE_TOOLCHAIN_PATH)) AND (DEFINED ENV{CROSS_COMPILE_TOOLCHAIN_PATH}))
25+ set (CROSS_COMPILE_TOOLCHAIN_PATH $ENV{CROSS_COMPILE_TOOLCHAIN_PATH} )
26+ endif ()
27+
2428set ( CROSS_COMPILE ${CROSS_COMPILE} CACHE PATH "" )
2529assert(CROSS_COMPILE "CROSS_COMPILE is not set" )
2630
31+ set (CROSS_COMPILE_TOOLCHAIN_PATH ${CROSS_COMPILE_TOOLCHAIN_PATH} CACHE PATH "Cross Compile toolchain directory" )
32+
2733set (COMPILER gcc)
2834set (LINKER ld)
2935set (BINTOOLS gnu)
3036
37+ # CROSS_COMPILE is flexible, meaning that it can in principle always support newlib or picolibc.
38+ # This is not decided by CROSS_COMPILE itself, but depends on libraries distributed with the installation.
39+ # Also newlib or picolibc may be created as add-ons. Thus always stating that CROSS_COMPILE does not have
40+ # newlib or picolibc would be wrong. Same with stating that CROSS_COMPILE has newlib or Picolibc.
41+ # The best assumption for TOOLCHAIN_HAS_<NEWLIB|PICOLIBC> is to check for the presence of
42+ # '_newlib_version.h' / 'picolibc' and have the default value set accordingly.
43+ # This provides a best effort mechanism to allow developers to have the newlib C / Picolibc library
44+ # selection available in Kconfig.
45+ # Developers can manually indicate library support with '-DTOOLCHAIN_HAS_<NEWLIB|PICOLIBC>=<ON|OFF>'
46+
47+ # Support for newlib is indicated by the presence of '_newlib_version.h' in the toolchain path.
48+ if (NOT CROSS_COMPILE_TOOLCHAIN_PATH STREQUAL "" )
49+ file (GLOB_RECURSE newlib_header ${CROSS_COMPILE_TOOLCHAIN_PATH} /_newlib_version.h)
50+ if (newlib_header)
51+ set (TOOLCHAIN_HAS_NEWLIB ON CACHE BOOL "True if toolchain supports newlib" )
52+ endif ()
53+
54+ # Support for picolibc is indicated by the presence of 'picolibc.h' in the toolchain path.
55+ file (GLOB_RECURSE picolibc_header ${CROSS_COMPILE_TOOLCHAIN_PATH} /picolibc.h)
56+ if (picolibc_header)
57+ set (TOOLCHAIN_HAS_PICOLIBC ON CACHE BOOL "True if toolchain supports picolibc" )
58+ endif ()
59+ endif ()
60+
3161message (STATUS "Found toolchain: cross-compile (${CROSS_COMPILE} )" )
0 commit comments