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

# 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=semantic

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"

# Install-info-altdir does not actually exist. 
# Maybe somebody will write it.
if test -x /usr/sbin/install-info-altdir; then
    echo install/${PACKAGE}: install Info links for ${FLAVOR}
    install-info-altdir --quiet --section "" "" --dirname=${FLAVOR} /usr/share/info/${PACKAGE}.info.gz
fi

ELPREFIX=/usr/share/emacs/site-lisp/${PACKAGE}
UNCOMPILED='semantic-\(ede-grammar\|example\)\.el\|erlang'
for subdir in "" "/bovine"; do

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

    install -m 755 -d ${ELCDIR}
    cd ${ELDIR}
    FILES=`ls -1 *.el | grep -v ${UNCOMPILED}`
    cd ${ELCDIR}
    ln -sf ${ELDIR}/*.el .

    cat << EOF > path.el
(let ((paths (list "${ELPREFIX}" "${ELPREFIX}/bovine" "${ELPREFIX}/wisent"
                   "/usr/share/${FLAVOR}/site-lisp/cedet-common"
                   "/usr/share/${FLAVOR}/site-lisp/ede"
                   "/usr/share/${FLAVOR}/site-lisp/eieio"
                   "/usr/share/${FLAVOR}/site-lisp/speedbar")))
  (setq load-path (nconc paths load-path) byte-compile-warnings nil))
EOF
    ${FLAVOR} ${FLAGS} ${FILES}
    rm -f path.el

done

ln -sf /usr/share/emacs/site-lisp/${PACKAGE}/wisent \
    /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/wisent

exit 0
