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

# Written by Jim Van Zandt <jrv@vanzandt.mv.com>, borrowing heavily
# from the install scripts for gettext by Santiago Vila
# <sanvila@ctv.es> and octave by Dirk Eddelbuettel <edd@debian.org>.

FLAVOR=$1
PACKAGE=tc-el
DATADIR=/usr/share/tc

if [ ${FLAVOR} = emacs ]; then exit 0; fi

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

FLAVORTEST=`echo $FLAVOR | cut -c-6`
if [ ${FLAVORTEST} = xemacs ] ; then
    SITEFLAG="-no-site-file"
else
    SITEFLAG="--no-site-file"
fi
FLAGS="${SITEFLAG} -q -batch -l make-elc.el -f batch-byte-compile"

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
STARTDIR=/etc/${FLAVOR}/site-start.d
STARTFILE="${PACKAGE}-init.el"

COMMON_EL_FILES="tc-setup.el tc.el tc-help.el tc-complete.el tc-jiscode.el tc-bushu.el tc-mazegaki.el tc-util.el tc-tbl.el tutc-tbl.el eelll.el tc-inst.el tc-stat.el tc-ja-alnum.el"
EL_FILES=tc-is18.el

# Install-info-altdir does not actually exist. 
# Maybe somebody will write it.
#if test -x /usr/sbin/install-info-altdir; then
#    echo install/${PACKAGE}: install Info links for ${FLAVOR}
#    install-info-altdir --quiet --section "" "" --dirname=${FLAVOR} /usr/info/${PACKAGE}.info.gz
#fi

echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."
install -m 755 -d ${ELCDIR}
install -m 444 ${DATADIR}/tc-bitmap-8x16 ${ELCDIR}
cd ${ELDIR}
FILES=`echo *.el`
cp ${FILES} ${ELCDIR}
ln -sf ${ELDIR}/${STARTFILE} ${STARTDIR}/95${STARTFILE};

cd ${ELCDIR}

cat << EOF > make-elc.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
(load "tc-sysdep.el")
(and (fboundp 'set-language-environment)
     (set-language-environment "Japanese"))
EOF
${FLAVOR} ${FLAGS} ${COMMON_EL_FILES} ${EL_FILES} > ${ELCDIR}/CompilationLog 2>&1
gzip -9 ${ELCDIR}/CompilationLog

rm -f ${COMMON_EL_FILES} ${EL_FILES} make-elc.el
echo " done."

exit 0

