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

# Written by Jim Van Zandt <jrv@vanzandt.mv.com>, 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=emms

if [ ${FLAVOR} = xemacs21 ] || \
       [ ${FLAVOR} = emacs21 ] || \
       [ ${FLAVOR} = emacs22 ] || \
       [ ${FLAVOR} = emacs23 ] || \
       [ ${FLAVOR} = emacs24 ]; then
    echo "install/${PACKAGE}: skipping unsupported ${FLAVOR}"
    exit 0
fi

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
FLAGS="${SITEFLAG} -q -batch -l path.el -f batch-byte-compile"

echo "install/${PACKAGE}: byte-compiling for ${FLAVOR}"

install -m 755 -d ${ELCDIR}
cd ${ELCDIR}
# Handle 'emacs' flavor where .elc will be in the same directory as .el
if [ ${ELDIR} != ${ELCDIR} ]; then
    ln -sf ${ELDIR}/* .
fi

cat << EOF > path.el
(setq load-path (cons "." load-path))
EOF

${FLAVOR} ${FLAGS} *.el > install.log 2>&1
if [ $? -ne 0 ]; then
    cat install.log
    exit 1
fi
gzip -9f install.log
rm -f path.el path.elc

exit 0
