#! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/evernote-mode

FLAVOR=$1
PACKAGE=evernote-mode

# don't support older FSF emacs, XEmacs.
case $FLAVOR in
    emacs|emacs22|emacs21|emacs20|emacs19|mule2|*xemacs*)
    exit 0
    ;;
esac

echo "install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}"

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

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

install -m 755 -d ${ELCDIR}
cd ${ELDIR}
FILES=`echo *.el`
for f in ${FILES} ; do
  [ -L ${ELCDIR}/$f ] && rm -f ${ELCDIR}/$f ;
  cp $f ${ELCDIR}
done
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
ELCFILES=`echo *.elc`
for f in ${ELCFILES} ; do 
  ln -s ../../../emacs/site-lisp/${PACKAGE}/`basename $f .elc`.el . 
done

exit 0
