#!/bin/sh -e

FILES="mmm-auto.el mmm-class.el mmm-cmds.el mmm-compat.el mmm-cweb.el mmm-defaults.el mmm-erb.el mmm-mason.el mmm-mode.el mmm-myghty.el mmm-noweb.el mmm-region.el mmm-rpm.el mmm-sample.el mmm-univ.el mmm-utils.el mmm-vars.el"

FLAVOR="$1"
FLAVORTEST=`echo $FLAVOR | cut -c-6`

if [ "$FLAVORTEST" = "xemacs" ]; then
    echo "Sorry, XEmacs is no longer supported."
    exit 0
fi

echo "install/mmm-mode: Handling install of emacsen flavor ${FLAVOR}"

# e25 makes things stale and unflavoured, just emacs and source dir == compile dir
# before that flavours emacs24, xemacs21 etc.
echo "install/mmm-mode: byte-compiling for ${FLAVOR}"
mkdir -p /usr/share/${FLAVOR}/site-lisp/mmm-mode

for i in $FILES; do
		if [ ! -f /usr/share/${FLAVOR}/site-lisp/mmm-mode/$i ]; then
				ln -s /usr/share/emacs/site-lisp/mmm-mode/$i /usr/share/${FLAVOR}/site-lisp/mmm-mode
		fi
done

	
cd /usr/share/${FLAVOR}/site-lisp/mmm-mode
cat <<EOF > path.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
EOF
SITEFLAG="--no-site-file"
${FLAVOR} -q ${SITEFLAG} -batch -l path.el -f batch-byte-compile $FILES
rm -f path.el

exit 0;
