#! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/w3m-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=w3m

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

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

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

install -m 755 -d ${ELCDIR}
install -m 755 -d ${ELCDIR}/shimbun

case ${FLAVOR} in
xemacs*)
    SITEFLAG="-no-site-file";;
*)
    SITEFLAG="--no-site-file";;
esac
LPATH=""
for el in apel apel/emu flim mew
do
 if [ -d /usr/share/${FLAVOR}/site-lisp/${el} ]; then
  LPATH="${LPATH}:/usr/share/${FLAVOR}/site-lisp/${el}"
 else
  LPATH="${LPATH}:/usr/share/emacs/site-lisp/${el}"
 fi
done
if [ ${FLAVOR} = mule2 ]; then
  LPATH="${LPATH}":/usr/share/mule2/site-lisp/custom-mule
  cp /usr/share/doc/w3m-el/attic/regexp-opt.el ${ELCDIR}/regexp-opt.el
fi
FLAGS="${SITEFLAG} -q -batch -l path.el -l w3mhack.el ${LPATH}"

# 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

(cd ${ELDIR}; FILES=`echo *.el`; cp ${FILES} ${ELCDIR})
(cd ${ELDIR}/shimbun; FILES=`echo *.el`; cp ${FILES} ${ELCDIR}/shimbun)
cd ${ELCDIR}
rm -f *.elc shimbun/*.elc
if [ ${FLAVOR} = mule2 ]; then
  ${FLAVOR} -q -no-site-file -batch -f batch-byte-compile regexp-opt.el
fi
cat << EOF > path.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
EOF
${FLAVOR} ${FLAGS} -f w3mhack-compile 2>&1 | gzip -9 > CompilationLog.gz
rm -f `ls -1 *.el | grep -v w3m-kwds.el` path.el shimbun/*.el path.elc
exit 0
