#!/usr/bin/perl
#!/bin/perl
#!/usr/local/bin/perl
#
# configure* copyright (c) 1998/11/14(Sat) 17:14:47 by isaki.
# $Id: configure,v 2.1.1.1 2000-01-30 17:45:45+0900 isaki Exp $

#--- @`FbN

$uname="/bin/uname";
if(!-x $uname){
  $uname="/usr/bin/uname";
  if(!-x $uname){
    $uname="./uname";
  }
}

if(open(IN,"$uname|")){
  $arch=<IN>;
  chop($arch);
  close(IN);
}else{
  $arch="Human68k";
}

#--- @ˑ𕪂
if($arch eq "Human68k"){
  $u="x68";
  $exe=".x";
}else{
  $u="bsd";
  $exe="";
}

#--- o[Wǂݍ
$version_txt="_version.txt";

open(IN, $version_txt)||die("cannot open $version_txt");
$major=<IN>; chop($major);
$minor=<IN>; chop($minor);
$major="0".$major; $major=~s/\d?(\d\d)$/$1/;
$minor="0".$minor; $minor=~s/\d?(\d\d)$/$1/;
close(IN);

#--- Makefile.in
$mk="Makefile";

open(IN, "$mk.in")||die("cannot open $mk.in");
open(REF,"$mk.$u")||die("cannot open $mk.$u");
open(OUT,">$mk")  ||die("cannot open $mk");
print OUT "# This file was automatically made by ./configure\n\n";
while(<IN>){
  if(/\@\@LOCAL_VALUES\@\@/){
    while(<REF>){
      last if /LOCAL_VALUES_END/;
      next if /^#/;
      print OUT $_;
    }
  }elsif(/\@\@LOCAL_RULES\@\@/){
    while(<REF>){
      last if /LOCAL_RULES_END/;
      next if /^#/;
      print OUT $_;
    }
  }else{
    s/!major!/$major/;
    s/!minor!/$minor/;
    s/!exe!/$exe/;
    print OUT $_;
  }
}
close(IN);
close(REF);
close(OUT);
  
