#!/bin/sh 
set -e
FILES="haml-mode.el sass-mode.el"

FLAVOR="$1"

if [ "${FLAVOR}" = "emacs21" ];then
    echo "Skipping byte-compilation for emacs21: Not supported"
    exit 0;
fi

echo "install/haml-elisp: Handling install of emacsen flavor ${FLAVOR}"

if [ "${FLAVOR}" != "emacs" ]; then
  echo "install/haml-elisp: byte-compiling for ${FLAVOR}"
  cd /usr/share/emacs/site-lisp/haml-elisp
  mkdir -p /usr/share/${FLAVOR}/site-lisp/haml-elisp
  cp $FILES /usr/share/${FLAVOR}/site-lisp/haml-elisp
  cd /usr/share/${FLAVOR}/site-lisp/haml-elisp
  cat <<EOF > path.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
EOF
  FLAVORTEST=`echo $FLAVOR | cut -c-6`
  if [ ${FLAVORTEST} = xemacs ] ; then
    SITEFLAG="-no-site-file"
  else
    SITEFLAG="--no-site-file"
  fi
  ${FLAVOR} -q ${SITEFLAG} -batch -l path.el -f batch-byte-compile $FILES
  rm path.el $FILES
fi

exit 0;

