#!/bin/sh
# /usr/lib/emacsen-common/packages/install/bitmap-mule
set -e

FLAVOR=$1
PACKAGE="bitmap-mule"
VERSION=8.5+0.20030825.0433-10

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"

#COMPILED=no
case "${FLAVOR}" in
  *xemacs*)
    ;;
  *)
    echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."
    STAMP="${ELCDIR}/compile-stamp"
    if [ -e "${STAMP}" ]; then
      if [ "X${VERSION}" = X"`cat ${STAMP}`" ]; then
	echo " skipped. (already compiled)" 
      else
	rm -f ${STAMP}
      fi
    fi
    if [ ! -e "${STAMP}" ]; then
      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
	cd ${ELDIR}
	for f in *.el; do
	  if [ -f ${ELCDIR}/${f}c ]; then
	    ln -sf ${ELDIR}/${f} ${ELCDIR}/${f}
	  fi
	done
	case "${FLAVOR}" in
	  emacs21|emacs20)
	    ;;
	  *)
	    # po.el conflicts with Emacs' lisp/textmodes/po.el 
	    rm -f ${ELCDIR}/po.el*
	    ;;
        esac
      )
      gzip -9 ${ELCDIR}/CompilationLog
      chmod 644 ${ELCDIR}/CompilationLog.gz
      if [ -f ${ELCDIR}/bitmap.elc ]; then
	chmod 644 ${ELCDIR}/*.elc
	echo "${VERSION}" > ${STAMP}
	chmod 644 ${STAMP}
	#COMPILED=yes
      fi
      echo " done."
    fi
    ;;
esac

exit 0
