#!/bin/sh
#
# $Id: makeallchives 338696 2011-09-21 19:34:41Z bollin $
#
#
# Creates all archives from a directory above 'ncbi'
#
# based on mkarchive written by
# J. Epstein, 9/29/95
#   modified to work in a distributed environment 3/13/98 (Friday the 13th)
#    -Karl Sirotkin
#
PATH=/bin:/usr/bin:$PATH
export PATH

if [ ! -d ncbi ] ; then
	echo must be executed above \'ncbi\' 
	exit 1
fi
if [ ! -d ncbi/build ] ; then
	echo must be executed above \'ncbi\' after make
	exit 1
fi

datafiles="humrep.fsa lineages.txt sequin.hlp asn2ff.prt bstdt.val \
   featdef.val gc.val makerpt.prt objprt.prt pubkey.enc seqcode.val \
   sgmlbb.ent taxlist.txt BLOSUM62 KSat.flt KSchoth.flt KSgc.flt \
   KShopp.flt KSkyte.flt KSpur.flt KSpyr.flt \
   BLOSUM45 BLOSUM80 PAM30 PAM70 KSpcc.mat \
   ecnum_ambiguous.txt ecnum_specific.txt UniVec.nhr UniVec.nin UniVec.nsq \
   UniVec_Core.nhr UniVec_Core.nin UniVec_Core.nsq organelle_products.prt \
   product_rules.prt"

configfiles="nlmstmanrc sequinrc ncbidtrc"

TOPDIR=`pwd`
configdir=$TOPDIR/ncbi/config/unix
datadir=$TOPDIR/ncbi/data
errmsgdir=$TOPDIR/ncbi/errmsg
sequindoc=$TOPDIR/ncbi/doc/sequin.htm
sequinimages=$TOPDIR/ncbi/doc/images/

#delete the old archive subdir
test -d archive && rm -rf archive

#make sure we have timestamp file
test -f ncbi/VERSION || date > ncbi/VERSION

for i in sequin entrez fa2htgs asn2xml
do
	f=""
	mkdir -p archive/$i/data
	for file in $datafiles
	do
		ln $datadir/$file archive/$i/data/
	done
	ln ncbi/VERSION archive/$i/VERSION

#	cat > archive/$i/Cn3D.ReadMe <<EOF
#Cn3D is now distributed separately from $i
#To download Cn3D please look at the Cn3D home page or ftp site:
#
#http://www.ncbi.nlm.nih.gov/Structure/cn3d.html
#ftp://ftp.ncbi.nih.gov/cn3d/
#EOF

	case "$i" in
	entrez)
		cat > archive/$i/README.1st <<EOF
If you have not done so already, please refer to the
file at ftp://ftp.ncbi.nih.gov/entrez/README
EOF
		f="entrez entrez2 ../doc/firewall.html"		
		(cd ncbi/build; test -f Nentrez && ln -f Nentrez entrez)
		;;
	sequin)
		f="sequin"
		(cd ncbi/build; test -f Psequin && ln -f Psequin sequin)
		mkdir -p archive/sequin/errmsg archive/sequin/images
		test -d $errmsgdir && ln $errmsgdir/* archive/sequin/errmsg/
		test -d $sequinimages && ln $sequinimages/* archive/sequin/images/
		test -r $sequindoc && ln $sequindoc archive/sequin/
		#for file in $configfiles
		#do
		#	test -r $configdir/$file && ln $configdir/$file archive/sequin/config/
		#done
		;;
	asn2xml)
		f="asn2xml ../doc/README.asn2xml ../doc/ncbixml.txt"
		#no need in data subdir
		rm -rf archive/asn2xml/data
		;;
	fa2htgs)
		f="fa2htgs"
		;;
	*)
		;;
	esac
	for file in $f
	do
		if [ -f ./ncbi/build/$file ] ; then
			ln ./ncbi/build/$file ./archive/$i/
		else
			echo "$i: file $file was not built, skipping the archive"
			rm -fr ./archive/$i
		fi
	done
done

#cd back to archive
cd $TOPDIR/archive

case `uname -s` in
SunOS)
	case `uname -r` in
	4.1*)
		platform=sun
		;;
	*)
		if [ `uname -p` = i386 ] ; then
			platform=solarisintel
		else
			platform=solaris
			if [ "$SOLARIS_MODE" = "64" ] ; then
				platform=solaris64
			fi
		fi
		;;
	esac
	;;
IRIX*)
	case `uname -r` in
	4.*)
		platform=sgi4
		;;
	5.*)
		platform=sgi5
		;;
	6.5)
		#platform=sgi-mips4
		platform=sgi
		;;
	6.[0-4])
		platform=sgi
		;;
	*)
		platform=sgi
		;;
	esac
	;;
Linux)
	case `uname -m` in
	ppc)
		platform=ppclinux
		;;
	parisc)
		platform=hppalinux
		;;
	alpha)
		platform=linux-alpha
		;;
	x86_64)
		platform=linux-x86_64
		;;
	i?86)
		platform=linux-x86
		if [ "$LINUX_MODE" = "icc" ] ; then
			platform=linux-x86_icc
		fi
		;;
	ia64)
		platform=linux-ia64
		;;
	*)
		platform=linux
		;;
	esac
	;;
OSF1)
	platform=alphaOSF1
	;;
HP-UX)
	if [ `uname -m` = ia64 ] ; then
		platform=hpux_ia64
	else
		platform=hpux
	fi
	;;
QNX)
	platform=qnx
	;;
FreeBSD)
	platform=freebsd
	;;
Darwin)
	platform=darwin
	;;
NetBSD)
	platform=netbsd
	;;
AIX)
	platform=ibm_auto
	;;
*)
	platform="`uname -s`.`uname -m`"
	platform=`echo $platform|tr '[A-Z]' '[a-z]'|tr ' ' '_'`
	;;
esac

echo PLATFORM is $platform
pwd

for A in sequin entrez fa2htgs
do
	cd $A || continue
	#if [ $platform = "linux" ] ; then
	#	touch README.1st
	#fi

	if [ $platform = "solaris" ] ; then
		touch README.1st
		cat >>README.1st <<EOF
As of 5/29/1996, the Solaris executables distributed by NCBI no longer include
a statically-linked Motif library.  This is due to the manner in which
Sun distributes Motif libraries.  Users of Solaris version 2.4 and higher
will find the runtime shared Motif library on their system.  Users of Solaris
version 2.3 and earlier may need to either upgrade their systems or purchase
the Motif library separately.

It may be necessary to set your LD_LIBRARY_PATH environment variable to
point to the directory where this file, libXm.so.3 (the final digit may
vary), appears on your system.  E.g.
   setenv LD_LIBRARY_PATH /usr/dt/lib
EOF
	fi

	if [ $platform = "sun" ] ; then
		touch README.1st
		cat >>README.1st <<EOF
 ******************************************************************
 *          ! ! !   W A R N I N G   ! ! !                         *
 *                                                                *
 *  The NCBI Toolkit on                                           *
 *     Windows 16 bit                                             *
 *         and                                                    *
 *     SunOS 4.X platforms                                        *
 *                                                                *
 *     WILL NO LONGER BE SUPPORTED   after May 1, 1999            *
 *                                                                *
 ******************************************************************

EOF
	fi
	if [ $platform = "sgi5" ] ; then
		touch README.sgi5
		cat >>README.1st <<EOF
 *******************************************************************
 *          ! ! !   W A R N I N G   ! ! !                          *
 *                                                                 *
 *  The NCBI Toolkit binaries for IRIX5.X                          *
 *     WILL NO LONGER BE SUPPORTED AND BUILT after January 1, 2002 *
 *                                                                 *
 *******************************************************************

EOF
	fi
	#cd back to archive
	cd ..
done

for A in sequin entrez fa2htgs asn2xml
do
	cd $A || continue
	tar cf ../$A.$platform.tar .
	rm -f ../$A.$platform.tar.Z
	#compress < ../$A.$platform.tar > ../$A.$platform.tar.Z
	gzip < ../$A.$platform.tar > ../$A.$platform.tar.gz 2>/dev/null
	if [ $? != 0 ] ; then
		/usr/ncbi/bin/gzip < ../$A.$platform.tar > ../$A.$platform.tar.gz 2>/dev/null
	fi
	rm -f ../$A.$platform.tar
	# cd back to archive
	cd ..
	#and remove it
	rm -fr $A
done

echo Building blast archive...

BLASTDIR=blast-`cat ../ncbi/demo/.BLAST_VERSION`

mkdir $BLASTDIR
mkdir $BLASTDIR/bin
mkdir $BLASTDIR/data
mkdir $BLASTDIR/doc

for file in blastall blastpgp seedtop formatdb formatrpsdb fastacmd copymat makemat impala megablast blastclust rpsblast bl2seq 
do
cp ../ncbi/build/$file $BLASTDIR/bin
done

for file in $datafiles
do
cp ../ncbi/data/$file $BLASTDIR/data
done

for file in bl2seq.html blast.html blastall.html blastclust.html blastdb.html blastftp.html blastpgp.html fastacmd.html filter.html formatdb.html formatrpsdb.html history.html impala.html index.html megablast.html netblast.html rpsblast.html scoring.pdf web_blast.pl
do
cp ../ncbi/doc/blast/$file $BLASTDIR/doc
done

cp ../ncbi/VERSION $BLASTDIR

tar -cpf blast.$platform.tar $BLASTDIR
gzip blast.$platform.tar
rm -rf $BLASTDIR

# end build blast archive

echo Building netblast archive...

mkdir net$BLASTDIR
mkdir net$BLASTDIR/data
mkdir net$BLASTDIR/bin
mkdir net$BLASTDIR/doc

for file in $datafiles
do
cp ../ncbi/data/$file              net$BLASTDIR/data
done

cp ../ncbi/doc/firewall.html       net$BLASTDIR/doc
cp ../ncbi/doc/blast/netblast.html net$BLASTDIR/doc
cp ../ncbi/bin/blastcl3            net$BLASTDIR/bin
cp ../ncbi/VERSION                 net$BLASTDIR

tar -cpf netblast.$platform.tar    net$BLASTDIR
gzip netblast.$platform.tar
rm -rf net$BLASTDIR

echo Building wwwblast archive...

mkdir blast

cp -r ../ncbi/network/wwwblast/* blast 

find blast -type d -name CVS | xargs rm -rf
find blast -type d -name Src | xargs rm -rf

for file in psiblast.REAL psiblast_cs.REAL blast.REAL blast_cs.REAL wblast2.REAL wblast2_cs.REAL bl2bag.cgi nph-viewgif.cgi
do
cp ../ncbi/build/$file blast
done

mkdir -p blast/TmpGifs
chmod 777 blast/TmpGifs
chmod 666 blast/*.log

tar -cpf wwwblast.$platform.tar blast
gzip wwwblast.$platform.tar

rm -rf blast

exit 0
