'Makefile prefix logs with target name
We have rather complicated makefiles that make race condition debugging a nightmare due to the fact that multiple targets and being run at the same time. I'd like to prefix the logs with the target name and possibly with a timestamp as well.
Is this possible? We are using bash exclusively as the shell.
Solution 1:[1]
I'm not aware of any mechanism to automatically prepend the target to every line of output, but there is a make option --output-sync which groups all output from a target together. This makes it much simpler to debug multi-threaded makes. Note that nothing is output for a target until the target has completed, so if you have a long running target, it will delay the output.
As far as prepending the time, you can pipe your output to gawk:
make | gawk '{ print strftime("[%H:%M:%S]"), $0 }'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HardcoreHenry |
