#! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/lookup-el

# Written by Jim Van Zandt <jrv@vanzandt.mv.com>, borrowing heavily
# from the install scripts for gettext by Santiago Vila
# <sanvila@ctv.es> and octave by Dirk Eddelbuettel <edd@debian.org>.

FLAVOR=$1
PACKAGE=lookup-el
VERSION=1.1
LOG=`tempfile`

if [ ${FLAVOR} = emacs ]; then exit 0; fi

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

FLAVORTEST=`echo $FLAVOR | cut -c-6`
if [ ${FLAVORTEST} = xemacs ] ; then
    SITEFLAG="-no-site-file"
else
    SITEFLAG="--no-site-file"
fi
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}

case "$FLAVOR" in
    emacs20|xemacs20|xemacs21 )
    install -m 755 -d ${ELCDIR}
    cd ${ELDIR}
    sed -e s/\@VERSION\@/${VERSION}/  -e s!\@pkgemacsdir\@!${ELCDIR}!  lookup-vars.el.in > lookup-vars.el
    FILES=`echo *.el`
    cp ${FILES} ${ELCDIR}
    cd ${ELCDIR}
    echo '(setq load-path (cons "." load-path) byte-compile-warnings nil)' > path.el
    ${FLAVOR} ${FLAGS} ${FILES} > $LOG 2>&1
    mv $LOG ${ELCDIR}/install.log 
    rm -f *.el path.el
    rm ${ELDIR}/lookup-vars.el
    ;;
    *) echo "install/$PACKAGE: Ignoring emacsen flavor $FLAVOR."
    ;;
esac

exit 0 ;
