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

set -e

FLAVOR=$1
PACKAGE="egg"

if [ "X${FLAVOR}" = "X" ]; then
    echo Need argument to determin FLAVOR of emacs;
    exit 1
fi

if [ "X${PACKAGE}" = "X" ]; then
    echo Internal error: need package name;
    exit 1;
fi

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

STARTDIR=/etc/${FLAVOR}/site-start.d
STARTFILE="${PACKAGE}-init.el";

SITELISP=/usr/share/${FLAVOR}/site-lisp

SRCS=" egg-util.el \
       menudiag.el its.el egg-edep.el \
       its/ascii.el \
       its/aynu.el \
       its/bixing.el \
       its/erpin.el \
       its/hankata.el \
       its/hira.el \
       its/jeonkak.el \
       its/pinyin.el \
       its/hangul.el \
       its/kata.el \
       its/thai.el \
       its/quanjiao.el \
       its/zenkaku.el \
       its/zhuyin.el \
       its-keydef.el \
       egg-mlh.el egg-cnv.el egg-com.el \
       egg.el \
       egg/cannarpc.el egg/canna.el \
       egg/sj3rpc.el egg/sj3.el \
       egg/wnnrpc.el egg/wnn.el"


EFLAGS="-batch -q --no-site-file --no-init-file -l ./docomp.el -l./jisx0213.el -f batch-byte-compile"
COMPILE="-batch -q -f batch-byte-compile"

case "${FLAVOR}" in
	emacs)
	;;
	emacs2*)

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

	rm -rf ${ELCDIR}
    install -m 755 -d ${ELCDIR}

    # Copy the temp .el files (and Makefile or so)
    # cp -par ${ELDIR}/* ${ELCDIR}/

    # Byte compile them
    (cd ${ELDIR}
     make EMACS=${FLAVOR} lispdir=${SITELISP} install clean > CompilationLog 2>&1
	)

	mv ${ELDIR}/CompilationLog ${ELCDIR}/
	gzip -9 ${ELCDIR}/CompilationLog

	if [ ! -d ${STARTDIR} ]; then
		install -m 755 -d ${STARTDIR}
	fi

	cp ${ELDIR}/${STARTFILE} ${STARTDIR}/50${STARTFILE};

	echo " done."
	;;
	*)
	;;
esac

exit 0;
