#!/usr/unsupported/bin/bash

#
# 1: variables
#
# g++ -g -static -I../std -I.. -I../stl -I../libio -L/mnt/hd/bliss/bld-x86-libstdc++/src/.libs 27/27boolfmt.cc
INC_PATH="-I../std -I.. -I../stl -I../libio"
LIB_PATH="-L/mnt/hd/bliss/bld-x86-libstdc++/src/.libs"
CXX_FLAG="-g -O2"
CXX_SHARED_FLAG=
CXX_STATIC_FLAG="-static"
RESULTS_FILE="$(date +%y%m%d)-results.txt"

#
# 2: clean
#
if [ -f $RESULTS_FILE ]; then
    rm $RESULTS_FILE
fi
echo "host: $(uname -mrsv)" >> $RESULTS_FILE
echo "compiler: $(g++ --version)" >> $RESULTS_FILE
echo "" >> $RESULTS_FILE

for NAME in */*.cc
do
    OUT_NAME="`echo $NAME | sed 's/cc$/exe/'`"

    #
    # 3: static compile, link, execute, time
    #
    echo "static compile of $NAME"
    echo "static compile of $NAME" >> $RESULTS_FILE
    TIME_START="$(date +%s)"
    g++ $CXX_FLAG $CXX_STATIC_FLAG $INC_PATH $LIB_PATH $NAME -o $OUT_NAME 
    TIME_END="$(date +%s)"
    if [ $TIME_START -lt $TIME_END ]; then
	TIME_TOTAL_S=$[ $TIME_END - $TIME_START ]
	echo "static compile/link time: $TIME_TOTAL_S seconds" >> $RESULTS_FILE
    else
	echo "static compile/link time: failure" >> $RESULTS_FILE
    fi

    # Should format this in some kind of way that makes the resulting
    # data file easy to parse. Hmm. 
    if [ -f $OUT_NAME ]; then
	size $OUT_NAME >> $RESULTS_FILE
	./$OUT_NAME
	if [ -f core ]; then
	    echo "static execute: failure" >> $RESULTS_FILE
	    rm core
	else
	    echo "static execute: pass" >> $RESULTS_FILE
	fi
	rm $OUT_NAME
    else
	echo "static compile/link: failure" >> $RESULTS_FILE
    fi
    echo "" >> $RESULTS_FILE

    #
    # 3: shared compile, link, execute, time
    #
    echo "shared compile of $NAME"
    echo "shared compile of $NAME" >> $RESULTS_FILE
    TIME_START="$(date +%s)"
    g++ $CXX_FLAG $CXX_SHARED_FLAG $INC_PATH $LIB_PATH $NAME -o $OUT_NAME 
    TIME_END="$(date +%s)"
    if [ $TIME_START -lt $TIME_END ]; then
	TIME_TOTAL_S=$[ $TIME_END - $TIME_START ]
	echo "shared compile/link time: $TIME_TOTAL_S seconds" >> $RESULTS_FILE
    else
	echo "shared compile/link time: failure" >> $RESULTS_FILE
    fi

    # Should format this in some kind of way that makes the resulting
    # data file easy to parse. Hmm. 
    if [ -f $OUT_NAME ]; then
	size $OUT_NAME >> $RESULTS_FILE
	./$OUT_NAME
	if [ -f core ]; then
	    echo "shared execute: failure" >> $RESULTS_FILE
	    rm core
	else
	    echo "shared execute: pass" >> $RESULTS_FILE
	fi
	rm $OUT_NAME
    else
	echo "shared compile/link: failure" >> $RESULTS_FILE
    fi
    echo "" >> $RESULTS_FILE

    echo "" >> $RESULTS_FILE
    echo "" >> $RESULTS_FILE
done


# 990210 bkoz should also run these, with -DDEBUG_ASSERT to 
# make sure the finished executables run without errors.









