#!/bin/sh -e

echo install/custom: Handling installation of emacsen flavor $1

if [ "$1" = "emacs19" ]; then
  echo install/custom: byte-compiling for $1

  # Make sure the directory exists
  test -d /usr/share/$1/site-lisp/custom/ || mkdir /usr/share/$1/site-lisp/custom/

  # Move to the new directory
  cd /usr/share/$1/site-lisp/custom

  # Copy the temp .el files
  cp /usr/share/emacs/site-lisp/custom/*.el .

  # Byte compile them
  $1 -batch -q -no-site-file -l ./lpath.el -f batch-byte-compile widget.el wid-edit.el widget-example.el wid-browse.el custom.el cus-edit.el cus-face.el

  # remove the redundant .el files
  rm *.el

  # Make sure we get into the load path
  if [ ! -f /etc/emacs19/site-start.d/20custom-init.el ]; then
    ln -s ../../../usr/share/emacs/site-lisp/custom-init.el /etc/emacs19/site-start.d/20custom-init.el
  fi
fi

exit 0
