#! /bin/sh

# This script should be run by executing
#   make DOC
# or
#   make HTML
# from the main ACL2 directory.  The environment variable ACL2 is used
# in this script; it is typically set in ../GNUmakefile.

# It is our convention to keep the .fig and .gif files in graphics/
# (under the main ACL2 source directory), but only in the development
# directory at UT (not distributed with releases).  As part of this
# creation, we copy the *.gif files from that source to the doc/HTML
# subdirectory where they will reside for convenient HTML access.  We
# delete the copies on doc/HTML every time we rebuild, because the
# definitive copies are in graphics/.

rm -f doc/HTML/*.gif

# The next two non-blank lines should be commented out if we don't want to
# destroy the preceding version.

rm -rf doc/HTML-old
mv -f doc/HTML doc/HTML-old
mkdir doc/HTML
chmod 775 doc/HTML

# Now copy the definitive .gif files over to doc/HTML.

cp -p graphics/*.gif doc/HTML

# Copy the license down to the doc/HTML so the home page can reference it.

cp LICENSE doc/HTML/LICENSE

# Copy down the files we are allowed to change without rebuilding.
cp new.html doc/HTML/new.html
mkdir doc/HTML/installation
cp installation/installation.html doc/HTML/installation/
cp installation/misc.html doc/HTML/installation/
cp installation/obtaining-and-installing.html doc/HTML/installation/
cp installation/requirements.html doc/HTML/installation/
cp installation/using.html doc/HTML/installation/
cp installation/windows7.html doc/HTML/installation/
cp installation/windows-gcl-jared.html doc/HTML/installation/
cp installation/installing-make.html doc/HTML/installation/

cp other-releases.html doc/HTML/other-releases.html
cp workshops.html doc/HTML/workshops.html

# Ok, now we are ready!

cd doc/HTML

# 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)' > workxxx
echo '(lp)' >> workxxx

echo '(certify-book "../write-acl2-html")' >> workxxx

if [ "${ACL2_DOC_UNDOCUMENTED_FILE}" != "" ] ; then \
    (echo '(write-html-file :file "acl2-doc" :undocumented-file t)' >> workxxx) ; \
else \
    (echo '(write-html-file :file "acl2-doc")' >> workxxx) ; \
fi

echo ':q' >> workxxx

${ACL2} < workxxx

rm -f workxxx

# Make all files world-readable.

chmod a+r *

# To debug bad documentation:
# cd /projects/acl2/v2-9/doc/HTML
# ../../large-saved_acl2
# (certify-book "/projects/acl2/v2-9/doc/write-acl2-html")
# or if it hasn't been changed since it was certified, just
# (include-book "/projects/acl2/v2-9/doc/write-acl2-html")
# Redefine whatever you need in the image, e.g., *home-page*.
# Apply DEFDOC to fix bad documentation.
# (write-html-file :file "acl2-doc")
