Related: Making make print commands before executing when NOT using CMake
I have the task to recollect the full list of optimizations flags that are being used to compile our project. The idea is to compile the whole project and parse the compilation log to collect all the flags that are being used.
Our project is compiled using make, but our 900 makefiles doesn't follow the same patterns everywhere and, in particular, the silent mode is giving me headaches. There are usages of make -s
, of $(MAKE) -s
, of MAKEFLAGS += -s
, of @
at the beginning of lines, usages of conditional constructs that depends on environmental variables, several compilation commands in one line separated by ;
, and so on.
The usage of make SHELL="/bin/bash -x" | grep -E "Entering|Leaving" 2> log.txt"
is great, because I get the whole list of used commands with all variables already expanded and each individual command in a different line, which is awesome for parsing purposes, but the problem is with the make's messages of Entering
and Leaving
, because that is what allows me to track which "subfolder" I'm in at each moment, so I can gather the executed commands on a per-module basis.
But the silent mode strikes again. If a submake is executed in silent mode, the Entering|Leaving lines are not printed at all.
If there a way, together with -x
, to force bash to print the pwd bash is in at the moment of executing each command? Because the only solution I see so far is to edit all the files to remove all usages of the silent mode, which is not easy because I could even edit files that are not even makefiles in the first place (not all makefiles are necesarily named makefile
).
Any other solution?
NOTE: --dry-run
is not an option. It has its own problems as well. Using SHELL=/bin/bash -x
is the best option so far.
Define a text file /tmp/bash
as :
pwd
/bin/bash "$@"
then run chmod +x /tmp/bash
Define another text file /tmp/Makefile
as :
all:
date
sleep 1
Now run SHELL=/tmp/bash make
in /tmp, you'll get :
$ SHELL=/tmp/bash make
date
/tmp
Sun 11 Jun 12:56:17 2023
sleep 1
/tmp
Update
Actually, we don't need /tmp/bash, just run SHELL="pwd; exec /bin/bash" make