#!/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
if [ "X${FLAVOR}" = Xemacs ]; then exit 0; fi

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${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 ${ELCDIR}
  ${FLAVOR} ${COMPILE_OPT} ${COMPILE_SRC} > ${ELCDIR}/CompilationLog 2>&1
  rm -f ${ELCDIR}/*.el
  cd ${ELDIR}
  for f in *.el; do
    if [ -f ${ELCDIR}/${f}c ]; then
      ln -sf ${ELDIR}/${f} ${ELCDIR}/${f}
    fi
  done
)
gzip -9 ${ELCDIR}/CompilationLog
chmod 644 ${ELCDIR}/CompilationLog.gz
if [ -f ${ELCDIR}/select-xface.elc ]; then
  chmod 644 ${ELCDIR}/*.elc
fi
echo " done."

exit 0
