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

# 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=icicles
STAMPFILE=lacarte.elc
LOG=$(tempfile -pelc_ -s.log -m644)

case ${FLAVOR} in
  emacs|emacs21|xemacs*) exit 0 ;;
esac

if test -e "${ELCDIR}/${STAMPFILE}"; then
    echo "${PACKAGE} files already compiled in ${ELCDIR}."
    rm -f ${LOG}
    exit
fi
echo "install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}, logged in ${LOG}"

FLAVORTEST=$(echo $FLAVOR | cut -c-6)
SITEFLAG="--no-site-file"
FILES="/usr/share/emacs/site-lisp/${PACKAGE}/*.el"

ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
install -m 755 -d ${ELCDIR}
for file in ${FILES} ; do
  ln -sf ${file} ${ELCDIR}/
done

FLAGS="${SITEFLAG} -q -batch -l path.el -f batch-byte-compile"

cd ${ELCDIR}
cat << EOF > path.el
(setq load-path (cons "." load-path))
(setq byte-compile-warnings nil)
EOF

echo ${FLAVOR} ${FLAGS} *.el > ${LOG}
${FLAVOR} ${FLAGS} *.el >> ${LOG} 2>& 1
egrep -s -e "While compiling|\*\*" ${LOG} || /bin/true
echo install/${PACKAGE}: Deleting ${LOG}
rm -f path.el*

exit 0
