#!/bin/sh

# Emacs install: /usr/lib/emacsen-common/packages/install/miscbits-el

# Copyright 2005, 2007, 2009, 2010 Kevin Ryde
# Copyright 1998, 2009 Robert Browning
#
# This file is part of miscbits-el.  It was derived from the example code in
# /usr/share/doc/emacsen-common/debian-emacs-policy.gz of emacsen-common
# version 1.4.16.  That code is by Rob Browning and covered by the GPL, as
# described in /usr/share/doc/emacsen-common/copyright.
#
#
# miscbits-el is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later
# version.
#
# miscbits-el is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# This uses the "single directory" style.  The .el files are symlinked into
# the $FLAVOUR directory and compiled there.  The symlinks are left so the
# source is available for the various help tools like `find-function'.

set -e

FLAVOUR=$1
echo install/miscbits-el: Handling install of emacsen flavor $FLAVOUR

el_dir=/usr/share/emacs/site-lisp/miscbits-el/
elc_dir=/usr/share/$FLAVOUR/site-lisp/miscbits-el/

if [ $FLAVOUR != emacs ]
then
  echo install/miscbits-el: byte-compiling for $FLAVOUR

  test -d $elc_dir || mkdir $elc_dir
  # symlink .el files
  ln -sf $el_dir/*.el $elc_dir

  cd $elc_dir
  set -x

  case $FLAVOUR in
    emacs20)
      EL_FILES=`ls *.el \
        | egrep -v 'gutenberg-coding.el|mo-mode.el|unicode-disp.el' \
        `
      ;;
    *)
      EL_FILES="*.el"
      ;;
  esac

  # Autoloads differ a bit between emacs, generate for each flavour, as per
  # Makefile in the sources.
  #
  $FLAVOUR -batch -q -no-site-file \
    -l /usr/share/miscbits-el/miscbits-generate-loaddefs.el \
    -f my-loaddefs-batch \
    $EL_FILES

  # Byte compile .el files.
  #
  $FLAVOUR -batch -q -no-site-file \
    -l /usr/share/miscbits-el/miscbits-byte-compile.el \
    -f batch-byte-compile \
    $EL_FILES
  set +x
fi
exit 0
