#!/bin/sh -e

FLAVOR=$1
PACKAGE=gnuserv

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

# Need to load gnuserv-compat because gnuserv.el will not
# byte-compile without it.
FLAGS="-q -batch -l path.el -l gnuserv-compat -f batch-byte-compile"

# 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

rm -f install.log
${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



