#!/bin/sh

SCRIPTTEST=false

while test $# -gt 0
do
    case "$1" in
    -t)
        SCRIPTTEST=true
        ;;
    -*)
	echo "Unknown option $1 Aborting."
	exit 1
	;;
    *)
	break
	;;
    esac
    shift
done

if $SCRIPTTEST
then
    cat <<EOF
make_daily_make_summary test
Directory:     `pwd`
Other options: $@
EOF
    exit 0
fi

exec >index.html

cat << EOF
<html>
<head>
<title>Results of daily builds</title>
<style type="text/css">
.results {position: absolute; right: 10pt; background-color: green; }
.fails {background-color: red;}
.others {background-color: blue;}
.results,.fails,.others {height: 0.9em;}
</style>
</head>
<body>
<h1>Results of daily builds</h1>

<ul>
EOF

(
cd logs;
for f in `ls -r`
do 
    if test -r $f/index.html
    then
	(
	cd $f
	eval `(cat *.result) 2> /dev/null | \
	    awk '\
		{result[$1]++} \
		END { \
		    printf "RESULT=%c", 39; \
		    s=""; \
		    for(i in result) { \
			printf "%s%d x %s", s, result[i], i; \
			s=", "; \
		    } \
		    printf "%c; TOTAL=%d; FAIL=%d; OTHER=%d\n", 39, NR, \
			result["Fail"], NR-result["Fail"]-result["Pass"]}'`
	cat <<EOF
<div class="results" style="width: ${TOTAL}pt;">
<div class="fails" style="width: ${FAIL}pt;"> &nbsp; </div>
<div class="others" style="width: ${OTHER}pt;"> &nbsp; </div>
</div>
<li> <A HREF="logs/$f">$f</A>: $RESULT
EOF
	if test -r warnings.log
	then
	    echo "; unique warnings: `cat warnings.log | wc -l`"
	fi
	echo "</li>"
	)
    fi
done
)

cat << EOF
</ul>

<p>
Maintenance notes: see <a href="http://wiki/Hydra_drivers/Daily_builds">wiki page</a>.
</p>
</body>
</html>
EOF
