快速回答
最好不要修改任何系统文件。这是一些变量和一个简单的colorgcc shell 函数,用于管道输出编译的输出。您丢失了返回代码,但如果您真的需要它,您可以以不同的方式处理它。
n=$(tput setaf 0)
r=$(tput setaf 1)
g=$(tput setaf 2)
y=$(tput setaf 3)
b=$(tput setaf 4)
m=$(tput setaf 5)
c=$(tput setaf 6)
w=$(tput setaf 7)
N=$(tput setaf 8)
R=$(tput setaf 9)
G=$(tput setaf 10)
Y=$(tput setaf 11)
B=$(tput setaf 12)
M=$(tput setaf 13)
C=$(tput setaf 14)
W=$(tput setaf 15)
END=$(tput sgr0)
colorgcc()
{
perl -wln -M'Term::ANSIColor' -e '
m/not found$/ and print "$ENV{N}$`$ENV{END}", "$&", "$ENV{END}"
or
m/found$/ and print "$ENV{N}$`${g}", "$&", "$ENV{END}"
or
m/yes$/ and print "$ENV{N}$`${g}", "$&", "$ENV{END}"
or
m/no$/ and print "$ENV{N}$`$ENV{END}", "$&", "$ENV{END}"
or
m/undefined reference to/i and print "$ENV{r}", "$_", "$ENV{END}"
or
m/ Error |error:/i and print "$ENV{r}", "$_", "$ENV{END}"
or
m/ Warning |warning:/i and print "$ENV{y}", "$_", "$ENV{END}"
or
m/nsinstall / and print "$ENV{c}", "$_", "$ENV{END}"
or
m/Linking |\.a\b/ and print "$ENV{C}", "$_", "$ENV{END}"
or
m/Building|gcc|g\+\+|\bCC\b|\bcc\b/ and print "$ENV{N}", "$_", "$ENV{END}"
or
print; '
}
像这样使用它:
./configure | tee -a yourlog.configure.log | colorgcc
make | tee -a yourlog.make.log | colorgcc
make install | tee -a yourlog.install.log | colorgcc