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

FLAVOR=$1
echo install/bbdb: Handling install of emacsen flavor ${FLAVOR}

byte_compile_options="-no-site-file -batch -f batch-byte-compile"
el_files="`cd /usr/share/emacs/site-lisp/bbdb; echo *.el`"
el_dir=/usr/share/emacs/site-lisp/bbdb/
elc_dir=/usr/share/${FLAVOR}/site-lisp/bbdb/

if [ ${FLAVOR} != emacs ]; then
    if test -x /usr/sbin/install-info-altdir; then
	echo install/bbdb: install Info links for ${FLAVOR}
	install-info-altdir --quiet --section "" "" --dirname=${FLAVOR} /usr/info/bbdb.info.gz
    fi

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

    cd ${el_dir}
    TARGETS="rmail mhe gnus bbdb"
    if [ -d /usr/share/${FLAVOR}/site-lisp/vm ]; then
	TARGETS="$TARGETS vm"
    elif [ ${FLAVOR} = xemacs19 -o ${FLAVOR} = xemacs20 ]; then
	TARGETS="$TARGETS vm"
    fi
    if [ ${FLAVOR} = emacs19 ]; then
	GNUSDIR=/usr/share/${FLAVOR}/site-lisp/../lisp
    else
	GNUSDIR=/usr/share/${FLAVOR}/site-lisp/../lisp/gnus
    fi
    if [ ${FLAVOR} = emacs19 ]; then
	MHEDIR=/usr/share/${FLAVOR}/site-lisp/../lisp
    elif [ ${FLAVOR} = xemacs19 -o ${FLAVOR} = xemacs20 ]; then
	MHEDIR=/usr/share/${FLAVOR}/site-lisp/../lisp/mh-e
    else	# emacs20
	MHEDIR=/usr/share/${FLAVOR}/site-lisp/../lisp/mail
    fi

    LOG=`tempfile`
    make clean > $LOG
    make $TARGETS EMACS=${FLAVOR} VMDIR=/usr/share/${FLAVOR}/site-lisp/vm GNUSDIR=${GNUSDIR} MHEDIR=${MHEDIR} >> $LOG 2>&1
    
    rm -rf ${elc_dir}
    install -d -m 755 -p ${elc_dir}
    install -m 644 lisp/*.elc ${elc_dir}
    install -d -m 755 /usr/share/${FLAVOR}/site-lisp/../etc/bbdb/{tex,utils}
    install -m 644 tex/* /usr/share/${FLAVOR}/site-lisp/../etc/bbdb/tex
    install -m 644 utils/* /usr/share/${FLAVOR}/site-lisp/../etc/bbdb/utils
    cat > ${elc_dir}/load-path.el <<EOF 
(setq load-path (nconc load-path (list "${elc_dir}")))
(provide 'bbdb/load-path)
EOF
    make clean >> $LOG
    mv $LOG ${elc_dir}/install.log
    echo "Compilation log for ${FLAVOR} saved to ${elc_dir}install.log"
fi
exit 0


