#!/bin/sh
# ACL:license
#  ----------------------------------------------------------------------
#  This software and ancillary information (herein called "SOFTWARE")
#  called POOMA (Parallel Object-Oriented Methods and Applications) is
#  made available under the terms described here.  The SOFTWARE has been
#  approved for release with associated LA-CC Number LA-CC-98-65.
#  
#  Unless otherwise indicated, this SOFTWARE has been authored by an
#  employee or employees of the University of California, operator of the
#  Los Alamos National Laboratory under Contract No.  W-7405-ENG-36 with
#  the U.S. Department of Energy.  The U.S. Government has rights to use,
#  reproduce, and distribute this SOFTWARE, and to allow others to do so.
#  The public may copy and use this SOFTWARE, FOR NONCOMMERCIAL USE ONLY,
#  without charge, provided that this Notice and any statement of
#  authorship are reproduced on all copies.  Neither the Government nor
#  the University makes any warranty, express or implied, or assumes any
#  liability or responsibility for the use of this SOFTWARE.
#  
#  If SOFTWARE is modified to produce derivative works, such modified
#  SOFTWARE should be clearly marked, so as not to confuse it with the
#  version available from LANL.
#  
#  For more information about POOMA, send e-mail to pooma@acl.lanl.gov,
#  or visit the POOMA web page at http://www.acl.lanl.gov/pooma/.
#  ----------------------------------------------------------------------
# ACL:license

##########################################################################
# POOMA script to install POOMA
#
# Usage:
#
#   makeinstall <SUITE> <installdir> <arch> [<extensions>]
#
# where
#
#   <SUITE> = the suite where files should be read from.
#   <installdir> = the directory where files should be installed.
#   <arch> = the architecture subdir where libs should be installed.
#   <extensions> = the extensions to install
#
# NOTE: This must be invoked from the top-level of the POOMA tree.
##########################################################################


### Get our current directory, and make sure it is the top-level dir

topdir=`pwd`

if [ ! -d $topdir/src -o ! -d $topdir/lib ]; then
  echo "Error: This script must be run from the top level of the POOMA tree."
  exit 1
fi


### Make sure we have the right arguments

if [ "$#" != "4" -a "$#" != "5" ]; then
  echo "Usage: $0 <SUITE> <installdir> <arch> <libext> [<extensions>]"
  exit 1
fi

suite=$1
libext=$4
libbase=pooma
libname=lib$libbase
libfull=$libname.$libext

extensions=""
if [ "$#" != "4" ]; then
  extensions=$5
fi

libfilename=$libname$extensions.$libext

if [ ! -d lib/$suite -o ! -f lib/$suite/$libfilename ]; then
  echo "Error: Cannot find lib/$suite suite directory or $libfilename library file."
  exit 1
fi


### Create installation directory tree

installdir=$2
srcdir=$installdir/src
htmldir=$installdir/html

echo "Creating installation directory tree ..."
if [ ! -d $installdir ]; then
  mkdir -p $installdir
  if [ ! -d $installdir ]; then
    echo "Error: Cannot create installation directory $installdir."
    exit 1
  fi
fi

arch=$3
archdir=$installdir/$arch
libdir=$archdir/lib
bindir=$archdir/bin

for d in $srcdir $htmldir $archdir $libdir $bindir; do
  if [ ! -d $d ]; then
    mkdir $d
    if [ ! -d $d ]; then
      echo "Error: Cannot create directory $d."
      exit 1
    fi
  fi
done

cd $archdir
for d in src html ; do
  if [ ! -d $d ]; then
    ln -s ../$d $d
  fi
done
cd $topdir


### Copy source files to src directory

echo "Copying src files to $installdir ..."
srclisth=`find src -name \*.h -print | grep -v tests | grep -v CVS | grep -v arch`
srclistc=`find src -name \*.cpp -print | grep -v tests | grep -v CVS | grep -v arch`
srclista=`find src/arch -type f -print | grep -v CVS`
tar cf - $srclisth $srclistc $srclista | (cd $installdir ; tar xvf - )


### Copy HTML files to html directory

echo "Copying html files to $installdir ..."
tar cf - html | (cd $installdir ; tar xvf - )


### Copy library files to lib directory

echo "Copying lib files to $libdir ..."

makefilename=Makefile.$libbase$extensions
hdrdirname=PoomaConfiguration$extensions
configfilename=PoomaConfiguration.h

rm -rf $libdir/$makefilename $libdir/$libfilename $libdir/$hdrdirname
cp lib/$suite/$makefilename $libdir/$makefilename
cp lib/$suite/$libfilename $libdir/$libfilename
mkdir $libdir/$hdrdirname
cp lib/$suite/$configfilename $libdir/$hdrdirname/$configfilename


### Copy binary files to bin directory

# none yet


### Create links to default version of library, if necessary

cd $libdir
if [ ! -f $libfull ]; then
  echo "Creating link from $libfull --> $libfilename ..."
  ln -s $libfilename $libfull
fi
if [ ! -f Makefile.$libbase ]; then
  echo "Creating link from Makefile.$libbase --> $makefilename ..."
  ln -s $makefilename Makefile.$libbase
fi
if [ ! -r PoomaConfiguration ]; then
  echo "Creating link from PoomaConfiguration --> $hdrdirname ..."
  ln -s $hdrdirname PoomaConfiguration
fi

# ACL:rcsinfo
#  ----------------------------------------------------------------------
#  $RCSfile: makeinstall,v $   $Author: julianc $
#  $Revision: 1.6 $   $Date: 1999/12/23 03:07:22 $
#  ----------------------------------------------------------------------
# ACL:rcsinfo
