#!/usr/local/bin/perl
# Author Tomasz Haupt  (haupt@npac.syr.edu) 1997
#===========================================================================
# read fortran makefile and create list of files used to build the code.
# remove files not used in DAGH stub
# it is assumed that files of interest are gathered as OBJ
#===========================================================================

$makein="Makefile";
$makeout1=">appfiles";
$makeout2=">fmodules";


open(MIN,$makein)  || die "cannot open $makein: $! \n";
open(MOUT2,$makeout2)  || die "cannot open $makeout2: $! \n";

$makestr="";

$toggle=0;
LINE: while($line=<MIN>) {
      if($line =~ /MD/) {$toggle=1;}
      $toggle || next LINE;
      $toggle && ($line ne "\n") || last LINE;
      chop($line);
      $makestr=$makestr.$line;
}

$makestr =~ s/\\//g;
$makestr =~ s/MD = //;

print MOUT2 $makestr;
close MOUT2;
close MIN;

open(MIN,$makein)  || die "cannot open $makein: $! \n";
open(MOUT1,$makeout1)  || die "cannot open $makeout1: $! \n";


$makestr="";

$toggle=0;
LINE: while($line=<MIN>) {
      if($line =~ /OBJ/) {$toggle=1;}
      $toggle || next LINE;
      $toggle && ($line ne "\n") || last LINE;
      chop($line);
      $makestr=$makestr.$line;
}

$makestr =~ s/\\//g;
$makestr =~ s/OBJS = //;

print MOUT1 $makestr;

close MOUT1;
close MIN;
