#!/bin/sh 
#$Id: emacsen-install,v 1.5 2001/12/21 17:44:51 david Exp $
set -e

FLAVOUR=$1
PACKAGE="oo-browser"

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

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

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

BATCHFLAGS="-batch -q"
PRELOADS="-l localpath.el -l ./br-start.el";
COMPILE="-f batch-byte-compile";
PDOCDIR="/usr/share/$PACKAGE"

case "$FLAVOUR" in
    emacs)
	:
	;;
    *)
	echo -n "install/$PACKAGE: Byte-compiling for $FLAVOUR (this may take some time)..."

	rm -rf $ELCDIR;

        LOG=`tempfile`;

	echo cp -Rdp $ELDIR $ELCDIR > $LOG;
	cp -Rdp $ELDIR $ELCDIR;

	echo cd $ELCDIR >> $LOG;
	cd $ELCDIR;

	ELFILES=$(echo *.el hypb/*.el)

	cat << EOF > localpath.el
(setq load-path (cons "." (cons "./hypb" load-path)) 
      byte-compile-warnings nil)
EOF

	echo $FLAVOUR $BATCHFLAGS $PRELOADS $COMPILE \*.el hypb/\*.el >> $LOG;
	$FLAVOUR $BATCHFLAGS $PRELOADS $COMPILE $ELFILES  >> $LOG 2>&1;

	echo rm \*.el hypb/\*.el >> $LOG ;
	rm *.el hypb/*.el >> $LOG 2>&1 ;

	# Link to the documentation files
	ln -sf $PDOCDIR/BR-FEATURES BR-FEATURES
	ln -sf $PDOCDIR/BR-VERSION BR-VERSION
	ln -sf $PDOCDIR/BR-RELEASE BR-RELEASE
	ln -sf $PDOCDIR/BR-COPY BR-COPY

	echo done.
	mv -f $LOG install.log;
	chmod 644 install.log
	echo Output has been saved in $ELCDIR/install.log
	;;
esac
