#!/usr/local/bin/perl -w

use File::Copy;


$Usage = <<END_USAGE;
   
   Usage: perl sethost.prl hh
      where hh is any one of:
         pc       for Turbo C   
         dj       for djgpp under command.com
         cyg      for Cygnus gnuwin under bash
         mgw      for Minimalist GnuWin32 under bash
         sun      for SunOs 4.x
         sol      for Solaris 2.x
         sgi      for Silicon Graphics
         lnx      for Linux on Intel x86
   This must be run from the Codas root directory.

END_USAGE

if (@ARGV != 1) { die $Usage; }
if (! (-d "make" and -d "bin" and -d "lib") ) { 
   print $Usage; die "Error: Not running from codas directory?\n\n"} 

$hh = $ARGV[0];
%hhlist = ('pc', 'dos',  'dj', 'dos',
           'sun', 'unx',  'sol', 'unx',
           'sgi', 'unx', 'lnx', 'unx',
           'cyg', 'unx', 'mgw', 'unx');

if (! defined $hhlist{$hh}) { 
   print $Usage; die "Invalid host: $hh\n"; }

if ( ! -d "lib/$hh" ) { 
   mkdir "lib/$hh", 0777 or die "Error making lib/$hh"; }
if ( ! -d "bin/$hh" ) { 
   mkdir "bin/$hh", 0777 or die "Error making bin/$hh"; }

# 2001/11/12 Pierre Jaccard
#            Added for gfi
if ( ! -d "gfi/lib/$hh" ) { 
   mkdir "gfi/lib/$hh", 0777 or die "Error making gfi/lib/$hh"; }
if ( ! -d "gfi/bin/$hh" ) { 
   mkdir "gfi/bin/$hh", 0777 or die "Error making gfi/bin/$hh"; }


if ( ! -f "include/dbhost.$hh" ) {
   die "Can't find include/dbhost.$hh\n"; }

copy("include/dbhost.$hh", "include/dbhost.h");
$mf = "make/makefile.$hhlist{$hh}";
copy("$mf", "makefile");
copy("make/$hh/makefile.dep", "makefile.dep");

print <<END_REMINDER ;

   Reminders:
      1) for pc or dj, set BASE_DIR in makefile.dep
      2) if switching from dos to unix or the reverse,
         run make/convert.prl to fix the line terminations.
      3) after editing a makefile, if there is any possibility
         that the tabs were deleted or whitespace might follow
         an ending backslash, then use make/formake.prl to 
         fix the makefile format.

END_REMINDER
