#!/bin/sh
set -e

FLAVOR=$1
PACKAGE="bitmap-mule"

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

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

EFLAGS="-batch -q -no-site-file -l BITMAP-MK.tmp"

case "${FLAVOR}" in
  xemacs*)
    ;;
  *)
    echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."
    rm -rf ${ELCDIR}
    install -m 755 -d ${ELCDIR}

    cp ${ELDIR}/* ${ELCDIR}/
    cp ${PIXMAPS_DIR}/*.xbm ${ELCDIR}/

    (cd ${ELCDIR}
      cat << EOF > BITMAP-MK.tmp
(setq load-path (cons "/usr/share/${FLAVOR}/site-lisp/apel" load-path))
EOF
      cat BITMAP-MK >> BITMAP-MK.tmp
      make EMACS=${FLAVOR} LISPDIR=${SITELISP} FLAGS="${EFLAGS}" > CompilationLog 2>&1
      rm -f BITMAP-* *.el Makefile *.xbm
    )
    gzip -9 ${ELCDIR}/CompilationLog
    chmod 644 ${ELCDIR}/CompilationLog.gz
    echo " done."
    ;;
esac

