b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | Logging Everything of make process |
| 2 | |
| 3 | The console's scrollback buffer will often prove to be too small to keep the full output of the package build process. |
| 4 | |
| 5 | There are moments you want to enable logging of the build process so that you can comfortably search(grep) through the logfiles |
| 6 | when there appears to be a problem with building process |
| 7 | |
| 8 | The command looks like this: |
| 9 | |
| 10 | make -j2 V=99 2>&1 | tee build.log |
| 11 | |
| 12 | 0 is stdin. 1 is stdout. 2 is stderr |
| 13 | |
| 14 | There's one way to remember this construct (maybe it is not entirely accurate): |
| 15 | ------------- |
| 16 | First of all, 2>1 looks like a very good way to redirect stderr to stdout. but remember, |
| 17 | it has a very harmful disadvantage: it may actually be interpreted as "redirect stderr to a file named 1". |
| 18 | ------------- |
| 19 | & indicates that what follows is a file descriptor and not a filename. So the construct becomes: 2>&1. |
| 20 | ------------- |
| 21 | >& is shell syntax for "fold a file descriptor into another", you can also interprete it as |
| 22 | "it is the syntax to redirect a stream to another file descriptor" |
| 23 | |
| 24 | The part " | tee build.log" causes a file build.log to be created (if it does not yet exist) and a copy of the text that |
| 25 | your script displays on the console is going to be written to it. |
| 26 | Any previous content of that logfile will be overwritten. |
| 27 | |
| 28 | The part "2>&1" means that you will also catch the ERROR output of failed commands. You would normally not notice, |
| 29 | but programs can write their output to "standard output" as well as "error output". |
| 30 | These are two separate "channels" if you like, and since the tee command will only catch "standard output" and |
| 31 | duplicate it into the target file, you will have to explicitly add "error output" as well. |
| 32 | Remember, the error output will often be the stuff you're most interested in! |
| 33 | |
| 34 | |
| 35 | By using this command, you are still able to watch the proceedings of the package build process on your console, |
| 36 | and afterwards you can open the log file in an editor at your leisure. |
| 37 | |
| 38 | look for the info: |
| 39 | |
| 40 | •Compilation errors ( grep -iE "(error|failed)" ) |
| 41 | •Header/include/library files missing ( grep -iE "(not found|unavailable)" ) |
| 42 | |
| 43 | ref: http://tldp.org/LDP/abs/html/io-redirection.html |
| 44 | |