#! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/auctex
# [ This particular script hasn't been tested, so be careful. ]

set -e

FLAVOR=$1
PACKAGE="auctex"

if [ "X${FLAVOR}" = "X" ]; then
    echo Need argument to determin FLAVOR of emacs;
    exit 1
fi

if [ "X${PACKAGE}" = "X" ]; then
    echo Internal error: need package name;
    exit 1;
fi

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

STARTDIR=/etc/${FLAVOR}/site-start.d
STARTFILE="${PACKAGE}-init.el";

SITELISP=/usr/share/${FLAVOR}/site-lisp

## <merged from auctex-11.85/Makefile>
ELCC="${FLAVOR} -batch -q -no-site-file -no-init-file -l lpath.el"
MULESRC="tex-jp.el"
AUCSRC="tex.el tex-buf.el tex-style.el latex.el tex-info.el \
	texmathp.el multi-prompt.el tex-mik.el font-latex.el tex-font.el \
	context.el context-en.el context-nl.el tex-fold.el \
	toolbar-x.el tex-bar.el bib-cite.el tex-fptex.el"
STYLESRC="style/prosper.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 \
	   style/index.el     style/makeidx.el   style/multind.el \
	   style/varioref.el  style/fancyref.el	 style/mdwlist.el \
	   style/ngerman.el   style/graphicx.el	 style/graphics.el \
	   style/verbatim.el  style/scrbase.el   style/scrartcl.el \
	   style/scrbook.el   style/scrreprt.el	 style/scrlttr2.el \
	   style/scrpage2.el  style/captcont.el  style/subfigure.el \
	   style/paralist.el  style/booktabs.el  style/emp.el \
	   style/jura.el      style/alphanum.el	 style/beamer.el \
	   style/alltt.el     style/italian.el   style/doc.el \
	   style/ltxdoc.el    style/ltx-base.el	 style/units.el \
	   style/nicefrac.el  style/url.el       style/listings.el \
	   style/jurabib.el   style/csquotes.el  style/jsarticle.el \
	   style/jsbook.el    style/babel.el     style/dk-bib.el \
	   style/inputenc.el  style/frenchb.el   style/francais.el \
	   style/MinionPro.el style/pdfsync.el   style/polish.el \
	   style/polski.el    style/icelandic.el style/comment.el \
	   style/flashcards.el style/pstricks.el style/nomencl.el"
## </merged from auctex-11.85/Makefile>


case "${FLAVOR}" in

    *)

	echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."

	rm -rf ${ELCDIR}
	install -m 755 -d ${ELCDIR}

	# Byte compile
	(
	    cd ${ELDIR}
	    install -p -m 0644 *.el ${ELCDIR}
	    cp -ra style images ${ELCDIR}/
	    cd ${ELCDIR}

	    ${ELCC} -f batch-byte-compile \
		${MULESRC} ${AUCSRC} ${STYLESRC} > CompilationLog 2>&1

	    rm -f lpath.el auto-loads.el tex-wizard.el ${PACKAGE}-init.el
	)

	gzip -9 ${ELCDIR}/CompilationLog

	if [ ! -d ${STARTDIR} ]; then
	    install -m 755 -d ${STARTDIR}
	fi

	ln -sf ${ELDIR}/${STARTFILE} ${STARTDIR}/50${STARTFILE};

	echo " done."

	;;

esac

exit 0;
