MATLAB: Does the modified Make File result in a build error in Real-Time Workshop 7.3 (R2009a)

simulink coder

I use the following DOS commands (SYSTEM commands) from MATLAB to modify a Make file that was generated by Real-Time Workshop 7.3 (R2009a).
fid1 = fopen(CodeToModify, 'r');
fid2 = fopen('Tmp.m', 'w');
%
% Modify Tmp.m (fid2) somehow
%…
[status, result] = dos(['ATTRIB -R ', CodeToModify]);
[status, result] = dos(['del ' CodeToModify, ' -echo']);
[status, result] = dos('ATTRIB -R Tmp.m');
[status, result] = dos(['REN Tmp.m "', CodeToModify, '"']);
[status, result] = dos(['ATTRIB +R ', CodeToModify]);
I now wish to execute the 'Model.BAT' file to build this code with the updated Make file. However, I receive the following error message.
\RTW\C\Tools\lcctools.mak no such file or directory.
I can navigate to the folder and verify that this file is present.

Best Answer

This issue is typically observed when the Make file is saved in a way that is not readable later in the build process.
To resolve this issue:
First perform a file comparison by 'Right Click –> Compare Against-> the unmodified Make File'. Additionally, you may wish to open both text files in a simple (non-windows) text editor such as EMACS.
You may need to identify exactly what is causing the Make File to be altered in a way that cannot allow it to be picked up correctly by the resulting build process.
In this specific case, the following steps resolved the issue.
1) Use the "t" option when opening the Code as a text file
fid1 = fopen(CodeToModify, 'rt');
fid2 = fopen('Tmp.m', 'wt');
2) Remove any blank space characters.
fprintf(fid2, '%s\n', str);
3) Restrict using the following ATTRIB flags in the DOS commands as below
%[status, result] = dos(['ATTRIB -R ', CodeToModify]);
[status, result] = dos(['del ' CodeToModify, ' -echo']);
%[status, result] = dos('ATTRIB -R Tmp.m');
[status, result] = dos(['REN Tmp.m "', CodeToModify, '"']);
%[status, result] = dos(['ATTRIB +R ', CodeToModify]);