#!/bin/sh
# /usr/lib/emacsen-common/packages/install/select-xface
set -e

FLAVOR=$1
PACKAGE="select-xface"

if [ "X${FLAVOR}" = "X" ]; then
  echo Need argument to determin FLAVOR of emacsen
  exit 1
fi
if [ "X${PACKAGE}" = "X" ]; then
  echo Internal error: need package nameen
  exit 1
fi

ELDIR=/usr/share/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
TOELDIR=../../../$PACKAGE
COMPILE_SRC="select-xface.el"
COMPILE_OPT="-batch -q -no-site-file -f batch-byte-compile"

echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."
rm -rf ${ELCDIR}
install -m 755 -d ${ELCDIR}

cp ${ELDIR}/* ${ELCDIR}/

( cd "$ELDIR"
  FILES=`echo *.el`
  cd "$ELCDIR"
  ${FLAVOR} ${COMPILE_OPT} ${COMPILE_SRC} > ${ELCDIR}/CompilationLog 2>&1
  rm -f ${ELCDIR}/*.el
  for f in $FILES; do
    ln -sf "$TOELDIR/$f" .
  done
)
gzip -9 ${ELCDIR}/CompilationLog
chmod 644 ${ELCDIR}/CompilationLog.gz
if [ -f ${ELCDIR}/select-xface.elc ]; then
  chmod 644 ${ELCDIR}/*.elc
fi
if [ -f /usr/share/emacsen-common/debian-startup.el ] && \
   [ ! -f "/etc/$FLAVOR/site-start.d/52$PACKAGE.el" ] && \
   [ -f "/etc/emacs/site-start.d/52$PACKAGE.el" ] && \
   [ -d "/etc/$FLAVOR/site-start.d" ]; then
  ln -sf "../../emacs/site-start.d/52$PACKAGE.el" "/etc/$FLAVOR/site-start.d/52$PACKAGE.el"
fi
echo " done."

exit 0
