#!/bin/sh 

set -e

FLAVOUR=$1
PACKAGE="oo-browser"
VERSION="4.07"

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

## Copy/Paste from the orginal Makefile a part of the original
## source package.
HYPB_EL="hypb/h-skip-bytec.lsp hypb/hact.el hypb/hargs.el
	 hypb/hhist.el hypb/hmail.el hypb/hmouse-drv.el
	 hypb/hmouse-key.el hypb/hmous-info.el
	 hypb/hmouse-reg.el hypb/hmouse-sh.el hypb/hmouse-tag.el
	 hypb/hpath.el hypb/hui-mouse.el
	 hypb/hui-window.el hypb/hvar.el
	 hypb/hversion.el hypb/hypb.el hypb/hsys-w3.el hypb/set.el"
EL_COMPILE="br-c-ft.el br-c++-ft.el br-c++.el br-clos-ft.el
            br-clos.el br-compl.el
            br-eif-ft.el br-eif.el br-env.el br-ftr.el br-info.el
            br-init.el br-java.el br-java-ft.el
	    br-lib.el br-menu.el br-name.el br-objc-ft.el
            br-objc.el br-python.el br-python-ft.el br-site.el br-vers.el
	    br-smt.el br-start.el br-tree.el br.el c++-browse.el
	    clos-brows.el eif-browse.el eif-calls.el eif-ise-er.el
	    hasht.el hmouse-br.el info-brows.el java-brows.el
	    objc-brows.el pyth-brows.el smt-browse.el auto-autoloads.el"

BATCHFLAGS="-batch"
PRELOADS="-l debian_specific.el -l ./br-start.el";
COMPILE="-f batch-byte-compile";

INFO_FILES="oo-browser.info.gz";

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

case "$FLAVOUR" in
    emacs)
	echo "install/$PACKAGE: Ignoring $FLAVOUR."
	;;
    emacs19 | emacs20 | xemacs20 | xemacs21 )
	echo -n "install/$PACKAGE: Byte-compiling for $FLAVOUR..."
	CUSTOMINIT="-l /usr/share/emacs/site-lisp/oo-browser/oo-browser-init.el"
	if [ -d $ELCDIR ]; then
	        rm -rf $ELCDIR;
	fi
        LOG=`tempfile`;

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

	for i in `echo "$EL_COMPILE $HYPB_EL"| tr '[:space:]' '\n'`; do
		($FLAVOUR $BATCHFLAGS $CUSTOMINIT $PRELOADS $COMPILE $ELCDIR/$i) >> $LOG 2>&1;
	done

	echo cd $ELCDIR >> $LOG;
	cd $ELCDIR
	rm `find . -name "*.el" -print`
	mv -f $LOG install.log;

	# Link to the documentation files
	ln -sf /usr/share/doc/oo-browser/BR-FEATURES $ELCDIR/BR-FEATURES
	ln -sf /usr/share/doc/oo-browser/BR-VERSION $ELCDIR/BR-VERSION
	ln -sf /usr/share/doc/oo-browser/BR-RELEASE $ELCDIR/BR-RELEASE
	ln -sf /usr/share/doc/oo-browser/BR-COPY $ELCDIR/BR-COPY

	if [ ! -L $STARTDIR/20$STARTFILE ]; then
	    ln -s $ELDIR/$STARTFILE $STARTDIR/20$STARTFILE;
	fi
        if [ -x /usr/sbin/install-info ]; then
            for infofile in $INFO_FILES; do
                if [ -e /usr/share/info/$infofile ]; then
                    install-info --quiet --section "Miscellaneous" "Emacs" \
                    	--description="* OO-Browser: (oo-browser). Object-Oriented (X)Emacs Class Browser" /usr/share/info/$infofile
					#
					#  XXX: Workarround for non-FSH 2.0 compilent XEmacsen
					#       searching for info pages within /usr/info
					#       instead of /usr/share/info...
					#  !!! WILL BE REMOVED IN THE FUTURE !!!
					#
					if [ ! -L /usr/info/$infofile ]; then
						ln -s /usr/share/info/$infofile /usr/info/$infofile
					fi
		        fi
			done
		fi
		echo "done."
	;;
    *)
        echo "install/$PACKAGE: Ignoring emacsen flavor $FLAVOUR.";	
esac


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