#!/usr/bin/perl

=pod 
  You can change the variables $type and $level.
  choose variables below to build shared or static.

=cut

#  choose to link to shared or static
$type = 'shared';
#$type = 'static';

# level of information printed
$level = 0;
#$level = 1;
#$level = 2;
#$level = 3;

# probably don't change below here
###########################################
$F77 = 'g77';
$FFLAGS = '  ';
#$STLIBS = ' ./libcheck.a  /usr/lib/libslatec.a ';
$STLIBS = '  /usr/lib/libslatec.a ';
$SHLIBS = ' -L.    -lslatec ';
#$SHLIBS = ' -L. -lcheck   -lslatec ';
#$LIBS = ' ../*/*.o  libcheck.a  ';

@files = `ls test*.f`;

sub dosys {
  my $com = shift;
  print "$com\n";
  system $com;
}

sub static_test {
  $i =0;
  print "Doing static test\n";
  if ( not -e "libcheck.a" ) {
    print "libcheck.a not present, making ...\n";
    dosys "make static";
  }
  foreach ( @files) {
    chomp;
    dosys "rm -f chktest";
    dosys "$F77 $FFLAGS -o chktest $_  $STLIBS";
    dosys "echo $level | ./chktest";
    print "\n";
    $i++;
    #  last if $i > 1;
}
  
}

sub shared_test {
  print "Doing shared test\n";
  if ( not -e "libcheck.so" ) {
    print "libcheck.so not present, making ...\n";
    dosys "make shared";
  }
  $i =0;
  foreach ( @files) {
    chomp;
    dosys "rm -f chktest";
    dosys "$F77 $FFLAGS -o chktest $_  $SHLIBS";
    dosys "export LD_LIBRARY_PATH=. ; echo $level | ./chktest";
    print "\n";
    $i++;
    #  last if $i > 1;
  }
}

if ($type eq 'shared' ) {
  shared_test();
}
else {
  static_test();x
}
