#!/bin/sh

VERSION=2.56
FLAVOR=$1
PACKAGE="autoconf-mode"

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

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

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

COMPILE="-batch -q -f batch-byte-compile"
STAMP=${ELCDIR}/compile-stamp

case "${FLAVOR}" in

    emacs)

	;;

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

	if [ -e ${STAMP} ]; then
	    if [ "${VERSION}" = "`cat ${STAMP}`" ]; then
		echo " exited. (already compiled)" 
		# echo "${PACKAGE}: ${VERSION} have been compiled already."
		exit
	    else
		rm -f ${STAMP}
	    fi
	fi

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

	# Byte compile
	(
	    cd ${ELDIR}
	    ${FLAVOR} ${COMPILE} *.el > ${ELCDIR}/CompilationLog 2>&1
	    install -m 644 *.elc ${ELCDIR}/
	)

	gzip -9 ${ELCDIR}/CompilationLog
	echo ${VERSION} > ${STAMP}
   
	echo " done."
	;;
esac

exit 0;
