#!/bin/sh -eu

FLAVOR="$1"
echo "install/cdargs: Handling install of emacsen flavor $FLAVOR"

byte_compile_options="-batch -f batch-byte-compile"
el_file="cdargs.el" 
el_dir="/usr/share/emacs/site-lisp"
elc_dir="/usr/share/$FLAVOR/site-lisp"

if [ "$FLAVOR" != emacs ]
then
    echo "install/cdargs: byte-compiling for $FLAVOR"

    # Copy the temp .el files
    trap "rm -f \"$elc_dir/$el_file\"" 0
    cp "$el_dir/$el_file" "$elc_dir/$el_file"

    # Byte compile them
    "$FLAVOR" $byte_compile_options "$elc_dir/$el_file" > /dev/null 2>&1

    rm -f "$elc_dir/$el_file"
    trap "" 0
fi
exit 0
