#/bin/sh

echo ""
echo ""
echo =========================================================================================================
echo =========================================================================================================
echo ""
echo ""

NEWLINE='
'

(
 echo "extern void Say(const char*);"
 echo "extern void memcheck();"
 echo "void RunAllTests(void) {"
 for x in `
    cat [a-z]*.cc |
    tr -c 'A-Za-z0-9_' "$NEWLINE" | grep "^Test_" | sort -u `
 do
    echo "extern void  $x (void);"
    echo "    Say( \"... $x ...\" );"
    echo "    $x ();"
    echo "    memcheck();"
 done
 echo "}"
) > _RunAllTests.cc

 set -x
 
 if test -z "$OPT"
 then 
    g++ -c -g -fno-rtti -Wall -D"DEBUG" *.cc &&
    g++  -g -Wall *.o 
 else 
    g++ -c -g -fno-rtti -Wall $OPT -D"NO_BAD_TESTS" -U"MAGIC" *.cc &&
    g++  -static -g -Wall *.o 
 fi &&

 
 # EF_PROTECT_BELOW=1 ./a.out && 
if [ -f /usr/lib/libnjamd.so ]
then
 LD_PRELOAD=libnjamd.so ./a.out -t < 1.tri 
else
 ./a.out -t < 1.tri 
fi &&
 
 ci+ *.cc *.h *.tri mk* 
