#!/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 : Sun Apr 19 23:35:21 1998
# Last Machine Used: tiamat.datasync.com
# Update Count	   : 37
# Status	   : Unknown, Use with caution!
# HISTORY	   : 
# Description	   : 
# 
# 

set -e

FLAVOUR=$1
PACKAGE="psgml"
VERSION="1.0.1-17"

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
startdir=/etc/$FLAVOUR/site-start.d
INFO_FILES="psgml-api.info psgml.info";
STARTFILE="$PACKAGE-init.el";

# Darn it, this may well change.
EMACSB="$FLAVOUR -batch -l psgml-maint.el";

case "$FLAVOUR" in
    emacs19|emacs20)
	echo -n "install/$PACKAGE: Byte-compiling for $FLAVOUR..."
	if [ -d $ELCDIR ]; then
	    rm -f $ELCDIR/*.elc $ELCDIR/install.log;
	    rmdir $ELCDIR
	fi
	if [ ! -d $ELCDIR ]; then
	    install -m 755 -d $ELCDIR
	fi
	cd $ELDIR
	./configure --prefix=/usr
	LOG=`tempfile`;
	# if we do not have make, well, we are hosed.
	if [ -x /usr/bin/make ]; then
	    make clean                                 > $LOG;
	    make EMACS=$FLAVOUR psgmldir=$ELCDIR 2>&1 >> $LOG;
	    echo install -m 644 *.elc $ELCDIR         >> $LOG;
	    install -m 644 *.elc $ELCDIR;
	    make clean                                >> $LOG;
	else
	    echo $EMACSB -f psgml-compile-files       > $LOG;
	    $EMACSB -f psgml-compile-files
	    echo install -m 644 *.elc $ELCDIR         >> $LOG;
	    install -m 644 *.elc $ELCDIR;
	    echo rm -f *.elc                          >> $LOG;
	    rm -f *.elc;
	fi
	mv -f $LOG       $ELCDIR/install.log;
	sed -e "s|=F|/usr/share/$FLAVOUR/site-lisp/$PACKAGE|" \
            $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:
