#! /bin/sh
# A. Flatau  9-Jul-1993; modified by M. Kaufmann, 26-Oct-1993, also 8/94 and 10/94, etc.
#

# This script should be run by executing
#   make DOC
# or
#   make TEXINFO
# from the main ACL2 directory.  The make variable PREFIX is used in this script.

rm -f doc/workxxx

# The following lines should be commented out if we don't want to
# destroy what's in the saved/ subdirectories.  (As they currently stand,
# we have already arranged not to save doc/TEX.)

rm -rf doc/EMACS-old
## rm -rf doc/LEMACS-old
# rm -rf doc/TEX-old

mv -f doc/EMACS doc/EMACS-old
## mv -f doc/LEMACS doc/LEMACS-old

# mv -f doc/TEX doc/TEX-old
rm -rf doc/TEX

# Now that directories have been moved, re-create them.

mkdir doc/EMACS
## mkdir doc/LEMACS
mkdir doc/TEX
chmod 775 doc/EMACS
## chmod 775 doc/LEMACS
chmod 775 doc/TEX

# Some ACL2 images start up inside LP; some don't.  (value :q) always gets us
# out of the loop, and should also be harmless when executed in raw Lisp.
# However, note that Lispworks requires that the two forms not all be on the
# same line.

echo '(value :q)' > doc/workxxx
echo '(lp)' >> doc/workxxx

echo '(certify-book "doc/write-acl2-texinfo")' >> doc/workxxx

echo '(write-texinfo-file :dir-string "doc/EMACS/" :file "acl2-doc-emacs" :tex-only-flg nil :non-lucid-flg t)' >> doc/workxxx

## echo '(write-texinfo-file :dir-string "doc/LEMACS/" :file "acl2-doc-lemacs" :tex-only-flg nil)' >> doc/workxxx

echo '(write-tex-file :dir-string "doc/TEX/" :file "acl2-book")' >> doc/workxxx

echo ':q' >> doc/workxxx

${PREFIX}saved_acl2 < doc/workxxx

emacs -batch "doc/EMACS/acl2-doc-emacs.texinfo" -l "../make-texinfo.el" -f texinfo-format-buffer-and-save

## emacs -batch "doc/LEMACS/acl2-doc-lemacs.texinfo" -l "../make-texinfo.el" -f texinfo-format-buffer-and-save

cd doc/TEX

cp ../texinfo.tex .
texi2dvi acl2-book.tex

# We do it again because otherwise some index entries are wrong.

texi2dvi acl2-book.tex

dvips acl2-book.dvi -o acl2-book.ps

gzip acl2-book.dvi
gzip acl2-book.ps

# Make all files world-readable after changing back to doc/.

cd ..

chmod a+r EMACS/*
## chmod a+r LEMACS/*
chmod a+r TEX/*

# To debug bad documentation:
# Start up ACL2 in the source directory.
# (include-book "doc/write-acl2-texinfo")
# Apply DEFDOC to fix bad documentation.
# (write-texinfo-file :dir-string "doc/EMACS/" :file "acl2-doc-emacs" :tex-only-flg nil :non-lucid-flg t)
# One can write others too:
#
## # (write-texinfo-file :dir-string "doc/LEMACS/" :file "acl2-doc-lemacs" :tex-only-flg nil)
# (write-tex-file :dir-string "doc/TEX/" :file "acl2-book")
