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


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-exec.el
x-symbol-hooks.el
x-symbol-image.el
x-symbol-macs.el
x-symbol-mule.el
x-symbol-myuc.el
x-symbol-sgml.el
x-symbol-tex.el
x-symbol-texi.el
x-symbol-utex.el
x-symbol-vars.el
x-symbol-xmas20.el
x-symbol-xmas21.el
x-symbol.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"`


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


    if [ "${FLAVOR}" == xemacs21 -a -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
    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
