#! /bin/sh -e

FLAVOR=$1
PACKAGE=trr19

echo install/${PACKAGE}: Handling install of emacsen flavor ${FLAVOR}

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

case ${FLAVOR} in
    emacs|xemacs20)
        echo install/${PACKAGE}: Ignoring emacsen flavor ${FLAVOR};;
    *)
        echo -n install/${PACKAGE}: Byte-compiling for ${FLAVOR} ...
        install -m 755 -d ${ELCDIR}
    
        (
            cd ${ELCDIR}
            cp ${ELDIR}/*.el .
            for i in *.el; do
                if [ ${FLAVOR} = emacs19 ]; then
                    ${FLAVOR} -batch -no-site-file \
                        -f batch-byte-compile $i 2>&1 | gzip -9qf >>$LOG
                else
                    ${FLAVOR} -batch -no-site-file \
                        --eval '(set-language-environment "Japanese")' \
                        -f batch-byte-compile $i 2>&1 | gzip -9qf >>$LOG
                fi
            done
            rm *.el
        )
        echo " done.";;
esac

exit 0
