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

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

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}/
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}/
SRCS="stack-m.el queue-m.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-tut.el skk-isearch.el skk-menu.el \
      skk-attr.el skk-leim.el skk-rdbms.el skk-vars.el"


case ${FLAVOR} in
  emacs|emacs19)
    echo install/${PACKAGE}: Ignoring emacsen flavor ${FLAVOR};;
  *)
    echo install/${PACKAGE}: Byte-compiling for ${FLAVOR}
    install -m 755 -d ${ELCDIR}
    (
      cd ${ELDIR}
      ${FLAVOR} -batch -no-site-file -l ./make-vars.el -f make-skk-vars
      echo "(setq load-path (cons \".\" load-path))" > temp.el
      echo "(setq byte-compile-warnings '(callargs))" >> temp.el
      echo '(defun skk-compile () (mapcar (function (lambda (x) (byte-compile-file x))) (list ' >> temp.el
      echo ${SRCS} | sed -e 's/\([^ ][^ ]*\)/"\1"/g' >> temp.el
      echo ')))' >> temp.el
      ${FLAVOR} -batch -no-site-file -l ./temp.el -f skk-compile
      mv -f *.elc ${ELCDIR}
      rm -f skk-vars.el temp.el
    );;
esac

exit 0;
