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

set -e
FLAVOR=$1
PACKAGE=rabbit-mode

case $FLAVOR in
    emacs|*xemacs*|emacs21|emacs20|emacs19|mule2)
      exit 0
      ;;
    *)
      EMACSEN=$FLAVOR
      ;;
esac
echo install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}

FLAGS="-no-site-file -q -batch -l path.el -f batch-byte-compile"

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
ELCSTAMP=$ELCDIR/compile-stamp
if [ -f "$ELCSTAMP" ]; then
    echo "install/${PACKAGE}: already byte-compiled for $FLAVOR, skipped"
    exit 0
fi
echo "install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}" "$ELDIR"
if [ ! -d "$ELCDIR" ]; then
  install -m 755 -d "$ELCDIR"
fi
cd ${ELDIR}
FILES=`echo *.el`
for f in ${FILES} ; do
  [ -L ${ELCDIR}/$f ] && rm -f ${ELCDIR}/$f ;
  cp $f ${ELCDIR}/
done
cd "$ELCDIR"
cat << EOF > path.el
(setq load-path (cons "." load-path))
(setq byte-compile-warnings nil)
(require 'cl)
(require 'rd-mode)
EOF
${FLAVOR} ${FLAGS} ${FILES}
chmod 644 *.elc
rm -f *.el path.el path.elc
ELCFILES=`echo *.elc`
for f in ${ELCFILES} ; do
  ln -s ../../../emacs/site-lisp/${PACKAGE}/`basename $f .elc`.el .
done
touch "$ELCSTAMP"
exit 0
