g++, colorgcc and ccache

后端 未结 7 2019
庸人自扰
庸人自扰 2021-02-04 01:45

Trying to combine ccache and colorgcc. Following link text:

  • my g++ is soft link to colorgcc
  • ~/.colorgccrc contains line: \"g++: ccache /usr/bin/g++\"
7条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 02:24

    The Quick Answer

    Better not to modify any system files. here is some variables & a simple colorgcc shell function to pipe the output of your compilation. You loose the return code but you can handle that differently if you really need it.

    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; '
        }
    

    use it like that :

    ./configure | tee -a yourlog.configure.log | colorgcc
    make | tee -a yourlog.make.log | colorgcc
    make install | tee -a yourlog.install.log | colorgcc
    

提交回复
热议问题