#!/bin/sh -e

FLAVOR=$1
PACKAGE=global
el_files=gtags.el

byte_compile_options="-batch --no-init-file --no-site-file -f batch-byte-compile"
el_dir="/usr/share/emacs/site-lisp/${PACKAGE}/"
elc_dir="/usr/share/${FLAVOR}/site-lisp/${PACKAGE}/"
el_path_list=`echo ${el_files} | perl -pe "s|^|${el_dir}|o"`
elc_path_list=`echo ${el_files} | perl -pe "s|^|${elc_dir}|o"`

if [ ${FLAVOR} != emacs ]
then
	echo install/${PACKAGE}: byte-compiling for ${FLAVOR}

	install -m 755 -d ${elc_dir}

        # remove the redundant files
	rm -f ${elc_dir}/*.el ${elc_dir}/*.elc

	# Copy the temp .el files
	cp ${el_path_list} ${elc_dir}

	# Byte compile them
	${FLAVOR} ${byte_compile_options} ${elc_path_list}
fi
exit 0;

