#! /bin/bash -e
# /usr/lib/emacsen-common/packages/install/x-symbol

# FIXME - this is a mess, it kinda evolved

FLAVOR=$1
options="-batch -f batch-byte-compile"
el_dir=/usr/share/emacs/site-lisp/x-symbol/
elc_dir=/usr/share/${FLAVOR}/site-lisp/x-symbol/
el_files="
x-symbol-bib.el
x-symbol.el
x-symbol-hooks.el
x-symbol-image.el
x-symbol-macs.el
x-symbol-myuc.el
x-symbol-nomule.el
x-symbol-mule.el
x-symbol-sgml.el
x-symbol-site.el
x-symbol-tex.el
x-symbol-texi.el
x-symbol-vars.el
x-symbol-xmacs.el
x-symbol-startup.el
"

echo install/x-symbol: Handling install of emacsen flavor ${FLAVOR}

if [ "${FLAVOR}" == emacs21 -o "${FLAVOR}" == xemacs21 ];
then

#    echo install/x-symbol: install Info links for ${FLAVOR}
#    install-info-altdir --quiet --section "" "" --dirname=${FLAVOR} \
#	/usr/info/x-symbol.info.gz

    echo install/x-symbol: byte-compiling for ${FLAVOR}

    if [ ${FLAVOR} == "emacs21" ]
    then
	el_files="${el_files} x-symbol-emacs.el"
    fi

#    el_path_list=`echo ${el_files}|tr ' ' '\012'|perl -pe "next if m|startup|;s|^|${el_dir}|o"`
#    elc_path_list=`echo ${el_files}|tr ' ' '\012'|perl -pe "next if m|startup|;s|^|${elc_dir}|o"`
    el_path_list=`echo ${el_files}|tr ' ' '\012'|perl -pe "s|^|${el_dir}|o"`
    elc_path_list=`echo ${el_files}|tr ' ' '\012'|perl -pe "s|^|${elc_dir}|o"`


    install -d ${elc_dir}
    cp ${el_path_list} ${elc_dir}


    if [ "${FLAVOR}" == xemacs21 ]
    then
        if [ -x /usr/bin/xemacs21-nomule ]
        then
	  cp ${el_dir}/x-symbol-nomule.el ${elc_dir}
	  /usr/bin/xemacs21-nomule ${options} ${elc_dir}/x-symbol-nomule.el
        elif [ -x /usr/bin/xemacs21-gnome-nomule ]
	then
          cp ${el_dir}/x-symbol-nomule.el ${elc_dir}
	  /usr/bin/xemacs21-gnome-nomule ${options} ${elc_dir}/x-symbol-nomule.el
        fi
    fi

    # compile partially fails on emacs21, because X isn't avail

    ${FLAVOR} ${options} ${elc_path_list} || [ "${FLAVOR}" == emacs21 ]
    [ "${FLAVOR}" == emacs21 ] || rm -f ${elc_dir}/*.el

    # remove junk from old package
    if [ -f /etc/${FLAVOR}/site-start.d/42x-symbol.el ]; then
	rm /etc/${FLAVOR}/site-start.d/42x-symbol.el
    fi

fi
exit 0
