#!/bin/sh -e
# $Id: tl-update-txi 37166 2015-05-03 18:06:32Z karl $
# Public domain.  Originally written 2008, Karl Berry.
# 
# From the Texinfo manuals in TeX Live, simplistically build html/pdf,
# install info/html/pdf.  Don't delete info files since they are in the
# dist's.  Unfortunately no easy way to do the same for pdf.

: ${CTAN=/home/ftp/tex-archive}

texihtml_top="-c TOP_NODE_UP_URL=http://tug.org/texinfohtml"
texihtml="makeinfo --html --no-split $texihtml_top"
texipdf="texi2pdf --quiet --clean"

# Convenience variables.
mydir=`dirname $0`
Master=`cd $mydir/../.. && pwd`
docdir=$Master/texmf-dist/doc
infodir=$docdir/info  

Build=`cd $Master/../Build && pwd`
xk=$Build/source/texk
xu=$Build/source/utils

# 
do_dvipng() {
  mypkg=dvipng
  cd $xk/$mypkg/doc || exit 1
  MV=cp mvcp-if-change $mypkg.info $infodir/
  $texihtml $mypkg.texi && mvcp-if-change $mypkg.html $docdir/$mypkg/
  $texipdf $mypkg.texi && mv -v $mypkg.pdf $docdir/$mypkg/
}

# 
do_dvips() {
  mypkg=dvips
  cd $xk/${mypkg}k || exit 1
  MV=cp mvcp-if-change $mypkg.info $infodir/
  $texihtml $mypkg.texi && mvcp-if-change $mypkg.html $docdir/$mypkg/
  if texi2dvi --quiet --clean $mypkg.texi; then
    # raw PostScript examples
    mainmap=$Master/texmf-dist/fonts/map/dvips/updmap/psfonts.map
    dvips -q -t letter -u $mainmap $mypkg.dvi
    /usr/bin/ps2pdf $mypkg.ps
    mv -v $mypkg.pdf $docdir/$mypkg/
    rm $mypkg.dvi $mypkg.ps
  fi
}

# 
do_kpathsea() {
  mypkg=kpathsea
  cd $xk/$mypkg/doc || exit 1
  MV=cp mvcp-if-change $mypkg.info $infodir/
  $texihtml $mypkg.texi && mvcp-if-change $mypkg.html $docdir/$mypkg/
  $texipdf $mypkg.texi && mv -v $mypkg.pdf $docdir/$mypkg/
}

# 
do_tlbuild() {
  mypkg=tlbuild
  cd $Build/source/doc || exit 1
  MV=cp mvcp-if-change $mypkg.info $infodir/
  $texihtml $mypkg.texi && mvcp-if-change $mypkg.html $docdir/texlive/$mypkg/
  $texipdf $mypkg.texi && mv -v $mypkg.pdf $docdir/texlive/$mypkg/
}

# 
do_web2c() {
  mypkg=web2c
  cd $xk/$mypkg/doc || exit 1
  MV=cp mvcp-if-change $mypkg.info $infodir/
  $texihtml $mypkg.texi && mvcp-if-change $mypkg.html $docdir/$mypkg/
  $texipdf $mypkg.texi && mv -v $mypkg.pdf $docdir/$mypkg/
}

do_dvipng
do_dvips
do_kpathsea
do_tlbuild
do_web2c
exit $?

# static: tds texdraw.
# done as part of package update:
#   asy[mptote] eplain fontname epspdf latex2e[-es] latex2man mf2pt1.
