#!/bin/bash
#				-*- Mode: Sh -*- 
# emacsen.install --- 
# Author	   : Manoj Srivastava ( srivasta@tiamat.datasync.com ) 
# Created On	   : Fri Apr  3 14:39:59 1998
# Created On Node  : tiamat.datasync.com
# Last Modified By : Manoj Srivastava
# Last Modified On : Sat Dec  6 00:22:24 2003
# Last Machine Used: glaurung.green-gryphon.com
# Update Count	   : 35
# Status	   : Unknown, Use with caution!
# HISTORY	   : 
# Description	   : 
# 
# arch-tag: 8d8ec43a-8bb5-4ecd-bde8-67736b2d04d5
#

set -e

FLAVOUR=$1
PACKAGE="vm"
VERSION="7.19-4"

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
EFLAGS="-batch -q -l load-path-hack.el -f batch-byte-compile"
STARTDIR=/etc/$FLAVOUR/site-start.d
INFO_FILES="/usr/info/vm.info.gz";
STARTFILE="$PACKAGE-init.el";
BYTEOPTS="./vm-byteopts.el";
PRELOADS=" -l $BYTEOPTS -l ./vm-message.el -l ./vm-misc.el -l ./vm-vars.el -l ./vm-version.el";
BATCHFLAGS=" -batch -q -no-site-file"
CORE="vm-message.el vm-misc.el vm-byteopts.el"


case "$FLAVOUR" in
    emacs20|emacs21|emacs-snapshot|xemacs21)
	echo -n "install/$PACKAGE: Byte-compiling for $FLAVOUR..."
	if [ -d $ELCDIR ]; then
	    rm -f $ELCDIR/*.elc $ELCDIR/install.log $ELCDIR/vm-init.el;
	    rmdir $ELCDIR
	fi
	if [ ! -d $ELCDIR ]; then
	    install -m 755 -d $ELCDIR
	fi
	cd $ELDIR
	# if we do not have make, well, we are hosed.
	LOG=`tempfile`;
	trap "test -f $LOG && mv -f $LOG $ELCDIR/install.log > /dev/null 2>&1" exit
	if [ -x /usr/bin/make ]; then
	    make clean                          > $LOG;
	    (make EMACS=$FLAVOUR)              >> $LOG 2>&1 ;
	    echo install -m 644 *.elc $ELCDIR  >> $LOG;
	    install -m 644 *.elc $ELCDIR;
	    make clean                         >> $LOG;
	else
	    echo >&2 "You do not seem to have make." 
	    echo >&2 "This is not good, since I can't byte compile without make" 
	    echo >&2 "I am letting vm remain non-byte compiled, which slows it down." 
	    echo >&2 "Please hit return to continue."
	    read ans;
	    echo "You do not seem to have make."         > $LOG;
	    echo "Not byte compiling."                  >> $LOG;
	    echo "tar cf - . | (cd $ELCDIR; tar xpf -)" >> $LOG;
	    tar cf - . | (cd $ELCDIR; tar xpf -)
	    echo "cd $ELCDIR;"                          >> $LOG;
	    cd $ELCDIR;
	    echo "rm -f Makefile;"                      >> $LOG;
	    rm -f Makefile;
	fi
	
	mv $LOG       $ELCDIR/install.log;
        chmod 644      $ELCDIR/install.log;
	sed -e "s|=F|/usr/share/$FLAVOUR/site-lisp/$PACKAGE|" \
            $STARTFILE > $ELCDIR/$STARTFILE;
	ucf $ELCDIR/$STARTFILE $STARTDIR/50$STARTFILE;

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

exit 0


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