-
Notifications
You must be signed in to change notification settings - Fork 63
Supporting a new platform in the C target
One of the objectives of the C target is be able to generate code that will be cross compiled and will run on embedded platforms.
To support a new target (board, processor, etc.), do the following:
- LFC changes: The platform must be added as a target property:
target C {
platform: Patmos
}
This should make the LFC define a Cmake flag called CMAKE_SYSTEM_NAME and set it to "Patmos"
-
core/platform/Platform.cmake This file is included by the CMakeLists.txt and it looks at CMAKE_SYSTEM_NAME and sets the variable LF_PLATFORM_NAME which is added to the sources. In
Platform.cmake
andCMkaeLists.txt
lf_patmos_support.c should be added. TODO: why is the information here duplicated? -
lf_patmos_support.c/h The API defined in platform.h must be implemented in lf_patmos_support.c. If you have a pthread implementation you can just
#include "lf_POSIX_threads_support.c"
. This is what lf_linux_support.c does -
Add an entry in the
enum Platform
inTargetProperty.java
-
Add an entry in
pickCompilePlatform
inCGenerator.java
If the platform in question does not have cmake support, then you can create a shell script to perform the cross compilation and, if you wish, uploading the compiled code to the board in question. To specify to use your build script, include in your .lf file the following:
target C {
build: "path_to_script/my_script.sh"
};
Instructions for writing the script can be found here: https://www.lf-lang.org/docs/handbook/target-declaration?target=c#build
An example can be found here: https://github.com/icyphy/lf-buckler/blob/main/scripts/build_nrf_unix.sh