#!/bin/sh # # ProcMake 0.3: a GNU Make wrapper which produces a progress report. # 2004-12-08 groundzero@zuavra.net http://software.zuavra.net/procmake/ # # ProcMake is free to use and to distribute further, as long as no # modifications are made upon it. I make no guarantees for its effects # and functionality. By using it you assume all the responsability for # the outcome. Software can be based on it without any restrictions. ################################################### # Preferences: ################################################### # Lines with the following text are markers. MARKER_TEXT="Finished prerequisites" # Batch mode outputs the total markers as first # line, then a single dot on a new line for every # marker found. Percentage and time estimation are # left entirely to whoever is doing the processing. # Be aware that the number of markers may err high # or low in the actual run compared to the test run. BATCH_MODE=no # Time-to-finish estimation method. # "1": only estimate when percentage changes # "2": estimate every GRAIN markers # "3": GRAIN = total marker count / DIVIDE TIME_METHOD=2 # If divide is not 0, grain will be the total # marker count divided to this. A value of 100 # is practically equivalent to method 1. Values # lower than 100 produce worse precision than # method 1, higher are better. MARKER_DIVIDE=200 # If grain is not 0, time estimation is # done every grain markers; in this case, # if divide is not zero, the calculated # (total/divide) grain overrides the one set # here. If grain is zero, time estimation # is only done when the percentage changes. MARKER_GRAIN=5 # use 0 for old update method ################################################### # Script starts here. Do not modify below. ################################################### TSTART=`date +%s` TIME_METHOD=${TIME_METHOD:-1} MARKER_DIVIDE=${MARKER_DIVIDE:-1} MARKER_GRAIN=${MARKER_GRAIN:-10} # function to transform seconds in hours-minutes-seconds function showtime() { TIME=${1:-0} SECS=$((TIME%3600)) HOURS=$(((TIME-SECS)/3600)) TIME=$SECS SECS=$((TIME%60)) MINS=$(((TIME-SECS)/60)) echo -n "${HOURS}h ${MINS}m ${SECS}s" } # function to display current progress function progress() { PAR=${1:-0} if (( PAR <= 0 )); then return fi echo -en "\033[1G" case "$2" in x) echo -n "Done: ${PAR}% ?h ?m ?s " ;; w) echo -n "Done: ${PAR}% " ;; *) echo -n "Done: ${PAR}% " echo -n "ETA: " TCUR=`date +%s` TLEFT=$(((TCUR-TSTART)*(100-PAR)/PAR)) showtime $TLEFT echo -n " " ;; esac } # the simulation run test "$BATCH_MODE" = "no" && echo -n "Counting marker lines ... " TOTAL=`make -dnk ${@} 2>&1|grep -i "$MARKER_TEXT"|wc -l|tr -d "[:space:]"` test "$BATCH_MODE" = "no" && echo "expecting $TOTAL marker lines." || echo $TOTAL # report ETA method case "$TIME_METHOD" in 1) test "$BATCH_MODE" = "no" && echo "Time estimation method: percentage sensor." ;; 2) test "$BATCH_MODE" = "no" && echo "Time estimation method: fixed grain ($MARKER_GRAIN)." ;; 3) MARKER_GRAIN=$((TOTAL/MARKER_DIVIDE)) if (( MARKER_GRAIN < 1 )); then MARKER_GRAIN=1; fi test "$BATCH_MODE" = "no" && echo "Time estimation method: adaptive grain ($MARKER_GRAIN)." ;; *) test "$BATCH_MODE" = "no" && echo "Invalid time estimation method used." test "$BATCH_MODE" = "no" && echo "Edit me and change it!" exit 1000 ;; esac # the real run MCOUNT=0 OLD=0 progress 0 make -d ${@} 2>&1|grep -i "$MARKER_TEXT"|\ while read LINE; do MCOUNT=$((MCOUNT+1)) if [ "$BATCH_MODE" == "yes" ]; then echo . else NEW=$((MCOUNT*100/TOTAL)) if (( NEW > 100 )); then progress 100 x else if [ "$TIME_METHOD" == "1" ]; then if [ "$OLD" != "$NEW" ]; then progress $NEW fi else REST=$((MCOUNT%MARKER_GRAIN)) if [ "$REST" == "0" ]; then progress $NEW fi fi fi OLD=$NEW fi done RET=${PIPESTATUS[0]} test "$BATCH_MODE" = "no" && progress 100 w test "$BATCH_MODE" = "no" && echo # output results TSTOP=`date +%s` test "$BATCH_MODE" = "no" && echo -n "It took `showtime $((TSTOP-TSTART))`, " test "$BATCH_MODE" = "no" && echo "and make returned code ${RET}." exit $RET