#! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/lookup

FLAVOR=$1
PACKAGE=lookup
VERSION=1.4

FLAGS="${SITEFLAG} -q -batch -l /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/lookup-compile.el"

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

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

STAMP=${ELCDIR}/compile-stamp

SOURCES="evi.el evi-mule.el lookup.el lookup-utils.el lookup-types.el    lookup-vse.el lookup-package.el lookup-kanji.el lookup-entry.el lookup-content.el lookup-select.el     ndic.el ndeb-binary.el ndeb.el ndtp.el ndict.el ndkks.el ndspell.el    ndcookie.el ndmisc.el ndsrd.el ndnmz.el sdicf.el stem-english.el"

EXTRA_DIST="lookup-vars.el.in lookup-compile.el lookup-logo.xbm lookup-logo.xpm"
#EXTRA_DIST2="ndnmz.el"

case "$FLAVOR" in
    emacs)
    ;;
    *)
    echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."
    if [ ! -d /usr/share/emacs/site-lisp/flim ]; then
	echo " exited."
	echo "W: Please install \`flim' package for ${FLAVOR}." ;
	exit 0;
    fi

    if [ -e ${STAMP} ]; then
	if [ "${VERSION}" = "`cat ${STAMP}`" ]; then
	    echo " exited. (already compiled)" 
	    exit
	fi
    fi

    case "${FLAVOR}" in
    	xemacs-21*)
	## Fix compile error with xemacs21 on unset LANG or LANG=C .
	export LANG=ja_JP
	## Checking MULE supported XEmacs. -------------------------------------
	CHECKMULE=`${FLAVOR} -batch -vanilla -eval "(if (featurep 'mule)(message \"MULE\"))" 2>&1`
	if [ "${CHECKMULE}" != "MULE" ]; then exit 0; fi
	;;
	*)
	;;
    esac

    install -m 755 -d ${ELCDIR}
    cd ${ELDIR}
    cp ${SOURCES} ${EXTRA_DIST} ${ELCDIR}
    FILES="${SOURCES} lookup-vars.el"
    cd ${ELCDIR}
    sed -e s/\@VERSION\@/${VERSION}/  -e s!\@pkgemacsdir\@!${ELCDIR}!  lookup-vars.el.in > lookup-vars.el
    ${FLAVOR} ${FLAGS} ${FILES} > ${ELCDIR}/CompilationLog 2>&1
    rm -f ${SOURCES} lookup-vars.el.in

    gzip -9 ${ELCDIR}/CompilationLog
    echo ${VERSION} > ${STAMP}

    install -p -m644 ${ELDIR}/vine-default-${PACKAGE}.el ${ELCDIR}
    ln -sf ${ELDIR}/${STARTFILE} ${STARTDIR}/85${STARTFILE}

    echo " done."
    ;;
esac

exit 0 ;
