When using the toolchain approach, you will need to create a "grt_make_rtw_hook.m" file (if you are using Embedded Coder, it will be "ert_make_rtw_hook.m "). You can find more information about how to use build hooks in this documentation.
To add a main, you need to follow this process:
- Copy "ert_make_rtw_hook.m" to a folder in the MATLAB path. Rename it in accordance with the naming conventions. For example, to use it with the GRT target "grt.tlc", rename it to "grt_make_rtw_hook.m".
- Rename the "ert_make_rtw_hook" function within the file to match the file name (grt_make_rtw_hook if using Simulink Coder)
- In the "after_tlc" stage, use the "setTargetProvidesMain" function as follows:
setTargetProvidesMain(buildInfo,true);
Now, you need to use the Configuration Parameters > Code Generation > Custom Code > Source Files field to add your custom "main.c" to the project. When you indicate that the target provides "main.c," the project requires this file to build without errors.
More related information can be found on the "setTargetProvidesMain" and "addSourceFiles" documentation pages below, referring to functions that could be used in the 'after_tlc' case in the "grt_make_rtw_hook.m" file.
"setTargetProvidesMain" documentation:
"addSourceFiles" documentation:
You can find an example "grt_make_rtw_hook" setting up that functionality attached.