#! /bin/sh -e
#  /usr/lib/emacsen-common/packages/install/skk
# [ This particular script hasn't been tested, so be careful. ]
set -e

FLAVOR=$1
echo install/skk: Handling install of emacsen flavor ${FLAVOR}


SRCS="stack-m.el queue-m.el elib-node.el string.el \
      skk-foreword.el skk.el skk-num.el skk-gadget.el skk-auto.el \
      skk-comp.el skk-vip.el skk-viper.el skk-kakasi.el skk-kcode.el \
      skk-server.el skk-tree.el skk-tut.el skk-isearch.el skk-menu.el \
      skk-attr.el skk-leim.el make-vars.el"

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

byte_compile_options="-batch -q no-site-file -l lp.el -f batch-byte-compile"

if [ ${FLAVOR} != emacs ]
then
    echo install/skk: byte-compiling for ${FLAVOR}

    install -m 755 -d ${ELCDIR}
    
    # Copy the temp .el files
    for i in ${SRCS};
    do
        cp ${ELDIR}/${i} ${ELCDIR}/
    done


    # Byte compile them
    (cd ${ELCDIR}
    cat > lp.el <<EOF
(setq load-path (cons "." load-path))
(eval-when-compile
    (setq byte-compile-warnings '(callargs)))
EOF
    ${FLAVOR} -batch -q no-site-file -l make-vars.el -f make-skk-vars
    for i in ${SRCS}
    do
        ${FLAVOR} ${byte_compile_options} ${i}
    done
    )

    # remove the redundant .el files
    # presumes that any .el files in the <flavor> dir are trash.
    for i in ${SRCS}
    do
        rm ${ELCDIR}/${i}
    done
fi

exit 0;
