#! /bin/sh -e

FLAVOR=$1
PACKAGE=windows

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

SRCS="windows.el revive.el"

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

byte_compile_options="-batch -q -no-site-file -l ${ELDIR}pre.el -f batch-byte-compile"

if [ ${FLAVOR} = emacs ]
then
    echo "Ignoring emacsen flavor ${FLAVOR}"
else
    echo install/${PACKAGE}: byte-compiling for ${FLAVOR}

    install -m 755 -d ${ELCDIR}
    
    # Copy the temp .el files
    for i in ${SRCS};
    do
        cp ${ELDIR}/${i} ${ELCDIR}/
    done

    # Byte compile them
    (cd ${ELCDIR}
    for i in ${SRCS}
    do
        ${FLAVOR} ${byte_compile_options} ${i}
    done 2>&1 | gzip -9qf > CompilationLog.gz
    ) 

    # remove the redundant .el files
    # presumes that any .el files in the <flavor> dir are trash.
    for i in ${SRCS}
    do
        rm ${ELCDIR}/${i}
    done
fi

exit 0
