#!/bin/sh
#W  make_doc						     Alexander Hulpke
##
##  This shell script constructs the (La)TeX .dvi, .ps, and .pdf formats and
##  the HTML format versions of the GAP manuals, which currently includes:
##    ext, prg, ref, tut, new (main GAP manuals) and
##    ctbllib, gapdoc         (GAP package manuals)
##
echo "Cleaning main manual auxiliary files"

rm -f {ref,tut,prg,ext,new}/manual.{toc,lab,ind,dvi,log,ps,pdf}

# ensure that .tex files built from .msk files are re-generated
# ... in case there have been changes to .gd files etc.
rm -f build/._*

echo "Building main manual .tex files from .msk files"
(cd build;make -k)

echo "Creating main manual .toc, .bbl, .ind, .six and .lab files"
# tex all manuals and build their bibliography and index information
(cd ext; tex manual >& /dev/null;bibtex manual;../manualindex manual;tex manual >& /dev/null;../manualindex manual)
(cd prg; tex manual >& /dev/null;bibtex manual;../manualindex manual;tex manual >& /dev/null;../manualindex manual)
(cd ref; tex manual >& /dev/null;bibtex manual;../manualindex manual;tex manual >& /dev/null;../manualindex manual)
(cd tut; tex manual >& /dev/null;bibtex manual;../manualindex manual;tex manual >& /dev/null;../manualindex manual)
(cd new; tex manual >& /dev/null;bibtex manual;../manualindex manual;tex manual >& /dev/null;../manualindex manual)

# two further tex runs to get the indices in and in the TOC.
(cd ref; tex manual)
(cd tut; tex manual)
(cd ext; tex manual)
(cd prg; tex manual)
(cd new; tex manual)

#####################################################################

echo "Creating main manual .pdf files"
# pdftex all manuals to create pdf versions (need to run twice to set
# crossrefs properly)
(cd ref; pdftex manual >& /dev/null; pdftex manual)
(cd tut; pdftex manual >& /dev/null; pdftex manual)
(cd ext; pdftex manual >& /dev/null; pdftex manual)
(cd prg; pdftex manual >& /dev/null; pdftex manual)
(cd new; pdftex manual >& /dev/null; pdftex manual)
#echo "Creating CTblLib .pdf manual"
# ctbllib           # ctbllib's make doesn't include making .pdf format
#(cd ../pkg/ctbllib/doc; pdftex manual; pdftex manual)

echo "Creating main manual comprehensive index: .dvi, .ps and .pdf versions"
./allmanualsindex
tex fullindex
pdftex fullindex

echo "Creating main manual HTML documentation (inc. comprehensive index)"
# the main manuals + the comprehensive index
(cd htm; make clean; make)
