#! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/prime-el

FLAVOR=$1
VERSION=1.5.1.3-1
PACKAGE=prime-el

if [ "X${FLAVOR}" = "X" ]; then
  echo "Need argument to determine FLAVOR of emacsen"
  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}
FLAGS="${SITEFLAG} -q -batch -l path.el -f batch-byte-compile"
STAMP="${ELCDIR}/compile-stamp"

LOG=CompilationLog

case "$FLAVOR" in
    emacs20|emacs21)
	echo -n "install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}..."
	if [ -e "${STAMP}" ]; then
	    if [ "X${VERSION}" = X"$(cat ${STAMP})" ]; then
		echo " skipped. (already compiled)" 
		exit 0
	    else
		rm -f ${STAMP}
	    fi
	fi
	
	rm -rf ${ELCDIR}
	install -m 755 -d ${ELCDIR}
	cd ${ELDIR}
	FILES=$(find . -name '*.el')
	cp -dRf * ${ELCDIR}
	cd ${ELCDIR}
	
	cat << EOF > path.el
(setq load-path (cons "contrib" (cons "." load-path)) byte-compile-warnings nil)
EOF
	${FLAVOR} ${FLAGS} ${FILES} > ${LOG} 2>&1
	gzip -9 ${LOG}
	
	rm -f *.el path.el
	
	echo "${VERSION}" > ${STAMP}
	chmod 644 ${STAMP}
	
	echo " done."
	;;
    xemacs*)
	echo -n "install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}..."
	rm -rf ${ELCDIR}
	install -m 755 -d ${ELCDIR}
	cd ${ELDIR}
	cp contrib/*.el *.el ${ELCDIR}

	echo " done. (not compiled)"	
	;;
    *)
        echo "install/$PACKAGE: Ignoring emacsen flavor $FLAVOR."
        ;;
esac

exit 0
