#!/usr/local/bin/perl
# ************************************************************ #
# TO INSTALL - run this perl script, BUT first !!!
#
# Edit the variables declarations at the top
# 
#    BINDIR - where you want the executable to be put.
#    LIBDIR - where you want all the psmulti library files put.
#    MANDIR - where you want the man pages installed
#    PERLEXE - the execution path for Perl
#
# NOTE: these should be full pathnames!
# Any directories that are missing will be created!
#
# ************************************************************ #

# ************************************************************ #
# SCCS: @(#)Install	2.7 5/26/92
# HISTORY:
#       murray - Apr 3, 1992: Created.
# ************************************************************ #

# ============================================================ #
#   Site Dependent Settings
# ============================================================ #

$BINDIR="/usr/local/bin";
$LIBDIR="/usr/local/lib/psmulti";
$MANDIR="/usr/man";
$PERLEXE="/usr/local/bin/perl";

# ============================================================ #
#    Variable Declarations
# ============================================================ #

$USEAGE="Install [-b BinDir] [-l LibDir] [-m ManDir]";

@Executables=( "psmulti", "psfix" );

@Library=
  (
    'format-standard.pl', 'format-standard.ps',
    'format-raw.pl', 'format-raw.ps',

    'border-psmulti.ps', 'border-shadow.ps', 'border-pborder.ps',
    'border-mborder.ps', 'border-iborder.ps', 'border-frame.ps',

    'lcvp.ps', 'shadowstring.ps', 'bbox-util.ps', 'tilebox.ps',
    'param-util.ps', 'wrap-ops.ps', 'gstate-util.ps',
    'psmulti-wrapops.ps', 'psmulti-tm.ps',

    'pspp-util.pl', 'bbox-util.pl', 'file-util.pl', 'dsc-util.pl',
    'page-configure.pl',

    'psfix-border.ps', 'psfix-showpage.ps'
  );

@ManPages=( "psmulti.n", "psfix.n" );

$OrigLibDir="/home/murray/PS/psmulti";
$OrigPerlDir="/usr/local/bin/perl";

# ============================================================ #
#             Argument Processing
# ============================================================ #

while ( $#ARGV >= 0 )
  {
    $_=$ARGV[0];

    if ( /^-b/ )
      { $BINDIR=$ARGV[1]; shift @ARGV; }

    elsif ( /^-l/ )
      { $LIBDIR=$ARGV[1]; shift @ARGV; }

    elsif ( /^-m/ )
      { $MANDIR=$ARGV[1]; shift @ARGV; }

    else
      { print STDERR "usage: $USEAGE\n"; exit 1; }

    shift @ARGV;
  }

 
if ( ! -d $BINDIR )
  { print STDERR "Creating Directory: $BINDIR\n"; mkdir($BINDIR,0755); }

if ( ! -d $LIBDIR )
  { print STDERR "Creating Directory: $LIBDIR\n"; mkdir($LIBDIR,0755); }

if ( $LIBDIR !~ /psmulti$/ )
  { if ( ! -d $LIBDIR )
      { print STDERR "Creating Directory: $LIBDIR\n";
        mkdir($LIBDIR,0755);
      }
    $LIBDIR="$LIBDIR/psmulti";
  }

if ( ! -d $LIBDIR )
  { print STDERR "Creating Directory: $LIBDIR\n"; mkdir($LIBDIR,0755); }

if ( ! -d $MANDIR )
  { print STDERR "Creating Directory: $MANDIR\n"; mkdir($MANDIR,0755); }

# ============================================================ #
#           Install Exectuables
# ============================================================ #

foreach $File ( @Executables )
  {
    if ( -f $File )
      { open(INPUT,$File); }
    
    elsif ( -f "$File.pl" )
      { open(INPUT,"$File.pl"); }
    
    elsif ( -f "SCCS/$File" )
      { system "sccs get $File";
        system "chmod a+x $File";
        open(INPUT,$File);
      }
    
    elsif ( -f "SCCS/s.$File.pl" )
      { system "sccs get $File.pl";
        system "chmod a+x $File.pl";
        open(INPUT, "$File.pl");
      }
    else
      { print STDERR "Warning: could not find $File\n"; next; }

    open(OUTPUT,">/tmp/$File");
    
    while( <INPUT> )
      { s!$OrigPerlDir!$PERLDIR!ge; 
        s!$OrigLibDir!$LIBDIR!ge;
        print OUTPUT $_;
      }

    close(INPUT); close(OUTPUT);

    system "install -m 0755 /tmp/$File $BINDIR";
    unlink("/tmp/$File");
  }

# ============================================================ #
#           Install Library Files
# ============================================================ #

foreach $File (@Library)
  {
    if ( -f $File )
      { system "install -m 0644 $File $LIBDIR"; }
    elsif ( -f "SCCS/s.$File" )
      { system "sccs get $File";
        system "install -m 0644 $File $LIBDIR";
      }
    else
      { print STDERR "Warning: could not find file $File\n"; }
  }

# ------------------------------------------------------------ #
# And Finally ... The Manual Page
# ------------------------------------------------------------ #

foreach $File (@ManPages)
  {
    if ( $File =~ /[^\.]\.(.)/ )
      { $Section=$1; }
    else
      { $Section="n"; }

    if ( ! -d "$MANDIR/man$Section" )
      { print STDERR "Creating Directory: $MANDIR/man$Section\n";
        mkdir("$MANDIR/man$Section",0755);
      }

    if ( -f $File )
      { system "install -m 0644 $File $MANDIR/man$Section\n"; }
    elsif ( -f "SCCS/s.$File" )
      { system "sccs get $File";
        system "install -m 0644 $File $MANDIR/man$Section\n";
      }
    else
      { print STDERR "Warning: Could not find manual page $File\n"; }
  }

