#! /bin/sh
set -e

FLAVOR=$1
PACKAGE="iiimecf"

if [ "X${FLAVOR}" = "X" ]; then
  echo Need argument to determin FLAVOR of emacsen
  exit 1
fi
if [ "X${PACKAGE}" = "X" ]; then
  echo Internal error: need package nameen
  exit 1
fi
if [ "X${FLAVOR}" = Xemacs ]; then exit 0; fi
if [ "X${FLAVOR}" = Xemacs19 ]; then exit 0; fi
if [ "X${FLAVOR}" = Xmule2 ]; then exit 0; fi

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

case "${FLAVOR}" in
  xemacs*)
    ;;
  *)
    echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."
    rm -rf ${ELCDIR}
    install -m 755 -d ${ELCDIR}/tmp
    (cd ${ELCDIR}/tmp
      cp -r ${ELDIR}/* ${ELCDIR}/tmp
      ${FLAVOR} -q -no-site-file -batch -l iiimcf-comp.el > ${ELCDIR}/CompilationLog 2>&1
      mv ${ELCDIR}/tmp/lisp/*.elc ${ELCDIR}/
      cd ${ELCDIR}
      rm -fr ${ELCDIR}/tmp
    )
    gzip -9 ${ELCDIR}/CompilationLog
    chmod 644 ${ELCDIR}/CompilationLog.gz
    echo " done."
    ;;
esac

exit 0
