#! /bin/sh -e

FLAVOR=$1
PACKAGE=edb

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

ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}/
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}/

case ${FLAVOR} in
    emacs)
        echo install/${PACKAGE}: Ignoring emacsen flavor ${FLAVOR};;
    *)
        echo -n install/${PACKAGE}: Byte-compiling for ${FLAVOR} ...
        install -m 755 -d ${ELCDIR}
    
        (
            cd ${ELDIR}
            echo '(setq load-path (cons "." load-path))' > BYTE-COMPILE.el 
            echo '(setq edb-directory ".")' >> BYTE-COMPILE.el 
            ${FLAVOR} -batch -no-site-file \
                -l ./BYTE-COMPILE.el -l database.el \
                -f byte-compile-database-all \
                -f batch-byte-compile database.el
            ${FLAVOR} -batch -no-site-file -f batch-byte-compile edb-fixes-1.21.el

            rm BYTE-COMPILE.el
            mv -f *.elc ${ELCDIR}
        )
        echo " done.";;
esac

exit 0
