MATLAB: How to include the makefile in the ZIP file generated using packNgo

codegenEmbedded Codersimulink coder

I generate C/C++ code from my model with the options 'Generate code only' and 'Package code and artifacts' enabled. So after code generation the result is a ZIP file where I would expect all the files required to compile the executable.
However, there are some required files missing in the ZIP file, for example the makefile.
I would like to have everything in the ZIP file after the code generation process, so I don't have to scramble all the files together afterwards. Are there any settings for this?

Best Answer

It is a documented limitation that the packNgo feature does not include all files from code generation folder, including makefiles:
packNgo was mainly designed for users who would like to relocate the generated code to another environment or software project. For this use case, packaging the makefile is not necessary.
To work around the issue, disable the 'Package code and artifacts' option and run below script after the code generation has finished:
model = gcs;
bDirInfo = RTW.getBuildDir(model);
makefile = [model '.mk'];
cd(bDirInfo.BuildDirectory);
load('buildInfo.mat');
addNonBuildFiles(buildInfo, makefile, bDirInfo.BuildDirectory);
% once the makefile is "in" buildInfo, you can run PACKNGO and
% it will automatically include the makefile
% (and any other nonBuildFile you wish to add)
packNGo(buildInfo,{'packType', 'hierarchical','nestedZipFiles',false});