#!/bin/bash

set -e

FLAVOR=$1
PACKAGE=speechd-el

BYTE_COMPILE_OPTIONS="-batch -f batch-byte-compile"
EL_FILES=`echo *.el`
EL_DIR=/usr/share/emacs/site-lisp/$PACKAGE
ELC_DIR=/usr/share/${FLAVOR}/site-lisp/$PACKAGE

if [ "${FLAVOR}" = emacs25 ] || [ "${FLAVOR}" = emacs24 ]; then
  echo "install/$PACKAGE: byte-compiling for ${FLAVOR}..."

  # Link the temp .el files
  if [ ! -d ${ELC_DIR} ]; then
    mkdir ${ELC_DIR}
  fi
  ln -sf ${EL_DIR}/Makefile ${EL_DIR}/*.el ${ELC_DIR}/

  # Byte compile them
  cd ${ELC_DIR}
  make EMACS=${FLAVOR} compile
  rm Makefile
fi

exit 0
