#!/usr/local/bin/perl
#
# Copyright (C) 1996 Tetsuji KUBOYAMA and Makoto AMAMIYA
#
push(@INC,"/usr/local/lib/perl");

$base_dir  = "./";
$klic      = "klic";				# 
$mg2kl1   = $base_dir . "mg2kl1"; 
$mgtp_kl1  = $base_dir . "mgtp.kl1"; 
$cmgtp_kl1 = $base_dir . "cmgtp.kl1"; 
$dlg_mgtp_kl1 = $base_dir . "dlg-mgtp.kl1"; 
$fdown     = $base_dir . "fdown";

($progname) = ($0 =~ m#([^/]+)$#);

require 'getopts.pl';   # ץϥ饤֥

if($progname eq "mgtp"){
	if(! &Getopts('cdo:vR')){
		select(STDERR);
		print "$progname --- Model Generation Theorem Prover\n";
		print " Usage: % $progname [-cdvR] [-o filename] files\n";
		exit(0);
	}
}

$mgtp = $opt_c ? $cmgtp : $mgtp;
$mgtp = $opt_d ? $dlg_mgtp : $mgtp;
	       
$mg_file=@ARGV[0];
$_ = $mg_file; 
if (!s/\.mg//) {
    	select(STDERR);
	print "Illegal file name! \"$mg_file\" requires \".mg\".\n";
	exit(0);
    }
$base_file = $_;
$exe_file = $opt_o ? "-o $opt_o" : "";
m#([^/]+)$#;
$kl1_file = "$1.kl1";

$mgtp_kl1 = $opt_c ? $cmgtp_kl1 : $opt_d ? $dlg_mgtp_kl1 : $mgtp_kl1;


if (!$opt_R && (-e $exe_file) && (-M $exe_file < -M $mg_file)) {
    select(STDERR);
    print "`$exe_file' is up to date.\n";
    exit(0);
}

if ($opt_R || (!-e $kl1_file) || (-M $kl1_file > -M $mg_file)) {
    print STDERR "mg2kl1 $mg_file :  creating $kl1_file ...\n" if $opt_v;
    system $mg2kl1,$mg_file;
};

$compile_arg = "";	       
$compile_arg .= " -v" if $opt_v;
$compile_arg .= $exe_file." ".$kl1_file." ".$mgtp_kl1;  
print STDERR "klic $compile_arg ...\n" if $opt_v;
system $klic.$compile_arg;

