#! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/proofgeneral

# Written by Jim Van Zandt <jrv@debian.org>, borrowing heavily
# from the install scripts for gettext by Santiago Vila
# <sanvila@ctv.es> and octave by Dirk Eddelbuettel <edd@debian.org>.

FLAVOR=$1
PACKAGE=proofgeneral

if [ ${FLAVOR} != emacs23 ]; then exit 0; fi

echo install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}

PG_SUBDIRS="generic lib coq"

#FLAVORTEST=`echo $FLAVOR | cut -c-6`
#if [ ${FLAVORTEST} = xemacs ] ; then
#    SITEFLAG="-no-site-file"
#else
    SITEFLAG="--no-site-file"
#fi
FLAGS="${SITEFLAG} -q -batch -l path.el -f batch-byte-compile"

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}

install -m 755 -d ${ELCDIR}
cd ${ELDIR}
ALLFILES=
for d in ${PG_SUBDIRS} ; do
    install -m 755 -d ${ELCDIR}/${d}
    FILES=`echo ${d}/*el`
    ALLFILES="${ALLFILES} ${FILES}"
    cp ${FILES} ${ELCDIR}/${d}
done

cd ${ELCDIR}
cat << EOF > path.el
(require (quote bytecomp))
(setq load-path
      (append (list 
EOF

for d in ${PG_SUBDIRS} ; do
    echo "\"${ELCDIR}/${d}\"" >> path.el
done

cat << EOF >> path.el
)
              load-path))
(setq byte-compile-warnings nil)
(setq byte-compile-warnings 
      (remove 
       (quote cl-functions)
       (remove (quote noruntime) byte-compile-warning-types)))
(setq byte-compile-error-on-warn t)
EOF
${FLAVOR} ${FLAGS} ${ALLFILES}

rm -f path.el
for d in ${PG_SUBDIRS} ; do
    rm -f ${d}/*el
done

# I don't know why, but generic/proof-autoloads.el is not compiled. 
# I therefore keep the .el file.
cd ${ELDIR}
cp generic/proof-autoloads.el ${ELCDIR}/generic

# The path for images, proof-images-directory, is determinded at the
# time when generic/proof-site.el is loaded, see there. The simplest
# solution to ensure that Proof General finds the images is to copy
# them.
cp -a images ${ELCDIR}/images

exit 0
