It is very valuable to have a date and time information in the binary. That way for example using a shell I can check the version of the firmware running on a device, or it can be printed on a console or UART as needed.
The C/C++ language offers to macros which represent date and time.
They can be used directly or used with a pointer like below:
static const char *const FW_Date = __DATE__; static const char *const FW_Time = __TIME__;
However, they match the date and time the when the file (or compilation unit) has been compiled. If that file is not recompiled, it keeps the ‘old’ date and time.
But for a firmware version I would like to have the latest date & time of it. Sure I could delete the object file or do a clean and a full build.
A more elegant solution is to ‘touch’ (or change) the file containing the date/time information. On Linux or a ‘bare’ make or cmake build I could use the ‘touch’ command for this, and that file will be recompiled.
On Windows and including Eclipse (MCUXpresso IDE in this case) it is very easy too: I can setup a pre-build step which touches the file I need to rebuild, and it gets recompiled every time I do a build: exactly what I need :-).
Go to the project settings, C/C++ Build, Settings and then edit the Pre-Build steps in the Build Steps tab:
Use the touch command to touch a file, e.g.
💡 Make sure that there is line ending (CR/Return) at the end of the line!
The current directory is the build output directory, e.g. ‘Debug’.
That way I can always trigger a ‘touch & build’:
It is possible to use Eclipse Build variables too, for example if I would like to delete the ELF/Dwarf (Output binary) I could use
And then this will cause the following build at least to re-link the binary.
Happy Dating 🙂
- MCUXpresso IDE: https://www.nxp.com/mcuxpresso/ide/download
- Other usage of Build Steps: https://mcuoneclipse.com/2017/03/29/mcuxpresso-ide-s-record-intel-hex-and-binary-files/