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

# 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=ddskk

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

## Checking MULE supported XEmacs. -------------------------------------
if [ ${FLAVOR} = "xemacs20" -o ${FLAVOR} = "xemacs21" ]; then
    CHECKMULE=`${FLAVOR} -batch -vanilla -eval "(if (featurep 'mule)(message \"MULE\"))" 2>&1`
    if [ "${CHECKMULE}" != "MULE" ]; then exit 0; fi
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 path.el"

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

# 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 "Emacs" "Skk" --dirname=${FLAVOR} /usr/share/info/skk.info.gz
fi

install -m 755 -d ${ELCDIR}
cd ${ELDIR}
FILES=`echo *`
cp -r ${FILES} ${ELCDIR}
cd ${ELCDIR}

cat << EOF > path.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
EOF
${FLAVOR} ${FLAGS} -l SKK-MK -f SKK-MK-generate-autoloads-el >CompilationLog 2>&1
sed '/^;;; `load-path/,/^$/s/^/;/' skk-setup.el.in >skk-setup.el
mv -f leim-list.el.in leim-list.el
${FLAVOR} ${FLAGS} -f batch-byte-compile skk-setup.el >>CompilationLog 2>&1
${FLAVOR} ${FLAGS} -l SKK-MK -f SKK-MK-compile NONE NONE NONE >>CompilationLog 2>&1
cd nicola
${FLAVOR} ${FLAGS} -l NICOLA-DDSKK-ELS -l NICOLA-DDSKK-MK -f nicola-ddskk-generate-autoloads >>../CompilationLog 2>&1
${FLAVOR} ${FLAGS} -f batch-byte-compile nicola-ddskk-autoloads.el >>../CompilationLog 2>&1
${FLAVOR} ${FLAGS} -l NICOLA-DDSKK-MK -f compile-nicola-ddskk NONE NONE NONE >>../CompilationLog 2>&1
rm -f NICOLA-* *.el
cd ..
rm -rf SKK-* *.el *.in tut-code
gzip -9qf CompilationLog

exit 0
