#!/bin/sh
# /usr/lib/emacsen-common/packages/install/hyperlatex
# [ This particular script hasn't been tested, so be careful. ]
set -e

FLAVOR=$1
echo install/hyperlatex: Handling install of emacsen flavor ${FLAVOR}

byte_compile_options="-batch -q -f batch-byte-compile"
el_files="hyperlatex.el"
el_dir=/usr/lib/hyperlatex/
elc_dir=/usr/share/${FLAVOR}/site-lisp/hyperlatex/
el_path_list=`echo ${el_files} | perl -pe "s|^|${el_dir}|o"`
elc_path_list=`echo ${el_files} | perl -pe "s|^|${elc_dir}|o"`

if [ ${FLAVOR} != emacs ]; then
  echo install/hyperlatex: byte-compiling for ${FLAVOR}

  if [ ! -d ${elc_dir} ]; then
    mkdir ${elc_dir}
  fi
  # Copy the temp .el files
  cp ${el_path_list} ${elc_dir}

  # Byte compile them
  ${FLAVOR} ${byte_compile_options} ${elc_path_list}

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