#!/bin/bash -e
#
# elisp install file for Debian auctex package.
# $Id: install.in,v 1.6 1999/10/22 19:58:34 salve Exp $
#
# Copyright  Davide G. M. Salvetti <salve@debian.org>, 1997, 1998, 1999.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to: The Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# On Debian GNU/Linux System you can find a copy of the GNU General Public
# License in "/usr/share/common-licenses/GPL".

set -o posix

FLAVOR=$1

EFLAGS="--no-site-file --no-init-file --batch --load=lpath.el --funcall=batch-byte-compile"
EMULEFLAGS="--no-site-file --no-init-file --batch  --load=lpath-jp.el --funcall=batch-byte-compile"

# This shouldn't compile without X, and we have font-latex.el anyway: hilit-LaTeX.el.

case "$FLAVOR" in
    emacs)
	:
    ;;
    emacs19|emacs20|mule2)
	echo -n "install/auctex: Byte-compiling for $FLAVOR... "
	install -m 755 -d /usr/share/$FLAVOR/site-lisp/auctex/ \
	    /usr/share/$FLAVOR/site-lisp/auctex//style/
	for i in auc-old.el tex.el tex-buf.el latex.el tex-info.el texmathp.el multi-prompt.el bib-cite.el font-latex.el style/slides.el    style/foils.el    style/amstex.el style/article.el   style/book.el     style/letter.el style/report.el    style/amsart.el   style/amsbook.el style/epsf.el      style/psfig.el    style/latexinfo.el style/dutch.el     style/german.el   style/dk.el style/j-article.el style/j-book.el   style/j-report.el style/jarticle.el  style/jbook.el    style/jreport.el style/dinbrief.el  style/virtex.el   style/plfonts.el style/plhb.el      style/harvard.el	style/swedish.el style/danish.el    style/slovak.el   style/czech.el style/amsmath.el   style/amstext.el  style/amsbsy.el style/amsopn.el    style/amsthm.el	style/natbib.el
	    do cp /usr/share/emacs/site-lisp/auctex//$i /usr/share/$FLAVOR/site-lisp/auctex//$i
	done
	cat <<-EOF >/usr/share/$FLAVOR/site-lisp/auctex//lpath.el
		(setq load-path (cons "." load-path)
		    TeX-lisp-directory "<none>")
	EOF
	(cd /usr/share/$FLAVOR/site-lisp/auctex/ \
	    && $FLAVOR $EFLAGS auc-old.el tex.el tex-buf.el latex.el tex-info.el texmathp.el multi-prompt.el bib-cite.el font-latex.el style/slides.el    style/foils.el    style/amstex.el style/article.el   style/book.el     style/letter.el style/report.el    style/amsart.el   style/amsbook.el style/epsf.el      style/psfig.el    style/latexinfo.el style/dutch.el     style/german.el   style/dk.el style/j-article.el style/j-book.el   style/j-report.el style/jarticle.el  style/jbook.el    style/jreport.el style/dinbrief.el  style/virtex.el   style/plfonts.el style/plhb.el      style/harvard.el	style/swedish.el style/danish.el    style/slovak.el   style/czech.el style/amsmath.el   style/amstext.el  style/amsbsy.el style/amsopn.el    style/amsthm.el	style/natbib.el 2>&1 \
	    | gzip -9qf > CompilationLog.gz)
	if [ "$FLAVOR" = "emacs20" -o "$FLAVOR" = "mule2" ]; then
		# We have MULE.
		for i in tex-jp.el
		    do cp /usr/share/emacs/site-lisp/auctex//$i \
			/usr/share/$FLAVOR/site-lisp/auctex//$i
		done
		# This contains an hack to allow byte-compiling
		# with japanese multibyte chars
		cat <<-EOF >/usr/share/$FLAVOR/site-lisp/auctex//lpath-jp.el
			(setq load-path (cons "." load-path)
				TeX-lisp-directory "<none>")
			(set-language-environment 'Japanese);') <- beauty stuff
		EOF
		(cd /usr/share/$FLAVOR/site-lisp/auctex/ \
		    && $FLAVOR $EMULEFLAGS tex-jp.el 2>&1 \
		    | gzip -9qf >> CompilationLog.gz)
	fi
	rm -f /usr/share/$FLAVOR/site-lisp/auctex//*.el \
	    /usr/share/$FLAVOR/site-lisp/auctex//style//*.el
	echo "done."
    ;;
    *)
	echo "install/auctex: Ignoring emacsen flavor $FLAVOR."
    ;;
esac

exit 0
