#! /bin/sh -e
#  /usr/lib/emacsen-common/packages/install/navi2ch
# [ This particular script hasn't been tested, so be careful. ]

set -e

FLAVOR=$1
PACKAGE="navi2ch"
VERSION="2.0.0"

if [ "X${FLAVOR}" = "X" ]; then
    echo Need argument to determin FLAVOR 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/${FLAVOR}/site-lisp/${PACKAGE}

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

SITELISP=/usr/share/${FLAVOR}/site-lisp

STAMP=${ELCDIR}/compile-stamp

case "${FLAVOR}" in

	emacs-20*)
	echo "Not Support"
	;;

    emacs-21*)

	echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."

	if [ -e ${STAMP} ]; then
	    if [ "${VERSION}" = "`cat ${STAMP}`" ]; then
		echo " exited. (already compiled)" 
		exit
	    fi
	fi

	rm -rf ${ELCDIR}
	install -m 755 -d ${ELCDIR}

	cd ${ELDIR}
	#rm -f config.*
	./configure --with-emacs=${FLAVOR} --with-lispdir=${ELCDIR} > ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	make EMACS=${FLAVOR} >> ${ELCDIR}/CompilationLog 2>&1
	#make EMACS=${FLAVOR} -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make INSTALLPATH=${ELCDIR} install >> ${ELCDIR}/CompilationLog 2>&1
	#make INSTALLPATH=${ELCDIR} install -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	#rm -f config.*
	rm ${ELCDIR}/*.el

        #if [ -e /usr/share/info/navi2ch.info.gz ]; then
        #   rm -f /usr/share/info/navi2ch.info*.gz
        #fi

	gzip -9 ${ELCDIR}/CompilationLog
        #gzip -9 /usr/share/info/navi2ch.info
	echo ${VERSION} > ${STAMP}

	ln -f -s ${ELDIR}/${STARTFILE} ${STARTDIR}/90${STARTFILE};
	echo " done."

	;;


    emacs-22*)

	echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."

	if [ -e ${STAMP} ]; then
	    if [ "${VERSION}" = "`cat ${STAMP}`" ]; then
		echo " exited. (already compiled)" 
		exit
	    fi
	fi

	rm -rf ${ELCDIR}
	install -m 755 -d ${ELCDIR}

	cd ${ELDIR}
	#rm -f config.*
	./configure --with-emacs=${FLAVOR} --with-lispdir=${ELCDIR} > ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	make EMACS=${FLAVOR} >> ${ELCDIR}/CompilationLog 2>&1
	#make EMACS=${FLAVOR} -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make INSTALLPATH=${ELCDIR} install >> ${ELCDIR}/CompilationLog 2>&1
	#make INSTALLPATH=${ELCDIR} install -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	#rm -f config.*
	rm ${ELCDIR}/*.el

    #if [ -e /usr/share/info/navi2ch.info.gz ]; then
    #   rm -f /usr/share/info/navi2ch.info*.gz
    #fi

	gzip -9 ${ELCDIR}/CompilationLog
    #gzip -9 /usr/share/info/navi2ch.info
	echo ${VERSION} > ${STAMP}

	ln -f -s ${ELDIR}/${STARTFILE} ${STARTDIR}/90${STARTFILE};
	echo " done."

	;;

    xemacs-*)

	echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."

	if [ -e ${STAMP} ]; then
	    if [ "${VERSION}" = "`cat ${STAMP}`" ]; then
		echo " exited. (already compiled)" 
		exit
	    fi
	fi

	rm -rf ${ELCDIR}
	install -m 755 -d ${ELCDIR}

	cd ${ELDIR}
	#rm -f config.*
	./configure --with-xemacs=${FLAVOR} --with-lispdir=${ELCDIR} > ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	make EMACS=${FLAVOR} >> ${ELCDIR}/CompilationLog 2>&1
	#make EMACS=${FLAVOR} -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make INSTALLPATH=${ELCDIR} install >> ${ELCDIR}/CompilationLog 2>&1
	#make INSTALLPATH=${ELCDIR} install -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	#rm -f config.*
	rm ${ELCDIR}/*.el

    #if [ -e /usr/share/info/navi2ch.info.gz ]; then
    #   rm -f /usr/share/info/navi2ch.info*.gz
    #fi

	gzip -9 ${ELCDIR}/CompilationLog
    #gzip -9 /usr/share/info/navi2ch.info
	echo ${VERSION} > ${STAMP}

	ln -f -s ${ELDIR}/${STARTFILE} ${STARTDIR}/90${STARTFILE};
	echo " done."
	;;
	
    emacs-23*)

	echo -n "install/${PACKAGE}: Byte-compiling for ${FLAVOR} ..."

	if [ -e ${STAMP} ]; then
	    if [ "${VERSION}" = "`cat ${STAMP}`" ]; then
		echo " exited. (already compiled)" 
		exit
	    fi
	fi

	rm -rf ${ELCDIR}
	install -m 755 -d ${ELCDIR}

	cd ${ELDIR}
	#rm -f config.*
	./configure --with-emacs=${FLAVOR} --with-lispdir=${ELCDIR} > ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	make EMACS=${FLAVOR} >> ${ELCDIR}/CompilationLog 2>&1
	#make EMACS=${FLAVOR} -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make INSTALLPATH=${ELCDIR} install >> ${ELCDIR}/CompilationLog 2>&1
	#make INSTALLPATH=${ELCDIR} install -C contrib >> ${ELCDIR}/CompilationLog 2>&1
	make clean >> ${ELCDIR}/CompilationLog 2>&1
	#rm -f config.*
	rm ${ELCDIR}/*.el

    #if [ -e /usr/share/info/navi2ch.info.gz ]; then
    #   rm -f /usr/share/info/navi2ch.info*.gz
    #fi

	gzip -9 ${ELCDIR}/CompilationLog
    #gzip -9 /usr/share/info/navi2ch.info
	echo ${VERSION} > ${STAMP}

	ln -f -s ${ELDIR}/${STARTFILE} ${STARTDIR}/90${STARTFILE};
	echo " done."

	;;

	*)
	;;
esac

exit 0;
