#
# This is a strictly POSIX 1003.2 shell (Bourne shell) script 
# providing the addition of LaTeX/AMSTeX to the TeX Kernel system: 
# kerTeX.
#
# No shebang, since there is a bootstrapping problem: this script has
# to run on whatever host the kerTeX system runs on.
# It has to be invoked with whatever Bourne shell like interpreter is
# present on the host.
#
# C) 2012 Thierry Laronde <tlaronde@polynum.com>
# All rights reserved and absolutely no warranty! Use at your own 
# risks.
#

# Needed post action (build, apply, remove) routines.
#
pkg_post_build()
{
	return 0 # bash errors on empty function...
}

pkg_post_apply()
{
	pkg_log 
	pkg_log "The technical documentation has not been built since"
	pkg_log "amsclass.dtx has an error when run with LaTeX."
	pkg_log 
}

pkg_post_remove()
{
	return 0 # bash errors on empty function...
}

#==================== AUTOMATIC PROCESSING
# First include the pecularities of the TeX kernel system host.
#
. which_kertex

# Then we now how to find the library that defines routines and does
# some checks, argument processing and initializations. See the file
# directly for explanations.
#
. $KERTEX_BINDIR/lib/pkglib.sh

#==================== CUSTOM PROCESSING: we are in TMPDIR
#
#
pkg_log "Building the list of files to download. Please wait..."
pkg_get

# We get only the sources, and generate the *.sty and *.cls from them.
# We retrieve the doc in pdf, since there is at least one file with
# an error amsclass.dtx.
# 
# Since there are interdependencies between the 3 chunks, we will leave
# the sources in subdirs (but refs is the same as cls), but put
# *.sty and *.cls in the ams/ root dir
#
cd $TMPDIR/lib/$PKG_NAME
KERTEXINPUTS="cls/;math/;KERTEXSYS"
export KERTEXINPUTS
for file in cls/*.ins math/*.ins; do
  $KERTEX_BINDIR/latex $file
done
rm -f *.log cls/*.log math/*.log

#===== CUSTOM PROCESSING FINISHED
#
# Time to do whether the build or the install.
#
pkg_do_action

# not reached
exit 0

# Since we have exited above, no need to comment out the CID.

BEGIN_CID
NAME: latex/ams
VERSION: 2.20
KERTEX_VERSION: 0.9999.4.0
KXPATH:
	latex ams
	bibtex ams
SOURCES:
ftp://anonymous:kertex@ftp.ams.org/
	LCD HOME/cls/
	GET /pub/tex/amslatex/classes/ /.txt$/
	GET ./ /\.ins$/
	GET ./ /\.template$/
	GET ./ /\.dtx$/
	GET ./ /\.tex$/
	LCD HOME/doc
	GET ./ /\.pdf$/
	LCD /lib/bibtex/ams/
	GET ./ /\.bst$/
	LCD HOME/cls/
	GET ../amsrefs/amsrefs/ /.txt$/
	GET ./ /\.ins$/
	GET ./ /\.dtx$/
	GET ./ /\.tex$/
	LCD HOME/doc
	GET ./ /\.pdf$/
	LCD HOME/math/
	GET ../../math/ /.txt$/
	GET ./ /\.ins$/
	GET ./ /\.dtx$/
	GET ./ /\.tex$/
	LCD HOME/doc
	GET ./ /\.pdf$/
END:
END_CID

