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

# 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 for yacas by Gopal Narayanan <gopal@debian.org>

FLAVOR=$1
PACKAGE=yacas
#FILES="yacas.el yacas-notebook.el"
ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}


#xemacs check Stolen from octave 
flavortest=`echo ${FLAVOR} | cut -c-6`
if [ ${flavortest} = xemacs ] ; then
  SITEFLAG="-vanilla"
else
  SITEFLAG="--no-site-file"
fi

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

if [ ${FLAVOR} != emacs ] ; then
    echo install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}
    #Copy the temp .el files into the destination directory

    install -c -m 0755 -d ${ELCDIR}
    cd ${ELDIR}
    FILES=`echo *.el`
#    for i in ${FILES}
#    do
	cp ${FILES} ${ELCDIR}
#    done

    # The eval-and-compile construct is needed by emacs19, and was
    # pulled out of the auctex package by Yann Dirson. Merci bien, Yann!
    # The load-path.el trick is from Davide Salvetti's auctex package
    # This entire piece of code courtesy octave's emacsen-install

    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

else
    echo install/${PACKAGE}: Ignoring emacsen flavor ${FLAVOR}
fi


exit 0

#  (eval-and-compile
#    (condition-case () (require 'custom) (error nil))
#    (if (and (featurep 'custom) (fboundp 'custom-declare-variable))
#        nil
#      (defmacro defgroup (&rest args) nil)
#      (defmacro defcustom (var value doc &rest args)
#        (\` (defvar (, var) (, value) (, doc))))))
#  (setq load-path (cons "." load-path)
#        byte-compile-warnings nil)
#  EOF
#      logfile=`tempfile`
#      ${FLAVOR} ${FLAGS} ${FILES} >> ${logfile} 2>&1
#      rm ${FILES} path.el
#      mv ${logfile} ${ELCDIR}/install.log
#      echo "Compilation log saved to ${ELCDIR}/install.log"

#  else
#      echo install/${PACKAGE}: Ignoring emacsen flavor ${FLAVOR}
#  fi







