#!/bin/bash -e
#
# Copyright(c)1998 Hidenobu NABETANI <nabe@debian.or.jp>
# Copyright(c)2003 INOUE Hiroyuki <dombly@kc4.so-net.ne.jp>
#
# License: GPL2
# This program is written for Debian GNU/Linux YaTeX package.


abort_install() {
    echo "Byte compile for ${FLAVOR} failed."
    echo "Please check /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/CompilationLog.gz"
    echo
    exit 1
}

PACKAGE=yatex
FLAVOR=$1
case $FLAVOR in
    *xemacs*|emacs2[0123]|emacs19|mule2)
    exit 0
    ;;
esac

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

byte_compile_options="-batch -no-site-file -no-init-file"

# don't byte-compile yatex19.el 
LISP="comment.el yatex.el yatexadd.el yatexgen.el yatexenv.el \
    yatexlib.el yatexprc.el \
    yatexmth.el yatexhks.el yatexhlp.el \
    yatexm-o.el yatexsec.el  yatexhie.el yahtml.el yatexpkg.el"

if [ ${FLAVOR} != emacs ]
    then
    echo install/${PACKAGE}: Byte-compiling for ${FLAVOR}...

    install -m 755 -d ${ELCDIR}
    # link .el files
    ln -sf ${ELDIR}/*.el ${ELCDIR}

    # Byte compile them
    echo '(setq load-path (cons "." load-path))' >  ${ELCDIR}/lp.el
    echo '(load-file "./yatexlib.el")'           >> ${ELCDIR}/lp.el
    (cd ${ELCDIR} && ${FLAVOR} ${byte_compile_options} -l ./lp.el \
	-e bcf-and-exit ${LISP} 2>&1 | gzip -9qf > $LOG.gz) || abort_install
    echo "done."
fi

exit 0

### Local Variables:
### mode: shell-script
### End:
