title: How to log make output without buffering from stdout and stderr
body: <p>I am having a problem with logging to output from an automated build.</p>
  
  <p>The build is done with a Makefile and the makefile utility.</p>
  
  <p>The problem is that normal output like compiler command lines go to stdout and compile errors go to stderr.</p>
  
  <p>I want to get the output from the build as it would show on the screen. So something like:</p>
  
  <pre><code>(stdout) CC -c file.cpp
  (stderr) Compile error at file.cpp line 232, blah blah blah
  (stdout) CC -c file2.cpp
  </code></pre>
  
  <p>What I tried (from a ksh script) is:</p>
  
  <p>make -k > build.log 2> build.log</p>
  
  <p>This results in a single log file but the problem is that the streams are buffered and so the result in the log file is all mixed up.</p>
  
  <p>I could capture the output into 2 separate log files but then I would have no info on how to glue them back together into a single log file.</p>
  
  <p>Is there a way to turn off buffering for stdout and stderr in this case?</p>