#!/usr/bin/perl -- # -*-Perl-*-

# Compile and run a unit test.

{

    $CC = "CC";
    $CFLAGS = "-g -woff 3577";
#    $LFLAGS = '-lmalloc_cv';
    while ($ARGV[0] =~ /^[-+]/)
    {
	if ($ARGV[0] eq '-gnu')
	{
	    $CC = "g++";
	    shift;
	}
	else
	{
	    $CFLAGS .= " $ARGV[0]";
	    shift;
	}
    }
    foreach (@ARGV)
    {
	$_ =~ s/\.c\+\+$//;
	$files = &files("$_.c++");

	$command = "$CC $CFLAGS -DUNIT_TEST_$_ $files $LFLAGS && a.out";
# 	$command =~ s|a.out|_RLD_LIST=/usr/tmp/libdmalloc.so:DEFAULT a.out|;
	print "$command\n";
	system("$command") && die "dead\n";
    }	

}

sub files {
    local($c) = @_;
    local($files) = $c;
    local($_);
    open(C, "<$c") || return $files;
    while (<C>)
    {
	chop;
	$files = $_ if s|^//Files\:||;
    }
    return $files;
    close(C);
}
