#!/usr/local/bin/perl5

# This creates:
# "files" that is used by make to obtain the list of current agents
# "rmic.bat" that runs the very speedy dos rmic program over all the agents

$package = shift;

$class_dir = 'j:\\' . $ENV{USER} . '\hal\classes';

@javaFiles =  <*.java>;
@agentFiles = <*Agent.java>;
@implFiles = <*Impl.java>;
@grammarFiles = <*.gram>;

$file = "rmic.bat";
$filelist = "files";

open($file,">$file");
open($filelist,">$filelist");

print $filelist "TFILES = ";
foreach (@javaFiles) {
    if ( !( $_ =~ /EHA\.java/ ) )
    {
	print $filelist " \\\n\t$_";
    }
}

print $filelist "\n\n";
print $filelist "TAGENTS = ";
foreach (@agentFiles) {
  ($class) = /(.+)Agent.java/;
  if ($class) {
    print $filelist "\\\n\t$_";
    print $file "rmic.exe -d $class_dir $package.$class" . "Agent\r\n";
  }
}

# non-agent rmi needing things.
print $filelist "\n\n";
print $filelist "TIMPLS = ";
foreach (@implFiles) {
  ($class) = /(.+)Impl.java/;
  if ($class) {
    print $filelist "\\\n\t$_";
    print $file "rmic.exe -d $class_dir $package.$class" . "Impl\r\n";
  }
}

print $filelist "\n\n";
print $filelist "GFILES = ";
foreach (@grammarFiles) {
  print $filelist " \\\n\t$_";
}

close $file;
close $filelist;
