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

set -e

FLAVOR=$1
PACKAGE="bitmap-mule"

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}
SITELISP=/usr/share/${FLAVOR}/site-lisp

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

case "${FLAVOR}" in
	emacs)
	;;
	emacs2*|mule2)

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

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

    # Copy the temp .el files
    cp ${ELDIR}/* ${ELCDIR}/

    (cd ${ELCDIR}
cat << EOF > BITMAP-MK.comp
(setq load-path (cons (concat "/usr/share/${FLAVOR}/site-lisp/apel") load-path))
EOF
    cat BITMAP-MK >> BITMAP-MK.comp

        make EMACS=${FLAVOR} LISPDIR=${SITELISP} FLAGS="${EFLAGS}" > CompilationLog 2>&1
	rm -f BITMAP-* *.el Makefile
	)

	gzip -9 ${ELCDIR}/CompilationLog
	
	echo " done."
	;;
    *)
    ;;
esac

