Reputation: 21
I have a custom build tool configured in IAR. It takes a text file and outputs a .h file that is used by other C files. When I add the .h file to the list of output files it is deleted as the first step of a complete rebuild. The custom build step is executed at the end of the build after linking. That causes compilation of .c files depending on the .h to fail.
The other option is to put the custom build step in the project's pre-build step. However, this is always executed regardless of whether the .txt file is changed.
Questions:
Can I make IAR understand the dependency of the .c file on the .h file and go run the custom build step before its compilation?
If that isn't possible, can I at least force the custom build step to happen at the beginning?
Upvotes: 2
Views: 1752
Reputation: 887
In newer EWARM versions the custom build step provides a checkbox "run custom build tool before all other tool". I don't know in which version it has been added but I can confirm it is present in EWARM 7.60 and newer.
Another possible workaround for older versions could be, to set the 'read-only' attribute to the generated header file. This prevents EWARM from deleting that file at the beginning of a build run. Of course this requires the tool which generates the header file to be able to overwrite the read-only file. This can be usually usually achieved by running the external tool through a batch file, which removes the read-only attribute before running the tool and then restores the read-only attribute directly after the file has been generated.
Upvotes: 1
Reputation: 1
IAR appears to compile files alphabetically. In my case the source file is a CSV file, and the intermediate files produced by the custom tool by munging the CSV file are a C and H file (the H file is consumed by the other source files).
I solved this by prepending a 00 to the name of the intermediate C and H files produced by the custom tool. Due to the alphabetical IAR behavior, the CSV to C/H conversion via the custom tool happens in the beginning.
Upvotes: 0
Reputation: 5758
My solution is to make the pre-build step output to a temporary file, and only copy it over the original file if it differs. The pre-build step is always run, but it will not trigger a complete recompile if the result is the same as last time.
Put this in a batch file and make it your pre-build step:
your_prebuild_application > SVN_Revision_tmp.h
fc /b SVN_Revision_tmp.h SVN_Revision.h > nul
if errorlevel 1 goto newfile
del SVN_Revision_tmp.h
goto end
:newfile
del SVN_Revision.h
rename SVN_Revision_tmp.h SVN_Revision.h
goto end
:end
Upvotes: 1