summaryrefslogtreecommitdiffstats
path: root/utils/brmake
blob: e30119dd10bc5b35eacc158040bddcc5d7cad52a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
# (C) 2016, "Yann E. MORIN" <yann.morin.1998@free.fr>
# License: WTFPL, https://spdx.org/licenses/WTFPL.html

main() {
    local found ret start d h m mf

    if ! which unbuffer >/dev/null 2>&1; then
        printf "you need to install 'unbuffer' (from package expect or expect-dev)\n" >&2
        exit 1
    fi

    start=${SECONDS}

    ( exec 2>&1; unbuffer make "${@}"; ) \
    > >( while read line; do
             printf "%(%Y-%m-%dT%H:%M:%S)T %s\n" -1 "${line}"
         done \
         |tee -a br.log \
         |grep --colour=never -E '>>>'
       )
    ret=${?}

    d=$((SECONDS-start))
    printf "Done in "
    h=$((d/3600))
    d=$((d%3600))
    [ ${h} -eq 0 ] || { printf "%dh " ${h}; mf="02"; }
    m=$((d/60))
    d=$((d%60))
    [ ${m} -eq 0 ] || { printf "%${mf}dmin " ${m}; sf="02"; }
    printf "%${sf}ds" ${d}

    if [ ${ret} -ne 0 ]; then
        printf "  (error code: %s)" ${ret}
    fi
    printf "\n"

    return ${ret}
}

main "${@}"
OpenPOWER on IntegriCloud