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

set -e

FLAVOR=$1
VERSION="0.6"
PACKAGE="IIIMECF"

if [ "X${FLAVOR}" = "X" ]; then
    echo Need argument to determin FLAVOR of emacs;
    exit 1
fi

if [ "X${PACKAGE}" = "X" ]; then
    echo Internal error: need package name;
    exit 1;
fi

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

if [ ! -x "$ELCDIR" ] ; then
    mkdir -p "$ELCDIR"
fi

STARTDIR=/etc/${FLAVOR}/site-start.d
STARTFILE="${PACKAGE}-init.el";

SITELISP=/usr/share/${FLAVOR}/site-lisp

STAMP=${ELCDIR}/compile-stamp
case "${FLAVOR}" in
       emacs)
       ;;
       # emacs20|emacs21|xemacs21)
       *)

       echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."

    if [ -e ${STAMP} ]; then
        if [ "${VERSION}" = "`cat ${STAMP}`" ]; then
            echo " exited. (already compiled)" 
            exit
        else
            rm -f ${STAMP}
        fi
    fi
       echo
       echo -n "This will take a while ..."

       rm -rf ${ELCDIR}
    install -m 755 -d ${ELCDIR}

    # Byte compile them
       if [ "${FLAVOR}" = "xemacs-21.4.6" ];then
               # only IIIMECF
               (cd ${ELDIR}
                       ${FLAVOR} -q --no-site-file -batch -l iiimcf-comp.el > \
                               ${ELCDIR}/CompilationLog 2>&1
               )
               mv ${ELDIR}/lisp/*.elc ${ELCDIR}/
       elif [ "${FLAVOR}" = "xemacs-21.4.8" ];then
               # only IIIMECF
               (cd ${ELDIR}
                       ${FLAVOR} -q --no-site-file -batch -l iiimcf-comp.el > \
                               ${ELCDIR}/CompilationLog 2>&1
               )
               mv ${ELDIR}/lisp/*.elc ${ELCDIR}/
       else
               (cd ${ELDIR}
                       ${FLAVOR} -q --no-site-file -batch -l iiimcf-comp.el > \
                               ${ELCDIR}/CompilationLog 2>&1
               )
               mv ${ELDIR}/lisp/*.elc ${ELCDIR}/
       fi
               
               gzip -9 ${ELCDIR}/CompilationLog
               echo ${VERSION} > ${STAMP}

               #cp ${ELDIR}/${STARTFILE} ${STARTDIR}/40${STARTFILE};
               
               echo " done."
               ;;
    *)
               ;;
esac

exit 0;

