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

# $Id: emacsen-install,v 1.2 2002/03/30 02:08:10 walters Exp $

# 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>.

# Modified by Colin Walters <walters@cis.ohio-state.edu> to save
# compilation status, as well as to patch Calc before building for
# Emacs 21.

FLAVOR=$1
PACKAGE=calc

case ${FLAVOR} in
    emacs20|emacs21) echo install/${PACKAGE}: Byte-compiling for emacsen flavor ${FLAVOR}... ;;
    *) echo "install/${PACKAGE}: Ignoring emacsen flavor ${FLAVOR}" ; exit 0 ;;
esac

#FLAVORTEST=`echo $FLAVOR | cut -c-6`
#if [ ${FLAVORTEST} = xemacs ] ; then
#    SITEFLAG="-no-site-file"
#else
#    SITEFLAG="--no-site-file"
#fi


# Calc is compiled differently than other Emacs programs; it even
# provides its own compilation method.
FLAGS="${SITEFLAG} -q -batch -l path.el -l calc-maint.el -f calc-compile"

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
COMPILATIONLOG=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}/CompilationLog.gz

# 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/info/${PACKAGE}.info.gz
fi

install -m 755 -d ${ELCDIR}
cd ${ELDIR}
FILES=`echo *.el`
cp ${FILES} ${ELCDIR}
cd ${ELCDIR}

cat << EOF > path.el
(setq load-path (cons "." load-path))
EOF
estatus=0
if (${FLAVOR} ${FLAGS} 2>&1) | gzip -9 > $COMPILATIONLOG  ; then
    echo "Compilation successful, log saved as $COMPILATIONLOG"
else
    estatus=1
    echo "Compilation failed, log saved as $COMPILATIONLOG"
fi
rm -f *.el path.el

exit $estatus
