#!/bin/csh
# $Id: buildntdist,v 1.48 2001/03/06 21:40:12 balay Exp balay $ 
# 

if ($#argv == 1) then
  set version=$1
  echo "Building ~/petscnt$version.tar.gz"
else
  set version=""
endif
#
# If /sandbox/petsc/tmp does not exist create it.
#
set tmpdir = "/sandbox/petsc/tmp"
if (! -d $tmpdir) then
  mkdir -p $tmpdir
endif
if (! -d $tmpdir) then
  echo 'Cannot create $tmpdir. Exiting..'
endif


/bin/rm -r -f $tmpdir/petscnt
/bin/rm -f $tmpdir/petscnt.tar
setenv PETSC_DIR /home/bsmith/petsc
cd /home/bsmith/petsc
make ACTION=clean tree

cd /home/bsmith
/bin/tar cFFXf /home/bsmith/petsc/maint/xclude $tmpdir/petscnt.tar petsc

#
#   Gets the C version of BLAS and LAPACK (these are excluded by the 
#   regular PETSc distribution hence we need to tar them up separately
#
#cd /home/bsmith/petsc/src
#/bin/tar cFFXf /home/bsmith/petsc/maint/xcludecblas $tmpdir/cblas.tar blaslapack


mkdir $tmpdir/petscnt
cd $tmpdir/petscnt
/bin/tar xf $tmpdir/petscnt.tar

# Now copy the win32 specific stuff over from /home/bsmith/petsc
cd $tmpdir/petscnt/petsc
/bin/cp /home/bsmith/petsc/bmake/common_win32 bmake
mkdir -p bmake/win32
/bin/cp /home/bsmith/petsc/bmake/win32/* bmake/win32

cd $tmpdir/petscnt/petsc
/bin/rm -rf bin
find $tmpdir/petscnt -type d -name output -exec /bin/rm -rf {} \;
/bin/rm -rf bmake/alpha* bmake/sun4* bmake/solaris* bmake/hpux*
/bin/rm -rf bmake/paragon* bmake/rs6000* bmake/freebsd* bmake/linux*
/bin/rm -rf bmake/win32_gnu bmake/t3d* bmake/t3e* bmake/IRIX* bmake/i386*
/bin/rm -rf bmake/win32_* bmake/VXPV bmake/config
/bin/rm -rf bmake/ascired* bmake/beos* bmake/macx*
/bin/rm -f  bmake/common. bmake/common 
#
# Eliminate the '#requirespackage' stuff
#
/bin/cp -f bmake/win32/req.mak src/mat/impls/rowbs/mpi/makefile
/bin/cp -f bmake/win32/req.mak src/mat/impls/rowbs/makefile
/bin/cp -f bmake/win32/req.mak src/mat/partition/impls/pmetis/makefile
#/bin/cp -f bmake/win32/req.mak src/sys/src/objects/ams/makefile
/bin/cp -f bmake/win32/req.mak src/sys/src/objects/ams/java/makefile
/bin/cp -f bmake/win32/req.mak src/sys/src/viewer/impls/socket/matlab/makefile
/bin/cp -f bmake/win32/req.mak src/sys/src/viewer/impls/ams/makefile
/bin/cp -f bmake/win32/req.mak src/sys/src/draw/impls/x/makefile
/bin/cp -f bmake/win32/req.mak src/sles/pc/impls/spai/makefile
/bin/cp -f bmake/win32/req.mak src/ts/impls/implicit/pvode/makefile
/bin/cp -f bmake/win32/req.mak src/sys/src/matlabengine/makefile
#
# patch up missing dirs
#
/bin/mkdir -p src/dm/usg ;/bin/cp -f bmake/win32/req.mak src/dm/usg/makefile
mv src/contrib/libtfs src
/bin/rm -rf src/contrib/*
mv src/libtfs src/contrib
chmod u+w src/contrib/makefile
echo "DIRS = libtfs" > src/contrib/makefile
/bin/cat bmake/win32/req.mak >> src/contrib/makefile
#
# Build the tag files
#
cd $tmpdir/petscnt/petsc
make etags etags_examples TAGSDIR=`pwd`
/bin/cp -f bmake/win32/makefile.dos makefile

cd $tmpdir/petscnt
chmod -R u+w petsc
/home/bsmith/petsc/maint/makecpp.tcl $tmpdir/petscnt/petsc

/bin/rm -f $tmpdir/petscnt.tar $tmpdir/cblas.tar


cd $tmpdir/petscnt
if ($#argv == 1) then
  mv petsc petsc$version
endif

/bin/tar cf $tmpdir/petscnt$version.tar petsc$version
cd ~/
/bin/rm -r -f $tmpdir/petscnt

gzip -f $tmpdir/petscnt$version.tar
/bin/cp $tmpdir/petscnt$version.tar.gz ~/
chmod ug+w ~/petscnt$version.tar.gz 
/bin/rm -f $tmpdir/petscnt$version.tar.gz
