How would I do this in a make file? I wanted to wrap "CXX = g++"
–
HaltingStateApr 21 '12 at 0:30

That's actually a rather different question, as g++ will send any output (since it only produces output on error) to stderr. It's complex enough that you would want to use a wrapper script. Also, are you thinking of wrapping the (normally nonexistent) output from g++, or the echoed command from make? The latter can't easily be done while echoing the actual command.
–
geekosaurApr 21 '12 at 0:39

Anything. I just realized that the output was not from gcc, but from the make file. You are correct. When it is compiling main.cpp it outputs "main.cpp", how would I do "0:04: main.cpp", something like that?
–
HaltingStateApr 21 '12 at 0:53

1

That's more complicated, as the macro doesn't have ready access to the filename you want to echo; you need to replace the make pattern rules. See gnu.org/software/make/manual/make.html#Pattern-Rules for gmake; it's similar for other versions of make although specific details will differ.
–
geekosaurApr 21 '12 at 1:00

As geekosaur's answer says, time prints to stderr, and your command prints to stdout. And time waits for your command to finish before writing its output. I think you should try the program sponge from the package moreutils, like this:

/usr/bin/time -f "%e: " echo test | sponge

Sponge is a program which soaks up all the input and writes it when the input is closed (i.e. the previous program terminates). The above works because time will print to stderr when echo finishes, and echo's stdout will be soaked up by the sponge, which will only wring itself out when the left hand side finishes. So this does pretty much what you want as far as I can tell, though I wasn't able to test it for complete accuracy because my system's /usr/bin/time doesn't support the -f option.