#!/bin/bash

set -e

FLAVOR=$1

BYTE_COMPILE_OPTIONS="-batch -f batch-byte-compile"
EL_FILES="gnats.el send-pr.el" 
EL_DIR=/usr/share/emacs/site-lisp/gnats
ELC_DIR=/usr/share/${FLAVOR}/site-lisp/gnats

if [ "${FLAVOR}" != emacs ] && [ "${FLAVOR}" != xemacs21 ]; then
  echo "install/gnats: byte-compiling for ${FLAVOR}..."

  # Copy the temp .el files
  if [ ! -d ${ELC_DIR} ]; then
    mkdir ${ELC_DIR}
  fi
  cp ${EL_DIR}/*.el ${ELC_DIR}/

  # Byte compile them
  cd ${ELC_DIR}
  ${FLAVOR} ${BYTE_COMPILE_OPTIONS} ${EL_FILES} >/dev/null 2>&1

  # remove the redundant .el files
  # presumes that any .el files in the <flavor> dir are trash.
  rm ${ELC_DIR}/*.el
fi
exit 0
