#!/bin/sh

precompile()
{
    cd ..

    cd ../signal
    icmbuild

    cd ../processdata
    icmbuild

    cd ../process
    icmbuild

    cd driver
}

compile()
{
    precompile

    echo compiling $1.cc $2

    g++ --std=c++11 -o $1 $2 $1.cc \
		-L../tmp -lprocess \
		-L../../processdata/tmp -lprocessdata \
		-L../../signal/tmp -lsignal \
		-lbobcat -s
}
    
case $1 in
    (pipe|gpg|sha1sum|limit|ls)
        compile $1
    ;;

    (sort|thread)
        compile $1 -pthread
    ;;

    (all)
	compile cincoutcerr
	compile $1 -pthread
    ;;

    (clean)
	rm -f pipe gpg sort sha1sum thread limit ls all cincoutcerr
	rm -rf ../tmp ../../*/tmp
    ;;

    (*)
    echo "
Provide the name of the test as first argument. The executable receives the
name of the test. The test-name plus .cc extension is the name of the test
program source file.

Available tests are:
    all	    - stdin is split over stdout and stderr using multi-threading
    gpg     - stdin is a PGP encrypted file, stdout is the decrypted file,
              stderr shows the result of the signature verification
    limit   - limits process time to 5 seconds, while copying stdin to stdout
              using /bin/cat
    ls      - show directory contents: no input, only std output
    pipe    - stdin is passed through 3 /bin/cat programs, and is then
              written to stdout
    sha1sum - compute the input's sha1sum not using multi-threading
    sort    - multi threading is used when sorting stdin to stdout, where
              sort's output is extracted from the Process object
    thread  - compute the input's sha1sum using multi-threading
    
    clean   - not a test, but removes the test binaries
"
    ;;

esac







