#! /bin/sh
# /usr/lib/emacsen-common/packages/install/jde
# Ruud de Rooij <ruud@debian.org>  Fri,  8 Sep 2000 10:45:21 +0200
# Heavily based on Rob Browning's sample script distributed with the
# emacsen-common package.

set -e

FLAVOR=$1

byte_compile_options="-q -l path.el -batch -f batch-byte-compile"

el_files="
beanshell.el
efc.el
jde-ant.el
jde-autoload.el
jde-bug.el
jde-checkstyle.el
jde-compat.el
jde-compile.el
jde-complete.el
jde-db.el
jde-dbo.el
jde-dbs.el
jde-ejb.el
jde-gen.el
jde-help.el
jde-imenu.el
jde-import.el
jde-java-font-lock.el
jde-java-grammar.el
jde-javadoc-gen.el
jde-javadoc.el
jde-jdb.el
jde-make.el
jde-open-source.el
jde-package.el
jde-parse-class.el
jde-parse.el
jde-run.el
jde-stat.el
jde-util.el
jde-which-method.el
jde-widgets.el
jde-wiz.el
jde-xref.el
jde.el
setnu.el
tree-widget.el
"

el_dir=/usr/share/emacs/site-lisp/jde
elc_dir=/usr/share/${FLAVOR}/site-lisp/jde
el_paths=
elc_paths=

for el_file in $el_files 
do
    el_paths="$el_paths $el_dir/$el_file"
    elc_paths="$elc_paths $elc_dir/$el_file"
done

if [ ${FLAVOR} = emacs21 -o ${FLAVOR} = emacs20 -o ${FLAVOR} = xemacs21 ]
then
  echo jde: Installing byte-compiled files for emacsen flavor ${FLAVOR}

  # Copy the temporary .el files
  mkdir -p ${elc_dir}
  install -m 644 ${el_paths} ${elc_dir}
  cd ${elc_dir}

  cat << EOF > path.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
EOF
  # Byte compile them
  ${FLAVOR} ${byte_compile_options} ${elc_paths} >${elc_dir}/compile.log 2>&1
  echo jde: Compile log saved to ${elc_dir}/compile.log

  # remove the redundant .el files
  # presumes that any .el files in the <flavor> dir are trash.
  rm ${elc_dir}/*.el
else
  echo jde: Skipping installation for emacsen flavor ${FLAVOR}
fi
exit 0
