#!/bin/sh 
#                               -*- Mode: Sh -*- 
# emacsen-common-install --- 
# Author           : Manoj Srivastava ( srivasta@tiamat.datasync.com ) 
# Created On       : Wed Oct 14 23:23:39 1998
# Created On Node  : tiamat.datasync.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Mon Oct 29 14:16:24 2001
# Last Machine Used: glaurung.green-gryphon.com
# Update Count     : 18
# Status           : Unknown, Use with caution!
# HISTORY          : 
# Description      : 
# 
# 

set -e

FLAVOUR=$1
PACKAGE="gnus"
VERSION="5.8.8-8"

if [ "X$FLAVOUR" = "X" ]; then
    echo Need argument to determin FLAVOUR of emacs;
    exit 1
fi

if [ "X$PACKAGE" = "X" ]; then
    echo Internal error: need package name;
    exit 1;
fi

if [ "X$VERSION" = "X" ]; then
    echo Internal error: need package version;
    exit 1;
fi

ELDIR=/usr/share/emacs/site-lisp/$PACKAGE
ELCDIR=/usr/share/$FLAVOUR/site-lisp/$PACKAGE

BATCHFLAGS="-batch -q -no-site-file"
PRELOADS="  -l ./dgnushack.el";
COMPILE="-f dgnushack-compile";

INFO_FILES="/usr/info/gnus.gz";

STARTDIR=/etc/$FLAVOUR/site-start.d
STARTFILE="$PACKAGE-init.el";

case "$FLAVOUR" in
    emacs | emacs19)
	echo "install/$PACKAGE: Ignoring $FLAVOUR."
	;;
    emacs20 | xemacs20 | xemacs21)
	echo -n "install/$PACKAGE: Byte-compiling for $FLAVOUR..."
	if command -v $FLAVOUR 2>&1 >/dev/null; then
	    echo -n "found $FLAVOUR .."
	else
	    echo "Could not find $FLAVOUR. Exiting"
	    exit 0;
	fi
	#if [ "$FLAVOUR" = "emacs19" ]; then
	#    CUSTOMINIT="-l /usr/share/emacs/site-lisp/custom-init.el";
	#fi
        if [ -d $ELCDIR ]; then
	    test -f $ELCDIR/install.log && rm -f $ELCDIR/install.log
            rm -f $ELCDIR/*.elc || true;
            rmdir $ELCDIR
        fi
        if [ ! -d $ELCDIR ]; then
            install -m 755 -d $ELCDIR
        fi
        cd $ELDIR

        LOG=`tempfile`;
	trap "test -f $LOG && mv -f $LOG  $ELCDIR/install.log > /dev/null 2>&1" exit

	echo "($FLAVOUR $BATCHFLAGS $CUSTOMINIT $PRELOADS $COMPILE)"
	($FLAVOUR $BATCHFLAGS $CUSTOMINIT $PRELOADS $COMPILE) >$LOG 2>&1

	COMPILED=$(ls -1 *.elc)
	if [ "X$COMPILED" = "X" ]; then
	    echo >&2 "No compiled files exist!!"
	    echo >&2 "Aborting!!"
	    echo     "No compiled files exist!!"  >> $LOG;
	    echo     "Aborting!!"                 >> $LOG;
	    mv -f $LOG  $ELCDIR/install.log
	    exit 1
	fi

	echo install -m 644 *.elc  $ELCDIR  >> $LOG;
	for file in *.elc; do
	    install      -m 644 $file $ELCDIR;
	done
	mv -f $LOG                 $ELCDIR/install.log;
	rm -f *.elc || true;

	ucf $ELDIR/$STARTFILE $STARTDIR/20$STARTFILE;

        if test -x /usr/sbin/install-info-altdir; then
            for infofile in $INFO_FILES; do
                if [ -e $infofile ]; then
                    install-info-altdir --quiet --section "" "" \
                        --dirname=${FLAVOUR} $infofile
                fi
            done
        fi
        echo "done."
	;;
    *)
        echo "install/$PACKAGE: Ignoring emacsen flavor $FLAVOUR.";	
esac


### Local Variables:
### mode: shell-script
### End:
