#!/bin/sh -e
# /usr/lib/emacsen-common/packages/install/tm
# [ This particular script hasn't been much tested, so be careful. ]

FLAVOR=$1
echo "install/tm: Handling install of emacsen flavor ${FLAVOR}"

el_dir=/usr/share/emacs/site-lisp/tm
elc_dir=/usr/share/${FLAVOR}/site-lisp/tm
support_dir=${el_dir}/support

FLAGS="-no-site-file -q -batch -l ${support_dir}/fix-compile -f batch-byte-compile"
#FLAGS="-batch -l ${support_dir}/fix-compile -f batch-byte-compile"

case ${FLAVOR} in
emacs)
    echo "  nothing to do."
    exit 0
    ;;
xemacs*)
    echo "  under ${FLAVOR}'s administration - ignoring."
    exit 0
    ;;
esac

if test -x /usr/sbin/install-info-altdir; then
    echo install/tm: install Info links for ${FLAVOR}
    install-info-altdir --quiet --section "" "" --dirname=${FLAVOR} /usr/info/tm-en.info.gz
fi

if [ -r ${support_dir}/${FLAVOR}.lst ]
then
    echo "install/tm: byte-compiling for ${FLAVOR}"

    LOG=$(tempfile)

    # Copy the temp .el files
    mkdir -p ${elc_dir}
    ( cd ${el_dir} && cp $(cat ${support_dir}/${FLAVOR}.lst) ${elc_dir} )

    # Byte compile them
    cd ${elc_dir}
    ${FLAVOR} ${FLAGS} *.el >> $LOG 2>&1

    # remove the redundant .el files
    # presumes that any .el files in the <flavor> dir are trash.
    rm -f *.el

    mv $LOG ${elc_dir}/install.log
    echo "install/tm: compilation log for ${FLAVOR} saved to ${elc_dir}/install.log"
else
    echo "WARNING install/tm: don't know what to byte-compile for ${FLAVOR}"
    echo "Please get in touch with <dirson@debian.org> to add ${FLAVOR} support"
fi

exit 0

