#! /bin/sh -e
set -e

PACKAGE=sather-elisp
FLAVOR=$1

echo install/${PACKAGE}: Handling install of emacsen flavor ${FLAVOR}

byte_compile_options="-batch -f batch-byte-compile"
el_files="sather.el sather-module.el sather-lib.el" 
el_dir=/usr/share/emacs/site-lisp/${PACKAGE}
elc_dir=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}

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

    install -m 755 -d ${elc_dir}

    # Copy the temp .el files
    for f in ${el_files}
    do
	cp ${el_dir}/${f} ${elc_dir}/
	# Byte compile it
	${FLAVOR} ${byte_compile_options} ${elc_dir}/${f}
    done

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

exit 0
