#
# This is a strictly POSIX 1003.2 shell (Bourne shell) script 
# sketching the addition of LaTeX/babel 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) 2013 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()
{
	return 0 # bash errors on empty function...
}

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_get

# Unzipping and docstripping. We do the minimal.
# The missing carlisle/scalefnt.sty as been put in latex/.
#
# The zipped files expand relative to ./base/ and ./babel-contrib/. 
# We move in the PKG subdirectory and will set KXPATH later.
#
cd $TMPDIR # we should be here
$PKG_UNZIP base.zip
mv base/* $TMPDIR/lib/$PKG_NAME
rm base.zip

# The contrib files will be put in a contrib/ subdir (added to KXPATH).
# We only copy 
#
mkdir $TMPDIR/lib/$PKG_NAME/contrib
$PKG_UNZIP contrib.zip

# Some exceptions have not only $language.dtx but others. See below.
# Almost all have ins and dtx. Some sty, and some (hebrew and greek) 
# fdd.
#
# Serbianc has only one file for date.
#
for language in\
  albanian\
  bahasa\
  basque\
  breton\
  bulgarian\
  catalan\
  croatian\
  czech\
  danish\
  dutch\
  english\
  esperanto\
  estonian\
  finnish\
  frenchb\
  friulan\
  galician\
  german\
  greek\
  hebrew\
  icelandic\
  interlingua\
  irish\
  italian\
  kurmanji\
  latin\
  norsk\
  piedmontese\
  polish\
  portuges\
  romanian\
  romansh\
  russian\
  samin\
  scottish\
  serbian\
  serbian-date-lat\
  slovak\
  slovene\
  sorbian\
  spanish\
  swedish\
  turkish\
  ukraineb\
  welsh; do
  for suffix in dtx ins ldf sty fdd; do
    if test -f babel-contrib/$language/$language.$suffix; then
      mv babel-contrib/$language/$language.$suffix\
        $TMPDIR/lib/$PKG_NAME/contrib/
    fi
  done
done

# Some exceptions have not only $language.dtx but others.
#
for file in\
  bahasa/bahasam.dtx\
  german/germanb.dtx german/ngermanb.dtx\
  greek/athnum.dtx greek/grsymb.dtx greek/grmath.dtx\
  hebrew/heb209.dtx hebrew/hebinp.dtx\
  russian/russianb\
  sorbian/lsorbian.dtx sorbian/usorbian.dtx; do
  if test -f babel-contrib/$file; then
    mv babel-contrib/$file $TMPDIR/lib/$PKG_NAME/contrib/
  fi
done

# Serbianc exception:
#
for suffix in dtx ins ldf sty fdd; do
  if test -f babel-contrib/serbianc/tex/generic/serbianc/serbianc.$suffix;then 
    mv babel-contrib/serbianc/tex/generic/serbianc/serbianc.$suffix\
      $TMPDIR/lib/$PKG_NAME/contrib/
  fi
done

rm contrib.zip

pkg_log "Generating files from babel.ins"
cd $TMPDIR/lib/$PKG_NAME
# We will set KXPATH so we let the files here.
#
$KERTEX_BINDIR/latex babel.ins

pkg_log "Generating files for contrib packages"
cd contrib/
# We will set KXPATH so we let the files here.
#
for package in *.ins; do
  $KERTEX_BINDIR/latex $package
done


#===== 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/babel
VERSION: 3.8
LICENCE: LaTeX Project Public Licence for Babel base. GPL for some
contrib (see on CTAN for details when the licence is mentioned, which
is not generally the case).
	http://www.latex-project.org/lppl.txt
KERTEX_VERSION: 0.999.7.6
DESCRIPTION:
The Babel system supports multilingual typesetting.
NOTES:
frenchb depends on scalefnt.sty not provided by base or babel.
KXPATH:
	latex babel;babel/contrib
SOURCES:
ftp://anonymous:kertex@ftp.ctan.org/
	GET /tex-archive/macros/latex/required/babel/base.zip
	GET /tex-archive/macros/latex/required/babel/contrib.zip
	LCD HOME/..
	GET /tex-archive/macros/latex/contrib/carlisle/scalefnt.sty
END:
END_CID

