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

# Written by Jim Van Zandt <jrv@debian.org>, 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=emacspeak

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

FLAVORTEST=`echo $FLAVOR | cut -c-6`
if [ ${FLAVORTEST} = xemacs ] ; then
     echo "emacspeak does not support xemacs"
     exit 0;
fi
if [ -f /proc/cpuinfo ];then
    EST=`awk '/MHz/{printf(" (~%3.1f min)",1146/$NF)}' /proc/cpuinfo`
else
    EST=""
fi

log=`tempfile`

echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ${EST} with log file $log ..."

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

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

# 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}
cp *.el ${ELCDIR}

cd ${ELCDIR}

FILES="
dtk-voices.el
dtk-css-speech.el
dtk-interp.el
dtk-speak.el
outloud-voices.el
outloud-css-speech.el
dtk-tcl.el
voice-settings.el
voice-setup.el
voice-lock.el
emacspeak-speak.el
emacspeak-actions.el
lazy-voice-lock.el
jit-voice-lock.el
fast-voice-lock.el
html-voice.el
html-outline.el
emacspeak-pronounce.el
emacspeak-sounds.el
emacspeak.el
emacspeak-advice.el
emacspeak-keymap.el
emacspeak-fix-interactive.el
emacspeak-freeamp.el
emacspeak-redefine.el
emacspeak-replace.el
emacspeak-table.el
emacspeak-tabulate.el
emacspeak-table-ui.el
cd-tool.el
emacspeak-ansi-color.el
emacspeak-arc.el
emacspeak-auctex.el
emacspeak-aumix.el
emacspeak-babel.el
emacspeak-bbdb.el
emacspeak-bibtex.el
emacspeak-bookmark.el
emacspeak-browse-kill-ring.el
emacspeak-bs.el
emacspeak-buff-menu.el
emacspeak-buff-sel.el
emacspeak-c.el
emacspeak-calc.el
emacspeak-calculator.el
emacspeak-calendar.el
emacspeak-checkdoc.el
emacspeak-cmuscheme.el
emacspeak-compile.el
emacspeak-cperl.el
emacspeak-custom.el
emacspeak-dictation.el
emacspeak-dictionary.el
emacspeak-dired.el
emacspeak-dismal.el
emacspeak-dmacro.el
emacspeak-ecb.el
emacspeak-ediff.el
emacspeak-enriched.el
emacspeak-entertain.el
emacspeak-erc.el
emacspeak-eshell.el
emacspeak-eterm.el
emacspeak-eudc.el
emacspeak-facemenu.el
emacspeak-filtertext.el
emacspeak-find-dired.el
emacspeak-find-func.el
emacspeak-finder.el
emacspeak-flyspell.el
emacspeak-folding.el
emacspeak-forms.el
emacspeak-generic.el
emacspeak-gnuplot.el
emacspeak-gnus.el
emacspeak-gomoku.el
emacspeak-gridtext.el
emacspeak-gud.el
emacspeak-hide.el
emacspeak-hideshow.el
emacspeak-hyperbole.el
emacspeak-ibuffer.el
emacspeak-imenu.el
emacspeak-info.el
emacspeak-ispell.el
emacspeak-jde.el
emacspeak-kotl.el
emacspeak-make-mode.el
emacspeak-man.el
emacspeak-message.el
emacspeak-metapost.el
emacspeak-midge.el
emacspeak-mpg123.el
emacspeak-mspools.el
emacspeak-net-utils.el
emacspeak-ocr.el
emacspeak-oo-browser.el
emacspeak-outline.el
emacspeak-pcl-cvs.el
emacspeak-perl.el
emacspeak-psgml.el
emacspeak-python.el
emacspeak-realaudio.el
emacspeak-reftex.el
emacspeak-remote.el
emacspeak-rmail.el
emacspeak-sawfish.el
emacspeak-sgml-mode.el
emacspeak-sh-script.el
emacspeak-solitaire.el
emacspeak-speedbar.el
emacspeak-sql.el
emacspeak-supercite.el
emacspeak-tapestry.el
emacspeak-tar.el
emacspeak-tcl.el
emacspeak-tdtd.el
emacspeak-tempo.el
emacspeak-tetris.el
emacspeak-texinfo.el
emacspeak-tnt.el
emacspeak-url-template.el
emacspeak-view-process.el
emacspeak-view.el
emacspeak-vm.el
emacspeak-w3.el
emacspeak-websearch.el
emacspeak-widget.el
emacspeak-windmove.el
emacspeak-winring.el
emacspeak-wizards.el
emacspeak-wrolo.el
emacspeak-xslide.el
emacspeak-xslt-process.el
tapestry.el
emacspeak-rpm.el
regexp-opt.el
"
cat << EOF > path.el
(setq load-path (cons "." load-path)
;      byte-compile-warnings nil
      )
(setq byte-compile-dynamic t)
EOF

for f in ${FILES}; do
    echo "${FLAVOR} ${FLAGS} $f" >>${log}
    ${FLAVOR} ${FLAGS} $f >>${log} 2>&1
done

mv ${log} ${ELCDIR}/install.log
echo "done."
echo "Compilation log saved to ${ELCDIR}/install.log"

# compiling all at once does not work
#${FLAVOR} ${FLAGS} ${FILES}

rm *.el
cd ${ELDIR}
# copy over any uncompiled files
for x in *.el; do
    if [ ! -f ${ELCDIR}/${x}c ]; then cp $x ${ELCDIR}; fi
done

exit 0


