#! /bin/sh
# /usr/lib/emacsen-common/packages/install/rail

set -e 


FLAVOR=$1
PACKAGE=rail

if [ ! -f "/usr/share/$FLAVOR/site-lisp/flim/mime-def.elc" ]; then 
  exit 0
fi

case $FLAVOR in
    emacs|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 -l ./make.el"

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}
${FLAVOR} ${FLAGS} -f compile-rail
rm -f *.el path.el
ELCFILES=`echo *.elc`
for f in ${ELCFILES} ; do 
  ln -s ../../../emacs/site-lisp/rail/`basename $f .elc`.el . 
done

exit 0
