#!/bin/sh -e

FLAVOR=$1
FLAVORTEST=`echo $FLAVOR | cut -c-6`
PACKAGE=gnuserv

echo install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}


# e25 and up: unflavoured, just emacs and source dir == compile dir
ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
FILES="gnuserv-compat.el gnuserv.el devices.el"

install -m 755 -d ${ELCDIR}
cd ${ELCDIR}

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

for i in $FILES; do
    if [ ! -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/$i ]; then
				ln -s /usr/share/emacs/site-lisp/${PACKAGE}/$i /usr/share/${FLAVOR}/site-lisp/${PACKAGE};
		fi
done

if [ ${FLAVORTEST} = xemacs ] ; then
    SITEFLAG="-no-site-file"
else
    SITEFLAG="--no-site-file"
fi
# Need to load gnuserv-compat because gnuserv.el will not
# byte-compile without it.
FLAGS="-q ${SITEFLAG} -batch -l path.el -l gnuserv-compat -f batch-byte-compile"

rm -f install.log install.log.gz
${FLAVOR} ${FLAGS} ${FILES} >install.log 2>&1
rm -f path.el
gzip -9v install.log
echo "Compilation log saved to ${ELCDIR}/install.log.gz"
exit 0



