#!/bin/sh -e

FLAVOR=$1
PACKAGE=bongo

# Bongo supports emacs21, emacs22 and emacs-snapshot.
case ${FLAVOR} in
    emacs20|xemacs21)
	echo "install/${PACKAGE}: ${FLAVOR} isn't supported, skipping"
	exit 0
	;;
    emacs21|emacs22|emacs-snapshot)
	echo "install/${PACKAGE}: Handling installation for ${FLAVOR}"
	;;
    *)
	echo "install/$PACKAGE: Ignoring emacsen flavor $FLAVOR"
	exit 0
	;;
esac

FLAGS="-q -no-site-file --no-site-file -batch -l path.el -f batch-byte-compile"

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

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

case ${FLAVOR} in
    emacs21)
	FILES=`ls *.el`
	;;
    emacs22|emacs-snapshot)
	FILES=`ls *.el | grep -v bongo-emacs21`
	;;
    *)
	;;
esac

cp ${FILES} ${ELCDIR}
cd ${ELCDIR}

cat << EOF > path.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
EOF

${FLAVOR} ${FLAGS} ${FILES}
rm -f *.el path.el

for f in ${ELDIR}/*.pbm; do
    ln -sf $f
done

for f in ${FILES}; do
    ln -sf ${ELDIR}/$f
done

exit 0
