How to display build date and time in case of multiple source files?


I want to display the build date and time on the serial monitor and also on my OLED display. I know __ DATE __ and __ TIME __, but these values only show the compile time of one specific source file (in my case: main.cpp). If a different source file was compiled last, this value is not what I need.

So I tried to use extra_scripts to delete main.cpp.o after each build but couldn’t figure out a way how to do that. For example, I don’t know how to resolve $BUILD_DIR within a script or a callback.

Does anyone have an idea how to “always compile main.cpp when any other sourcefile is compiled”?
Or at least how to “delete main.cpp.o after each build”?

Additional info: I am using VS Code and platformio for an ESP32 with Arduino framework.