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

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

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

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

EMACS=$FLAVOR
FLAVORTEST=`echo $FLAVOR | cut -c-6`
if [ ${FLAVORTEST} = xemacs ] ; then
    SITEFLAG="-no-site-file"
    set +e
    EMACS=`/bin/ls -1 /usr/bin/${FLAVOR}*-mule* 2>/dev/null| head -1 `
    if test -x "$EMACS"; then
	:
    else
	echo Warning: Mule enabled ${FLAVOR} not found, skipped
	exit 0
    fi
    set -e
else
    SITEFLAG="--no-site-file"
fi
# FLAGS="${SITEFLAG} -q -batch -l path.el -f batch-byte-compile"
FLAGS="${SITEFLAG} -q -batch -l MHC-MK"

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

install -m 755 -d ${ELCDIR}
cd ${ELDIR}
FILES=`echo *.el`
cp ${FILES} Makefile MHC-MK ${ELCDIR}
cd ${ELCDIR}

INST_OPTS=--with-addpath=.
MEW_OPTS=
WL_OPTS=
GNUS_OPTS=
if test -d /usr/share/${FLAVOR}/site-lisp/mew; then
 INST_OPTS=${INST_OPTS}:/usr/share/${FLAVOR}/site-lisp/mew
 MEW_OPTS=--with-mew
fi
if test -d /usr/share/${FLAVOR}/site-lisp/wanderlust2; then
 INST_OPTS=${INST_OPTS}:/usr/share/${FLAVOR}/site-lisp/wanderlust2:/usr/share/${FLAVOR}/site-lisp/apel:/usr/share/${FLAVOR}/site-lisp/apel/emu:/usr/share/${FLAVOR}/site-lisp/flim:/usr/share/${FLAVOR}/site-lisp/semi
 WL_OPTS=--with-wl
fi
if test -d /usr/share/${FLAVOR}/site-lisp/wl; then
 INST_OPTS=${INST_OPTS}:/usr/share/${FLAVOR}/site-lisp/wl:/usr/share/${FLAVOR}/site-lisp/apel:/usr/share/${FLAVOR}/site-lisp/apel/emu:/usr/share/${FLAVOR}/site-lisp/flim:/usr/share/${FLAVOR}/site-lisp/semi
 WL_OPTS=--with-wl
fi
if test -d /usr/share/${FLAVOR}/site-lisp/wl-beta; then
 INST_OPTS=${INST_OPTS}:/usr/share/${FLAVOR}/site-lisp/wl-beta:/usr/share/${FLAVOR}/site-lisp/apel:/usr/share/${FLAVOR}/site-lisp/apel/emu:/usr/share/${FLAVOR}/site-lisp/flim:/usr/share/${FLAVOR}/site-lisp/semi
 WL_OPTS=--with-wl
fi
if test -d /usr/share/${FLAVOR}/site-lisp/t-gnus; then
 INST_OPTS=${INST_OPTS}:/usr/share/${FLAVOR}/site-lisp/t-gnus:/usr/share/${FLAVOR}/site-lisp/apel:/usr/share/${FLAVOR}/site-lisp/apel/emu:/usr/share/${FLAVOR}/site-lisp/flim:/usr/share/${FLAVOR}/site-lisp/semi
 GNUS_OPTS=--with-gnus
elif test -d /usr/share/${FLAVOR}/site-lisp/gnus; then
 INST_OPTS=${INST_OPTS}:/usr/share/${FLAVOR}/site-lisp/gnus
 GNUS_OPTS=--with-gnus
fi
if [ ${FLAVOR} = mule2 ]; then
 INST_OPTS=${INST_OPTS}:/usr/share/${FLAVOR}/site-lisp/custom-mule:/usr/share/${FLAVOR}/site-lisp/apel
fi
test -f mhc.elc && rm -f mhc.elc
make -f Makefile EMACS=${EMACS} FLAGS="${FLAGS}" OPTS="${INST_OPTS} ${MEW_OPTS} ${WL_OPTS} ${GNUS_OPTS}" elc > CompilationLog 2>&1
rm -f *.el path.el Makefile MHC-MK CompilationLog.gz
gzip -9 CompilationLog

exit 0
