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

##set -x

FLAVOR=$1
PACKAGE=auto-complete

FLAGS="-Q -L . -batch -f batch-byte-compile"

ELDIR="/usr/share/emacs/site-lisp/${PACKAGE}"
ELCDIR="/usr/share/${FLAVOR}/site-lisp/${PACKAGE}"
STARTDIR=/etc/${FLAVOR}/site-start.d
STARTFILE="${PACKAGE}-init.el"

SOURCES="auto-complete-config.el auto-complete.el fuzzy.el popup.el"
AC_DICT="ac-dict"

case "${FLAVOR}" in
    *) 
	echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."
	install -m 755 -d ${ELCDIR}
	cd ${ELDIR}
	cp *.el ${ELCDIR}
	sed -e "s|@@FLAVOR@@|${FLAVOR}|g" vine-default-${PACKAGE}.el.in > ${ELCDIR}/vine-default-${PACKAGE}.el
	rm -rf ${ELCDIR}/${AC_DICT}
	cp -ra ${AC_DICT} ${ELCDIR}/
	FILES="${SOURCES}"
	cd ${ELCDIR}
	${FLAVOR} ${FLAGS} ${FILES} > ${ELCDIR}/CompilationLog 2>&1
	rm -f ${SOURCES}
	gzip -9 ${ELCDIR}/CompilationLog

	rm -f ${PACKAGE}-init.{el,elc}
	rm -f vine-default-${PACKAGE}.elc

	ln -sf ${ELDIR}/${STARTFILE} ${STARTDIR}/95${STARTFILE};
	echo " done."
	;;
esac

exit 0 ;
