Have a build system comprised of make files, where I have one macro that
tries to capture the output of commands and stores it in a log file as
well as displaying it to the user should a variable be set.
Basically, the idea is that when calling make, users will just use the
following form:
$ make rulename
which will only output messages at various points (some rules will use
echo at the start to inform the user of where they currently are).
At the same time the output from all the commands run by the make rules
is outputted into log files, so that they can be viewed if there is a
problem.
Now I also wanted to permit a user to set a variable on the command line
(V), to also output to the stdout everything that is going to the log
files.
make macro
log = $(if $(filter 2,$(V)),2>&1 | tee -a $1,>> $1 2>&1)
Problem occurs that if V=2, tee is used which results in the wrong exit
code being received by the make rule.
i.e.
rule:
somerule:
@some_command $(call log,mylog.log)
With V=1, this becomes:
somerule:
@some_command >> mylog.log 2>&1
With V=2, this becomes:
somerule:
@some_command 2>&1 | tee -a mylog.log
Problem is that when there is an error executing some_command and V=2,
then make only receives the exit code of tee, which barring some problem
in tee itself is always going to be 0.
Any suggestions on how to get the output to go to the log file in all
three cases while still resulting in the correct exit code being given
to make?
--
Darragh
"Nothing is foolproof to a sufficiently talented fool."
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!